Session name lost after compaction — /rename breaks when context compacts
Bug Description
When a Claude Code session is /renamed (e.g., /rename gsd-plan), the name is stored as a custom-title entry in the session JSONL file tied to a specific session UUID. When the user runs /clear, a new session UUID is created but the name is not carried forward. The old named session becomes an orphan with stale history, and the running instance continues on an unnamed session.
Root cause confirmed: /clear creates a new session JSONL file with a new UUID. The custom-title entry from the old session is not copied to the new session. The user's named session is now stuck pointing at pre-/clear history.
Evidence from JSONL forensics
Original session (be04e4d2, named gsd-plan):
- Last entry:
2026-04-01T17:31:18.973Z—turn_durationsystem message, 374 messages - Has
custom-title: "gsd-plan"entry
Continuation session (cd957439, unnamed):
- First entry:
2026-04-01T17:39:07.579Z—file-history-snapshot - Second entry:
/clearcommand (<command-name>/clear</command-name>) - No
custom-titleentry — name was not carried forward - User later renamed to
gsd-planning(slightly different name, user error because they didn't realize the original name was lost) - No
parentSessionIdfield — no link back to the original session
Timeline: old session ends at 17:31 → 8 minute gap → new session starts at 17:39 with /clear as first real command.
Steps to Reproduce
- Start Claude Code:
claude - Rename the session:
/rename my-session - Do some work (build up conversation history)
- Run
/clear - Observe: new session UUID created, name lost
- Exit and try:
claude --resume my-session - Result: Resumes the pre-clear session state, not the post-clear continuation
Expected Behavior
/clearshould preserve the session name on the new session UUID- The
custom-titleentry should be written to the new JSONL file after/clear - If
/clearcannot preserve the name, it should warn: "This will create a new session. Your session name 'my-session' will need to be re-set with /rename" parentSessionIdshould be set on the new session linking to the old one (enables session chain traversal)
Actual Behavior
/clearcreates a new UUID and JSONL file without thecustom-title- The old JSONL retains the name but is stale (pre-clear state)
- The running Claude instance is now on an unnamed session
- User loses the ability to resume by name
- No
parentSessionIdfield links the sessions
Impact
This is especially painful for long-running workflows where:
- Multiple named sessions run in parallel tmux panes (
gsd-plan,gsd-execute,meta-director) - Sessions are expected to survive across
/clearoperations (which are recommended by GSD workflows: "/clear first → fresh context window") - Scripts use
--resume <name>to reconnect (e.g.,claude --resume gsd-plan) - The session name is the only discoverable handle — UUIDs are not human-usable
GSD workflows routinely recommend /clear before heavy execution phases to free context. Every /clear silently orphans the session name, making --resume useless.
Suggested Fix
On /clear:
- Read
custom-titlefrom the current session JSONL - Write it as the first entry in the new session JSONL
- Set
parentSessionIdon the new session pointing to the old UUID - Optionally:
--resume <name>should follow theparentSessionIdchain to find the latest session with that name
Alternative: Store session names in a separate index file (name → latest UUID) rather than embedding in JSONL. Update the index on /clear, compaction, or any session fork.
Environment
- Claude Code v2.1.89
- macOS Darwin 25.3.0
- tmux 3.x with multiple named sessions
- Model: Opus 4.6 (1M context)
5 Comments
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
This issue is specifically about
/clearas the trigger — distinct from #29922 (compaction) and #41352 (auto-continue). All three share the same root cause:custom-titleis not carried forward when a new session UUID is created. But/clearis a different code path than compaction or auto-continue, so the fix may need to touch different places.The JSONL forensics in this report confirm the exact mechanism:
/clearcreates a new JSONL file with a new UUID, thecustom-titleentry is not copied, and noparentSessionIdlinks the sessions.Upvoting #29922 and #41352 as well — the real fix is making
custom-titlesurvive ALL session transitions, not just one trigger.Please fix this. It's both ridiculous and super annoying.
/clear intentionally starts a fresh session: new UUID, new JSONL, and a cleared title/tag. We made that change because the previous behavior — where the old name carried over — caused the opposite confusion: people would /clear, keep working, and later --resume <name> expecting the new conversation but getting the new one stacked on an old-named file, or vice versa (see #26082). Dropping the identity on /clear was the fix for that.
So --resume my-session landing on the pre-clear history is the intended semantics: that's the session that was named my-session. After /clear you're in a new, unnamed session; if you want the same name on it, run /rename my-session again.
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.