From d19e6827237c0f3af9cb79a53d43367fb4c8fd2f Mon Sep 17 00:00:00 2001 From: Eric Antones Date: Wed, 6 May 2026 12:11:10 +0200 Subject: [PATCH] fix(deep-consolidation): isolate inner claude --print from caller's cwd The deep dream cycle invokes `claude --print` via execSync but never sets cwd, so the inner Claude inherits whichever cwd SNARC was triggered from (typically the parent agent's case folder). The inner Claude then loads the parent's project CLAUDE.md + SessionStart hooks (state-continuity pointing at a state pin, edit-validation hooks, etc.). With those in scope, the inner Claude is steered toward agent-style behavior and returns prose narration instead of the JSON array the prompt asks for. The result is a silent failure on every agent close: [snarc] Deep consolidation: no JSON array in response The fix is to set cwd: tmpdir() on the execSync call. With no project CLAUDE.md or project hooks in scope, the inner Claude treats the prompt as the only instruction and returns the JSON array as requested. Verified end-to-end: 8 high-quality deep_workflow / deep_insight / deep_decision / deep_error_fix patterns extracted from a 37k-observation DB on first post-fix invocation, 32s wall time. --- src/deep-consolidation.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/deep-consolidation.ts b/src/deep-consolidation.ts index e742567..7df59c9 100644 --- a/src/deep-consolidation.ts +++ b/src/deep-consolidation.ts @@ -88,9 +88,16 @@ export async function deepConsolidate( let response: string; try { writeFileSync(tmpFile, prompt); + // CRITICAL: run from tmpdir() so the inner `claude --print` does NOT inherit + // the outer agent's cwd. Without this, the inner Claude loads the outer + // agent's project CLAUDE.md + SessionStart hooks (e.g. state-continuity + // pointing at the agent's state pin), gets steered toward agent-style + // behavior, and returns prose instead of the requested JSON array. + // Symptom: "[snarc] Deep consolidation: no JSON array in response". response = execSync( `cat "${tmpFile}" | claude --print -`, { + cwd: tmpdir(), timeout: 60_000, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'],