Skip to content

Commit 47e0b21

Browse files
Marvinclaude
andcommitted
fix(hooks): use getPaiDir() instead of hardcoded ~/.claude paths
Replace hardcoded join(HOME, '.claude') fallbacks with getPaiDir() from hooks/lib/paths.ts in 4 hooks: LastResponseCache, RatingCapture, SessionCleanup, WorkCompletionLearning. This enables PAI_DIR portability — users can set PAI_DIR to install PAI outside ~/.claude/ (e.g. to work around Claude Code v2.1.78+ sensitive directory protection). Complements existing getPaiDir() usage in SecurityValidator, SessionAutoName, RelationshipMemory, KittyEnvPersist, LoadContext. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1202b4b commit 47e0b21

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

Releases/v4.0.3/.claude/hooks/LastResponseCache.hook.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
*/
1313

1414
import { readHookInput, parseTranscriptFromInput } from './lib/hook-io';
15+
import { getPaiDir } from './lib/paths';
1516
import { writeFileSync } from 'fs';
1617
import { join } from 'path';
17-
import { homedir } from 'os';
1818

1919
async function main() {
2020
const input = await readHookInput();
@@ -29,8 +29,7 @@ async function main() {
2929

3030
if (lastResponse) {
3131
try {
32-
const paiDir = process.env.PAI_DIR || join(homedir(), '.claude');
33-
const cachePath = join(paiDir, 'MEMORY', 'STATE', 'last-response.txt');
32+
const cachePath = join(getPaiDir(), 'MEMORY', 'STATE', 'last-response.txt');
3433
writeFileSync(cachePath, lastResponse.slice(0, 2000), 'utf-8');
3534
} catch (err) {
3635
console.error('[LastResponseCache] Failed to write:', err);

Releases/v4.0.3/.claude/hooks/RatingCapture.hook.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import { appendFileSync, mkdirSync, existsSync, readFileSync, writeFileSync } from 'fs';
3232
import { join } from 'path';
33+
import { getPaiDir } from './lib/paths';
3334
import { inference } from '../PAI/Tools/Inference';
3435
import { getIdentity, getPrincipal, getPrincipalName } from './lib/identity';
3536
import { getLearningCategory } from './lib/learning-utils';
@@ -60,7 +61,7 @@ interface RatingEntry {
6061

6162
// ── Shared Constants ──
6263

63-
const BASE_DIR = process.env.PAI_DIR || join(process.env.HOME!, '.claude');
64+
const BASE_DIR = getPaiDir();
6465
const SIGNALS_DIR = join(BASE_DIR, 'MEMORY', 'LEARNING', 'SIGNALS');
6566
const RATINGS_FILE = join(SIGNALS_DIR, 'ratings.jsonl');
6667
const LAST_RESPONSE_CACHE = join(BASE_DIR, 'MEMORY', 'STATE', 'last-response.txt');

Releases/v4.0.3/.claude/hooks/SessionCleanup.hook.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535

3636
import { writeFileSync, existsSync, readFileSync, unlinkSync } from 'fs';
3737
import { join } from 'path';
38+
import { getPaiDir } from './lib/paths';
3839
import { getISOTimestamp } from './lib/time';
3940
import { setTabState, cleanupKittySession } from './lib/tab-setter';
4041

41-
const BASE_DIR = process.env.PAI_DIR || join(process.env.HOME!, '.claude');
42+
const BASE_DIR = getPaiDir();
4243
const MEMORY_DIR = join(BASE_DIR, 'MEMORY');
4344
const STATE_DIR = join(MEMORY_DIR, 'STATE');
4445
const WORK_DIR = join(MEMORY_DIR, 'WORK');

Releases/v4.0.3/.claude/hooks/WorkCompletionLearning.hook.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@
5151

5252
import { writeFileSync, existsSync, readFileSync, mkdirSync } from 'fs';
5353
import { join, dirname } from 'path';
54+
import { getPaiDir } from './lib/paths';
5455
import { getISOTimestamp, getPSTDate } from './lib/time';
5556
import { getLearningCategory } from './lib/learning-utils';
5657

57-
const BASE_DIR = process.env.PAI_DIR || join(process.env.HOME!, '.claude');
58+
const BASE_DIR = getPaiDir();
5859
const MEMORY_DIR = join(BASE_DIR, 'MEMORY');
5960
const STATE_DIR = join(MEMORY_DIR, 'STATE');
6061
const WORK_DIR = join(MEMORY_DIR, 'WORK');

0 commit comments

Comments
 (0)