[BUG] Session name lost after context compaction
Status Open
Reported on v2.1.63
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 11 comments · opened Mar 1, 2026
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?
When a session is renamed via /rename, the name is lost after context compaction occurs. The session name gets overridden with the original value instead of using the renamed value.
What Should Happen?
The custom session name should persist after compaction.
Error Messages/Logs
Steps to Reproduce
- Start a Claude Code session and send a message so that the session gets an automatic name.
- Note the name it was given.
- Rename it with
/rename foo - Continue working until the conversation hits the context limit and compaction triggers.
- Observe the session name in the session picker has changed to the original name.
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.63 (Claude Code)
Platform
Anthropic API
Operating System
Other Linux
Terminal/Shell
Other
Additional Information
This is a duplicate of issue #26121. That issue was closed and locked as it was supposedly fixed in version 2.1.47. This is false as I am running 2.1.63 and the issue is still present.
11 Comments
+1, facing the same issue
related:
cc-memory addresses this with a different approach that's already working.
Instead of improving compaction, it moves context outside the window entirely:
just moved out)
scored by relevance
no token cost from your subscription
density and only triggers compaction when the window crosses a dynamic
threshold. The threshold itself adjusts based on content type:
decision-heavy turns raise it, tool output-heavy turns lower it.
Compaction never fires blindly at a fixed percentage
recoverable content, compaction is skipped entirely
summarized before they bloat the window, recoverable content evicted first
cleaning, the duplicate never hits the API
The result: Claude remembers schema decisions, variable names,
architectural rationale across sessions — not just within one session.
Compaction becomes a last resort, not a constant interruption.
Working implementation if you want to try it today:
https://github.com.AbdoKnbGit/claude-code-memory
Please go away with the sales pitch spam.
just proposing an solution
I'm still seeing this, it's not clear to me what the point of
/renameis if this isn't fixed.Session metadata loss after compaction is a symptom of the same underlying problem — the JSONL gets rebuilt from a summarized state and anything not in the summary structure is lost.
We built Cozempic to defer compaction by pruning JSONL bloat before it fires, keeping the file lean enough that the original session structure (including metadata) survives longer. The doctor command also has a
claude-json-corruptioncheck that can detect when metadata has been dropped.pip install cozempic && cozempic doctorOpen-sourced it because session data loss on compaction kept costing us work. Curious if others are seeing the name loss tied to specific session sizes — there may be a threshold pattern here.
What is it with all the sales pitches to use some third party solution that doesn't even fix the problem? Minimizing compaction does not fix the issue.
Fair point — my comment was off-target for this specific issue. Session name loss after compaction is a metadata persistence problem, not a bloat problem, and deferring compaction doesn't fix it. I shouldn't have stretched the framing. Leaving the original comment in case it's useful to anyone hitting the bloat-related symptoms, but you're right that it doesn't address the rename bug directly.
Claude Code's own comment on this bug:
Observation and hypothesis from a Claude session (2026-04-27), shared with the user's permission — analysis by Claude Sonnet 4.6
I hit this today and did some informal forensics on the session files. Sharing in case it helps narrow the root cause.
What I observed
The session was renamed via /rename several times during an active session. After context compaction triggered, a second Claude session described this
session as "unnamed", and the name badge in the bottom-right of the UI was absent on resume. Running /rename again in the resumed session immediately
restored the badge.
On the "new JSONL file" theory
I initially assumed compaction writes a new session file (new ID, name not carried over). The file evidence doesn't support this: the original JSONL
continued receiving writes after the compaction event, and claude -r <original-id> still resolves correctly. There appears to be only one session ID
throughout.
Proposed mechanism
If the JSONL stays in the same file, the name loss likely happens at the client's display layer rather than at the file level:
now behind that boundary and is not re-read.
This would explain why /rename after compaction works fine (the new entry lands after the boundary), and why any name set before compaction is silently
dropped.
Possible fix direction
When writing the compaction marker to the JSONL, emit a new custom-title entry immediately after it, copying forward any existing name. This keeps the
name within the "current window" regardless of when it was originally set.
---
This is behavioural inference — I haven't read the source. If the actual compaction path is in a known file it would be worth checking whether
custom-title is explicitly excluded or just overlooked during the continuation write.
Still reproducing on v2.1.149 (also v2.1.150) — ~90 versions past the #26121 "fix."
Additional findings from a forked session under explicit
/compact <custom-args>(not auto-compaction):1. The clobbered title is the parent session's
custom-title, not a freshly-generated AI titleThe fork's JSONL contains zero
ai-titlerecords —/compactdid not trigger AI title regeneration. The value that overwrites the user's rename is byte-identical to the parent session's existingcustom-title. So this isn't the auto-title generator misbehaving; it's a stale title being re-applied from inherited/parent state.2.
custom-titleandagent-nameare written as a pair — twice, back-to-backWindow around the bug in the fork's
.jsonl:Two
(custom-title, agent-name)pairs are written ~milliseconds apart, by two different code paths. The first writes the in-memory current value (correct). The second writes the parent's value (wrong). Whichever path runs second wins.3. Earlier in the same session, the rename was working fine
The user's
/renameis at line 1566; the title stays correct for ~1,300 records and through several earlier/compactinvocations without args. The clobber happens only on the/compactthat had custom args. May or may not be a coincidence — worth checking whether/compact <args>takes a different code path than/compactalone.4. Other context
sessionKind: "bg"(spawned via background mechanism). Unclear whether non-bg fork sessions show the same behavior — may be worth checking if title resolution diverges for bg sessions.custom-titlehad been set well before the fork point. Don't have data on whether a fork from a parent with only an ai-title would still get clobbered (would pinpoint whether the source is parent'scustom-titlefield specifically or whatever the parent's "display title" resolves to).Repro
/compact <any custom instruction>in B.custom-title.Side effect on
/resumeMultiple forks of one parent all converge to the parent's title, making the picker ambiguous. Workaround:
claude --resume <sessionId>directly, or append a freshcustom-titlerecord to the JSONL with Claude Code closed.Follow-up: this bug is not cosmetic. The clobbered title gets injected into the model's context as a behavioral steering signal, so it can silently override
/compact's custom args.What I found in the same JSONL
Continuing right after the bug moment (line 2905 = clobber, line 2908 = next user prompt), the very next records are:
Two things happen at the moment a prompt fires after a title-clobbering
/compact:<system-reminder>is injected telling the model the session's intent — using the clobbered (wrong) title. Whatever code path generates that "session intent" reminder reads the session'scustom-titlefield. Because the bug has just overwritten it with the parent's title, the model is now being told the session is about Topic A, not the topic the user explicitly redirected to via/compact <custom-args>.Observed downstream effect
After those injections, the model in this session spawned 21
Tasksub-agent calls doing research on the parent's topic (not the user's new debugging topic). ~1,300 transcript records of work landed before the user noticed and hit Escape.Why this matters
The original report frames this as titles reverting on
/compact. The deeper failure mode is:/compact <custom-args>is the documented way to redirect a session to a new topic./compactprompt itself.This bypasses one of the supported ways to refocus a session, so the impact is significantly larger than a wrong label in the picker.
Suggested investigation angle
Whatever code emits the
"The user named this session '<title>'..."reminder should at minimum:/compact <args>ran, since the user has just made an explicit topic-redirect statement that should take precedence.And separately, the parent-prompt re-injection on a forked session under
/compactlooks like fork-state-restore pulling from the parent rather than from the fork's own initial state — worth auditing the same path.