fix(deep-consolidation): isolate inner claude --print from caller's cwd#2
Open
eantones wants to merge 1 commit into
Open
fix(deep-consolidation): isolate inner claude --print from caller's cwd#2eantones wants to merge 1 commit into
claude --print from caller's cwd#2eantones wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every invocation of the deep dream cycle silently returns zero LLM-generated patterns. Logs show:
The heuristic (regex-based) dream cycle keeps producing Tier 2 patterns, which masks the failure — observers see "patterns being created" and assume the system is healthy, but the LLM-extracted high-quality patterns (
deep_*) are absent.Reproduction
Trigger
snarc dream --deepfrom any cwd that contains a project-specificCLAUDE.mdand/or a.claude/settings.jsonwithSessionStarthooks. This is a common setup when SNARC is embedded as a memory backend behind a project workspace.Root cause
src/deep-consolidation.tsinvokes the LLM helper like this:No
cwdoption is passed, soexecSyncinherits the parent process's cwd. When SNARC runs as a memory-consolidation pass from inside a project workspace, the innerclaude --printtherefore starts in that workspace's directory — picking up itsCLAUDE.md, itsSessionStarthooks, its state-continuity pin, and any edit-validation hooks.Two compounding effects:
response.match(/\[[\s\S]*\]/)then finds no JSON array.ETIMEDOUT.A representative response (paraphrased, observed after instrumentation):
The inner Claude even correctly identifies its role ("this turn was a memory consolidation pass, not project work") — but the project hooks override the prompt's authority.
Fix
Add
cwd: tmpdir()to theexecSyncoptions:response = execSync( `cat "${tmpFile}" | claude --print -`, { + cwd: tmpdir(), timeout: 60_000, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], }, ).trim();The inner
claude --printnow runs from the OS temp directory, where no project-levelCLAUDE.mdorSessionStarthooks exist. It operates in a clean context, follows the prompt, and returns the JSON array. With hooks no longer loading, the call also completes well within the existing 60 s timeout.A multi-line comment is added at the call site explaining the rationale, so future readers don't undo the cwd isolation thinking it's accidental.
Validation
Tested against a real-world database with 37,094 observations:
0LLM patterns;ETIMEDOUTand "no JSON array in response" in logs.deep_*entries — workflows, insights, decisions, error fixes), wall time 32.5 s, 0 errors.The 8 patterns extracted in the validation run were manually inspected and all were genuinely useful (no noise, no over-fitting on transient observations).
Notes
cwdtoexecSyncof an LLM CLI) is easy to introduce elsewhere;src/deep-consolidation.tsis the only such site I see in the current tree, but worth keeping in mind for future helpers.31255b5("feat: deep dream — LLM-powered consolidation via claude --print"). It only manifests when the cwd has agent-style configuration, which is why it has gone unnoticed in clean test environments.