Summary
Inference.ts only strips CLAUDECODE from the subprocess environment, but Claude Code 2.1.71 sets additional CLAUDE_CODE_* env vars that cause claude --print to hang silently. This breaks all hook-based inference (RatingCapture sentiment analysis, WorkCompletionLearning, etc.).
Additionally, RatingCapture.hook.ts sets a 12s inference timeout that is too short for claude --print cold-start on macOS
(~7-15s).
Environment
- PAI: v4.0.3
- Claude Code: 2.1.71
- Platform: macOS (Apple Silicon)
- Auth: claude.ai subscription
Symptoms
- Zero new entries in ratings.jsonl despite active sessions
- RatingCapture hook produces no output at all (not even [RatingCapture] Hook started)
- WorkCompletionLearning inference also silently fails
- Explicit ratings (number-only prompts) also fail because the hook process itself can't start
Root Cause
Claude Code injects these env vars into the hook execution environment:
CLAUDECODE=1
CLAUDE_CODE_ENTRYPOINT=cli
CLAUDE_CODE_SSE_PORT=31705
CLAUDE_CODE_MAX_OUTPUT_TOKENS=80000
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
Inference.ts (lines 72-77) only deletes CLAUDECODE:
const env = { ...process.env };
delete env.ANTHROPIC_API_KEY;
delete env.CLAUDECODE;
With only CLAUDECODE removed, claude --print gets past the nested session guard but then hangs silently. The remaining CLAUDE_CODE_* vars (likely CLAUDE_CODE_SSE_PORT) cause the subprocess to stall during initialization.
Secondary issue: RatingCapture.hook.ts sets timeout: 12000 for sentiment inference. Even after fixing the env vars, claude
--print takes ~7-15s on macOS cold start. The 12s timeout causes inference to time out and silently discard the result.
Fix
PAI/Tools/Inference.ts (lines 72-77)
Replace:
const env = { ...process.env };
delete env.ANTHROPIC_API_KEY;
delete env.CLAUDECODE;
With:
const env = { ...process.env };
delete env.ANTHROPIC_API_KEY;
for (const key of Object.keys(env)) {
if (key === 'CLAUDECODE' || key.startsWith('CLAUDE_CODE_')) {
delete env[key];
}
}
PAI/Tools/Inference.ts (line 57)
Increase fast-level default timeout:
fast: { model: 'haiku', defaultTimeout: 25000 }, // was 15000
hooks/RatingCapture.hook.ts (line 285)
Increase sentiment inference timeout:
timeout: 30000, // was 12000
Verification
After applying the fix:
[RatingCapture] Hook started
[RatingCapture] Running implicit sentiment analysis...
[RatingCapture] Implicit: 8/10 (conf: 0.92) - Direct praise for completed work
[RatingCapture] Wrote implicit rating 8 to .../ratings.jsonl
Both explicit rating and implicit sentiment paths confirmed working. First live rating written within minutes of fix.
Notes
Summary
Inference.ts only strips CLAUDECODE from the subprocess environment, but Claude Code 2.1.71 sets additional CLAUDE_CODE_* env vars that cause claude --print to hang silently. This breaks all hook-based inference (RatingCapture sentiment analysis, WorkCompletionLearning, etc.).
Additionally, RatingCapture.hook.ts sets a 12s inference timeout that is too short for claude --print cold-start on macOS
(~7-15s).
Environment
Symptoms
Root Cause
Claude Code injects these env vars into the hook execution environment:
CLAUDECODE=1
CLAUDE_CODE_ENTRYPOINT=cli
CLAUDE_CODE_SSE_PORT=31705
CLAUDE_CODE_MAX_OUTPUT_TOKENS=80000
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
Inference.ts (lines 72-77) only deletes CLAUDECODE:
const env = { ...process.env };
delete env.ANTHROPIC_API_KEY;
delete env.CLAUDECODE;
With only CLAUDECODE removed, claude --print gets past the nested session guard but then hangs silently. The remaining CLAUDE_CODE_* vars (likely CLAUDE_CODE_SSE_PORT) cause the subprocess to stall during initialization.
Secondary issue: RatingCapture.hook.ts sets timeout: 12000 for sentiment inference. Even after fixing the env vars, claude
--print takes ~7-15s on macOS cold start. The 12s timeout causes inference to time out and silently discard the result.
Fix
PAI/Tools/Inference.ts (lines 72-77)
Replace:
const env = { ...process.env };
delete env.ANTHROPIC_API_KEY;
delete env.CLAUDECODE;
With:
const env = { ...process.env };
delete env.ANTHROPIC_API_KEY;
for (const key of Object.keys(env)) {
if (key === 'CLAUDECODE' || key.startsWith('CLAUDE_CODE_')) {
delete env[key];
}
}
PAI/Tools/Inference.ts (line 57)
Increase fast-level default timeout:
fast: { model: 'haiku', defaultTimeout: 25000 }, // was 15000
hooks/RatingCapture.hook.ts (line 285)
Increase sentiment inference timeout:
timeout: 30000, // was 12000
Verification
After applying the fix:
[RatingCapture] Hook started
[RatingCapture] Running implicit sentiment analysis...
[RatingCapture] Implicit: 8/10 (conf: 0.92) - Direct praise for completed work
[RatingCapture] Wrote implicit rating 8 to .../ratings.jsonl
Both explicit rating and implicit sentiment paths confirmed working. First live rating written within minutes of fix.
Notes
versions may have only set CLAUDECODE.