[BUG] Assistant responses silently stop persisting to session JSONL after cd, breaking --resume
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
After using cd to change the working directory during a session, Claude Code silently stops persisting assistant responses (and eventually all messages) to the session JSONL file. The session continues to work normally in the terminal — the user sends messages, Claude responds, everything looks fine — but nothing is being written to disk. This makes --resume load an empty/broken conversation and causes complete data loss.
This was observed in two independent sessions on the same machine within the same day.
What Should Happen?
All messages should be persisted to the session JSONL regardless of cd operations during the session. The parent UUID chain should remain intact.
Evidence: Two Confirmed Cases
Both sessions started from /Users/alber and did cd to subdirectories during the conversation. Both continued working normally in the terminal after writes stopped.
Case 1 (a3adef1a): ~3100 lines, 27MB. cd to a subdirectory at line 3085. Some entries continued to appear in the JSONL after the cd, but --resume could not load from any point after the cd — only truncating to the last complete turn before the cd restored the conversation. At least two assistant responses were confirmed missing entirely (Stop hooks reference parentUuids that don't exist in the file), and the entries that are present all have stop_reason=null, suggesting they may be incomplete streaming fragments. The /exit and hooks WERE written. On --resume, conversation loaded empty.
Case 2 (3bc45a62): 652 lines, 1.2MB. Multiple cd operations during the session. Last entry written to the session JSONL at 13:17 UTC. Session continued until 16:36 UTC — over 3 hours of messages not present in the session JSONL (also not found in alternative project directories after the cd). A custom hook that reads the JSONL confirmed the later responses were absent from the file.
Forensic Details
In Case 1, the JSONL shows the exact failure mode:
Line 3148: type=user uuid=27640473 (user message)
Line 3149: type=progress parent=66d52b32 ← MISSING (stop hook references nonexistent response)
Line 3150: type=system parent=589e03af (stop_hook_summary)
Line 3151: type=system parent=38217547 (turn_duration: 126307ms)
The response with uuid 66d52b32 was generated (the turn took 2+ minutes, stop hooks ran referencing it as parent), but its line was never written to the JSONL. This breaks the parent chain and makes --resume unable to reconstruct the conversation.
Workaround
Manually truncating the JSONL to the last complete turn with an intact parent chain restores --resume:
# 1. Backup
cp ~/.claude/projects/<project>/<session>.jsonl ~/backup.jsonl
# 2. Find the last line where the parent chain is intact
# (inspect with: python3 -c "import json; ...")
# 3. Truncate
head -n <LAST_GOOD_LINE> ~/backup.jsonl > ~/.claude/projects/<project>/<session>.jsonl
# 4. Resume
claude --resume <session-id>
This recovered the full conversation history up to the truncation point.
Steps to Reproduce
- Start a Claude Code session from directory A
- During the session, ask Claude to
cdto directory B - Continue the conversation for several turns after the
cd - Run
/exit - Run
claude --resume
Result: Conversation loads empty or with only recent context. The JSONL file is missing assistant responses from after the cd.
Note: The issue may not manifest immediately after the cd — in Case 1, several responses after the cd persisted before writes started failing. In Case 2, the pattern is less clear due to multiple cd operations.
Claude Model
claude-opus-4-5-20251101
Is this a regression?
Unknown — this is the first version where I've investigated the JSONL directly
Claude Code Version
v2.1.29
Platform
Claude Max subscription
Operating System
macOS (Darwin 23.6.0, Apple Silicon)
Terminal/Shell
iTerm2 / zsh
Related Issues
- #4843 — Conversation history lost when changing directories with
cd(same root cause?) - #22107 — Session resume logic losing context (v2.1.27)
- #22030 — Resume shows partial history due to stale
sessions-index.json - #16970 — Claude is losing chat history
- #15315 — Claude Code writes history but doesn't read it back on resume
- #14462 — Resume reverts to pre-compaction state
- #21067 — Resume hangs on sessions with large tool outputs
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗