[BUG] /clear loses session name from prompt bar and spawns a distinct session
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?
Version: 2.1.198
Expected (per docs, https://code.claude.com/docs/en/sessions.md#manage-context-within-a-session — "start fresh with an empty context. The previous conversation is saved and resumable"):
Same session continues, name still shown on the prompt bar.
Actual:
- The prompt bar no longer shows the name after
/clear. - The name only survives in the terminal tab title.
- The picker/
--resumeshows what looks like a distinct session rather than the same renamed one continuing.
Workaround: running /rename <name> again immediately after /clear restores the prompt-bar display.
This contradicts the documented behavior that /clear resets context within the same session object, leaving the session identity (and its name) untouched.
What Should Happen?
Expected (per docs, https://code.claude.com/docs/en/sessions.md#manage-context-within-a-session — "start fresh with an empty context. The previous conversation is saved and resumable"):
Same session continues, name still shown on the prompt bar.
Error Messages/Logs
Steps to Reproduce
Steps to reproduce:
- Start a session, rename it with
/rename <name>(or-n <name>at startup) — name shows on the prompt bar as documented. - Run
/clear.
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.198 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
_No response_
4 Comments
Confirming this also reproduces in the VS Code extension (not just a standalone terminal), so it's not terminal-specific.
Repro:
/clear.Actual: the custom name is dropped and the prompt bar reverts to an auto-generated title.
Same behavior and same workaround as described (
/rename <name>again after/clearrestores it). Would be great to have/clearpreserve the session name here as the docs imply.🤖 Generated with Claude Code
Root-caused this by inspecting the shipped binaries (2.1.198 — the version reported here — plus 2.1.201/2.1.202/2.1.204). The name survives
/clearin every persistence layer; what breaks is only the prompt-bar UI state, which is wiped during the clear and never re-seeded. Property/record names below are as they appear in the bundle, so they should be greppable in source.1.
/clearstarting a new session is by design. The session id rotates (SessionStart hooks fire withsource: "clear"), and in 2.1.20x the command self-describes as "Start a new session with empty context; previous session stays on disk (resumable with /resume)", with aliases/resetand/newand an optional[name]argument that labels the cleared session for/resume. So "picker shows a distinct session" is expected behavior; the docs wording in sessions.md is what's misleading (related: #57445).2. The name carry-over already exists — in persistence.
clearConversationcaptures the user-set title before rotating and callssaveCustomTitle(newSessionId, title, undefined, "user")after: this appends a{"type":"custom-title"}record to the new session's transcript and updates in-memorycurrentSessionTitle. Present in 2.1.198 through 2.1.204 (this looks like the 2.1.111 fix "Fixed/cleardropping the session name set by/rename, causing statusline output to losesession_name"). Side effect: old and new sessions can then show the same name in/resume— which is exactly the duplicate-name complaint in #61172, i.e. more evidence the persistence carry-over works.3. The prompt bar renders a different store, and that's the bug. The prompt bar shows
appState.standaloneAgentContext.name. Only two paths write it: startup seeding and/rename(which does bothsaveCustomTitle(...)and asetAppStatethat writesstandaloneAgentContext.name).clearConversation's app-state reset explicitly discardsstandaloneAgentContext— it preserves onlyprideGradient— and nothing re-seedsnameafterwards. That is precisely why the reported workaround works:/renameafter/clearis the only path that writes the field back.4. The tab-title asymmetry. The terminal-title name lives in the per-PID registry (
~/.claude/sessions/<pid>.json). On clear, that file gets only itssessionIdfield updated in place; itsnamefield is untouched — so the tab keeps the name while the prompt bar loses it.Suggested fix: in
clearConversation, when the title carry-over branch runs, also re-seed the prompt-bar state — either exemptname(andcolor, which is dropped by the same reset) from thestandaloneAgentContextwipe when a user-set title exists, or invoke the same app-state update/renameuses aftersaveCustomTitle. #67389 (SessionStart hooksessionTitleignored forsource: "clear") looks like the same gap: the hook path persists viasaveCustomTitlebut never touchesstandaloneAgentContext.nameeither.Mechanism is unchanged in 2.1.204, so this should still reproduce on latest.
🤖 Generated with Claude Code
Also reproduces on macOS (Darwin 25.3.0), so this is not Windows-specific. Name set via /rename is gone after /clear and a new session file is created under ~/.claude/projects/<project>/.
Workaround that works for me: a SessionStart hook with matcher "clear" that reads the last
{"type":"custom-title"}line from the most recent previous session .jsonl in the project directory and re-applies it viahookSpecificOutput.sessionTitle.Confirmed — reproduced on the released 2.1.233 build (Linux, fresh profile):
/rename mytestname→ name shows on the prompt bar. ✔/clear→ name disappears from the prompt bar and doesn't come back on later turns, until another/rename. ✘Two useful details from digging in: the name is not actually lost — the continued session keeps the custom name in session storage, and the
--resumepicker shows it with the right name. Only the prompt-bar display drops it after/clear, which we agree is a bug.On the second part:
/clearsaving the previous conversation as its own resumable entry (so the picker shows the pre-clear conversation separately from the continuing one) is the documented behavior — "the previous conversation is saved and resumable" requires it to stay its own entry. So the distinct picker entry is expected; the prompt-bar losing the name is the part we'll fix.🤖 Generated with Claude Code