Repository navigation
Description
Summary
The sandboxed claude -p calls already strip CLAUDECODE from the child env "to allow nested sessions", but they don't strip the harness's job-identity vars CLAUDE_JOB_DIR and CLAUDE_CODE_SESSION_ID. As a result, the headless summarizer/compressor sub-sessions inherit the parent session's job identity and masquerade as part of the parent's "agents view" background job.
Combined with cwd=tempfile.gettempdir(), this surfaces as phantom temp-dir sessions in the Claude Code agents view / /resume picker. On my machine 457 of them accumulated under ~/.claude/projects/-private-tmp/, each a remember summarizer/compressor transcript.
This isn't a functional break in remember — the summarization works fine — it's an env-hygiene leak in the same class as the CLAUDECODE stripping you already do.
Root cause
Two launch sites strip only CLAUDECODE:
pipeline/haiku.py (~line 69):
# CLAUDECODE env var blocks nested sessions — must strip it
env = {k: v for k, v in os.environ.items() if k != "CLAUDECODE"}
result = subprocess.run(cmd, ..., env=env, cwd=tempfile.gettempdir())scripts/save-session.sh (lines 175 and 241):
HAIKU_JSON=$(cd /tmp && env -u CLAUDECODE claude -p ...)
NDC_JSON=$(cd /tmp && env -u CLAUDECODE claude -p ...)Because CLAUDE_JOB_DIR (and CLAUDE_CODE_SESSION_ID) survive into the child, anything keyed off "is this a background/agents-view job" treats the throwaway summarizer as a real, resumable session belonging to the parent job.
Impact
- Phantom
tmp : …sessions pile up in the agents view / resume picker (hundreds over time). - Tools that key off
CLAUDE_JOB_DIRcan write into the parent job's dir from the child, e.g. clobbering a shared per-job state/marker file.
Proposed fix
Extend the existing env strip to also drop the harness job-identity vars at both sites — same intent as the CLAUDECODE handling, since these sandboxed children are explicitly not part of the parent job:
pipeline/haiku.py:
_STRIP = {"CLAUDECODE", "CLAUDE_JOB_DIR", "CLAUDE_CODE_SESSION_ID"}
env = {k: v for k, v in os.environ.items() if k not in _STRIP}scripts/save-session.sh:
env -u CLAUDECODE -u CLAUDE_JOB_DIR -u CLAUDE_CODE_SESSION_ID claude -p ...Notes
- Repro: with an agents-view (background) session active, trigger consolidation (e.g. exit and relaunch
claude --agents); the summarizer sub-sessions show up named in the picker. - I also added a defensive guard downstream in my own session-naming hook (skip naming any session whose cwd is a temp dir), but the cleanest place to stop the leak is here at the source. Happy to send a PR if you'd like.
🤖 Filed via Claude Code
Activity
FrankLedo commentedon Jun 9, 2026
Cross-referencing #87 ("isolate the headless
claude -psummarization subprocess") — these overlap. The leak described here is a consequence of the summarizer subprocess inheriting the parent's full environment:CLAUDE_JOB_DIR/CLAUDE_CODE_SESSION_IDflow through unchanged, so the nested session looks like a resumable agents-view session to anything keying off those vars.Isolating the subprocess environment as proposed in #87 would very likely resolve this as a side effect — stripping/overriding the inherited Claude Code session vars (not just
CLAUDECODE) when spawning the headlessclaude -psummarizer/compressor would stop the leak at the source. Filing separately for visibility, but they can probably be triaged together.fdaviddpt commentedon Jun 18, 2026
Thank you for filing this separately with the root-cause analysis, @FrankLedo — spot on. 🙏
Status: #93's
--no-session-persistenceremoved the most visible symptom (the nested session is no longer written as a resumable record, so it stops flooding Recents / the agents view). But you're right that the underlying leak remains — theclaude -psubprocess still inheritsCLAUDE_JOB_DIRandCLAUDE_CODE_SESSION_ID, because we only stripCLAUDECODE.Fixing that properly now: stripping the parent Claude Code session vars (
CLAUDE_JOB_DIR,CLAUDE_CODE_SESSION_ID, and the rest ofCLAUDE_CODE_*) from the child env. PR incoming — keeping this open until it lands.fix: strip parent Claude Code session env from nested claude -p (#95) (…
release: 0.8.0 (#106)
fix: keep the OAuth token for the nested call, and report why it fail…
fix: keep the OAuth token for the nested call, and report why it fail…
fix(#898): the nested summarizer inherits the environment; session st…
fix(#898): write the session strip list and the Codex allow-list as l…
fix(#898): the release-tree checker allowlists the session messaging …
fix(#898): release tree scrub + 5 new guards (typed-heredoc shipped a…
fix(#900): compile hooks.json-registered hooks self-contained at buil…