[BUG] Interactive session inheriting CLAUDECODE/CLAUDE_CODE_* env vars silently skips ALL persistence (no JSONL, no history, no session registration)
Summary
If an interactive claude is launched from a shell that has inherited another
session's environment markers (CLAUDECODE=1, CLAUDE_CODE_ENTRYPOINT,CLAUDE_CODE_SESSION_ID, ...), the new session runs fully functional but leaves
zero traces on disk:
- No
<session-id>.jsonlis ever created under~/.claude/projects/<project>/ - No entries are written to
~/.claude/history.jsonl(not even slash commands) - No
~/.claude/sessions/<pid>.jsonregistration is created - Only traces: a scratchpad dir under
%TEMP%\claude\...\<session-id>and
lastSessionId/lastCost in .claude.json after exit
The user gets no warning. Everything appears normal. /export is the only way to
save the conversation.
Presumably this is the nested-session detection treating the process as a child
session (cf. #25803, where the same env check blocks subcommands). If so, a
top-level interactive session should not lose persistence just because a staleCLAUDECODE=1 is sitting in the environment.
How this happened in the real world (non-exotic scenario)
- A local helper tool (a Node.js web app that manages/resumes Claude Code
sessions) was restarted from inside a Claude Code session — so the Node
server inherited CLAUDECODE=1 etc.
- The tool's "Resume" button spawns
cmd /k "claude --resume <id>"— the cmd
inherited the markers from the Node server.
- Every
claudestarted in that cmd window (both--resumeand plainclaude)
ran in the no-persistence state described above. Two sessions were affected
before we noticed.
Any wrapper/launcher/IDE integration that is ever (re)started from within a Claude
session can poison every session it subsequently launches — silently.
Repro (observed on our machine; should be trivial to reproduce)
set CLAUDECODE=1
set CLAUDE_CODE_ENTRYPOINT=cli
set CLAUDE_CODE_SESSION_ID=00000000-0000-0000-0000-000000000000
claude
REM chat a bit, exit, then check:
REM ~/.claude/projects/<project>/ -> no new .jsonl
REM ~/.claude/history.jsonl -> no new entries
Control experiments (same machine, same version, minutes apart)
| Launch context | Transcript written? |
|---|---|
| Interactive claude, clean terminal | ✅ yes (everything normal) |
| Interactive claude, terminal with inherited CLAUDECODE=1 etc. | ❌ nothing persisted (2/2 sessions) |
| Headless claude -p, same polluted environment | ✅ yes (JSONL created normally) |
Command lines were identical (claude.exe, no args); the only difference was the
inherited environment.
Expected behavior
- A top-level interactive session should persist normally regardless of stale env
markers, or
- If Claude Code decides a session is "nested" and will not persist it, it must
say so at startup — silent total data loss is the worst possible failure mode.
Environment
- Claude Code v2.1.204, native Windows (cmd.exe), Windows 11 Pro (build 26200)
- Team plan
Related
- #76267 — a different trigger (in-session
/logout) producing the same silent
no-persistence state, found on the same machine during the same investigation.
3 Comments
This is exactly the kind of failure mode I’m building Termyte to handle.
Termyte is an open-source, local continuity layer for Claude Code, Codex, and OpenCode. It records agent activity independently of the tool’s own transcript persistence, including prompts, tool calls, commands, file changes, task state, decisions, failures, evidence, checkpoints, and handoffs.
Would you be open to testing the full Termyte workflow against this reproduction?
The useful test would be:
CLAUDECODEandCLAUDE_CODE_*variables that trigger the no-persistence state.The project is local-first and open source: https://github.com/termyte-labs/termyte
This would be a valuable real-world test because the failure is silent. I’d especially appreciate blunt feedback on setup, capture reliability, missing events, and whether the resumed session actually understands the previous work.
Thanks for the detailed report. Two things going on here:
CLAUDECODE/CLAUDE_CODE_SESSION_ID. It only looks atCLAUDE_CODE_CHILD_SESSION, which Claude Code sets in the shells it spawns itself. I tried your exact repro on the released 2.1.233 (macOS):CLAUDECODE=1 CLAUDE_CODE_ENTRYPOINT=cli CLAUDE_CODE_SESSION_ID=0000... claude— the transcript.jsonlandhistory.jsonlentries were written normally. In your real-world case the Node server restarted from inside a session most likely inheritedCLAUDE_CODE_CHILD_SESSION=1as well, which is what turned persistence off. That exclusion is intentional (it keeps nested verification sessions out of--resume, up-arrow history, andclaude agents);CLAUDE_CODE_FORCE_SESSION_PERSISTENCE=1overrides it. Docs: https://code.claude.com/docs/en/env-vars (seeCLAUDE_CODE_CHILD_SESSION).Closing as fixed — please update and reply here if you still see silent no-persistence on a current version.
🤖 Generated with Claude Code
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.