Session name lost after compaction — /rename breaks when context compacts

Status Fixed / completed
Maintainer reply None cached
Activity 5 comments · opened Apr 1, 2026 · closed Apr 7, 2026

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_duration system 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: /clear command (<command-name>/clear</command-name>)
  • No custom-title entry — 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 parentSessionId field — 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

  1. Start Claude Code: claude
  2. Rename the session: /rename my-session
  3. Do some work (build up conversation history)
  4. Run /clear
  5. Observe: new session UUID created, name lost
  6. Exit and try: claude --resume my-session
  7. Result: Resumes the pre-clear session state, not the post-clear continuation

Expected Behavior

  • /clear should preserve the session name on the new session UUID
  • The custom-title entry should be written to the new JSONL file after /clear
  • If /clear cannot 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"
  • parentSessionId should be set on the new session linking to the old one (enables session chain traversal)

Actual Behavior

  • /clear creates a new UUID and JSONL file without the custom-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 parentSessionId field 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 /clear operations (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:

  1. Read custom-title from the current session JSONL
  2. Write it as the first entry in the new session JSONL
  3. Set parentSessionId on the new session pointing to the old UUID
  4. Optionally: --resume <name> should follow the parentSessionId chain 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)

View original on GitHub ↗

5 Comments

github-actions[bot] · 6 months ago

Found 2 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/29922
  2. https://github.com/anthropics/claude-code/issues/41352

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

w3geekery · 6 months ago

This issue is specifically about /clear as the trigger — distinct from #29922 (compaction) and #41352 (auto-continue). All three share the same root cause: custom-title is not carried forward when a new session UUID is created. But /clear is 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: /clear creates a new JSONL file with a new UUID, the custom-title entry is not copied, and no parentSessionId links the sessions.

Upvoting #29922 and #41352 as well — the real fix is making custom-title survive ALL session transitions, not just one trigger.

jasondparrish · 6 months ago

Please fix this. It's both ridiculous and super annoying.

qing-ant · 6 months ago

/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.

github-actions[bot] · 6 months ago

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.