[BUG] Terminal title is blanked on exit instead of restored, corrupting tmux-resurrect saves
What's Wrong?
On exit, Claude Code writes an empty OSC 2 terminal title instead of restoring the title that was there before it started. It never saves the prior title, so whatever the user or a previous program had set is destroyed rather than restored.
Under tmux this is more than cosmetic. #{pane_title} is sticky — it defaults to the hostname and nothing ever reverts it — so the pane keeps an empty title indefinitely after Claude Code exits.
That silently corrupts tmux-resurrect saves. Its save.sh parses pane records with IFS=$'\t' read, and tab is IFS whitespace in bash, so an empty field collapses and every field after it shifts left one position. pane_current_path lands in the wrong slot, and on restore the pane falls back to $HOME. The result is that panes silently lose their working directories across a save/restore cycle — only the panes where Claude Code had been run and exited.
What Should Happen?
Use the xterm title stack: push on startup (CSI 22;2t) and pop on exit (CSI 23;2t). Other TUI programs do this — nvim and lazygit both leave a pre-existing title intact across a full run.
Failing that, emit no title write at all on exit. Leaving a stale title is strictly better than destroying the user's.
Error Messages/Logs
# Control: no CLAUDE_CODE_DISABLE_TERMINAL_TITLE
marker set: [MARKER]
claude running: [✳ Claude Code]
after /exit: [] # blanked, not restored
# Same steps with CLAUDE_CODE_DISABLE_TERMINAL_TITLE=1
marker set: [MARKER]
claude running: [MARKER] # never touched
after /exit: [MARKER]
Steps to Reproduce
- Start a tmux session and make sure the shell is not setting the title itself (with oh-my-zsh:
DISABLE_AUTO_TITLE=true). - Set a known pane title:
``sh``
printf '\033]2;MARKER\007'
- Confirm it took:
tmux display -p -F '#{pane_title}'→MARKER - Run
claude, then/exit. - Check again:
tmux display -p -F '#{pane_title}'→ empty. ExpectedMARKER.
To see the downstream effect with tmux-resurrect installed: run the save script and inspect the saved file. Pane records whose title is empty have 11 tab-separated fields with pane_current_path shifted out of field 8, e.g.
pane<TAB>sess<TAB>1<TAB>0<TAB>:-<TAB>0<TAB>:/some/path<TAB>1<TAB>zsh<TAB>4462<TAB>:
versus a well-formed record, where the title occupies field 7 and the path field 8:
pane<TAB>sess<TAB>1<TAB>0<TAB>:-<TAB>0<TAB>sometitle<TAB>:/some/path<TAB>1<TAB>zsh<TAB>:
Restoring from the first form puts the pane in $HOME.
Claude Model
Opus
Is this a regression?
I don't know
Claude Code Version
2.1.227 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other — Ghostty (outer) + tmux 3.5a, zsh
Additional Information
CLAUDE_CODE_DISABLE_TERMINAL_TITLE=1 avoids the problem entirely, and works from the env block of settings.json as well as the shell environment. But it's a workaround with costs: it disables the useful session-topic title too, it is undocumented (absent from the settings env table), and per #84789 it is ignored for background sessions.
Existing related issues are all requests to disable the title — #21677 (closed, not planned), #31107 (closed as duplicate), #76092, #17951. This report is different: the title feature is fine, the defect is that exit clobbers the previous title instead of restoring it.
The tab-collapsing behaviour in tmux-resurrect is arguably a bug on their side too, but Claude Code blanking the title is what triggers it, and the fix here (save/restore rather than blank) is well-defined regardless.
Showing cached comments. Read the full discussion on GitHub ↗
3 Comments
Reproduced on v2.1.233 (macOS, tmux 3.5a, zsh).
Steps:
DISABLE_AUTO_TITLE=true zsh -f).printf '\033]2;MARKER\007'thentmux display -p -F '#{pane_title}'→MARKER.claude, accept the workspace prompt, wait for the REPL.tmux display -p -F '#{pane_title}'→✳ Claude Code(expected while running)./exit, thentmux display -p -F '#{pane_title}'.Observed: the title is empty after exit.
Expected: the previous title (
MARKER) is restored, or at least left untouched.Assessment: intended today, but the expectation is reasonable. Claude Code deliberately writes an empty title on exit so a terminal tab does not keep showing a stale session name; it never saves the title that was there before, and this has been the behavior for a long time (not a recent regression). Outside tmux most terminals fall back to a default title, so it goes unnoticed, but tmux keeps the blank pane title forever, which is what breaks tmux-resurrect. We should make this cleaner by pushing the title on startup and popping it on exit (the xterm title stack), or by leaving the title alone on exit instead of blanking it.
CLAUDE_CODE_DISABLE_TERMINAL_TITLE=1remains the workaround for now.🤖 Generated with Claude Code
Adding a noise comment to prevent this from being closed.
Adding a noise comment to prevent this from being closed.