feat: name the Ghostty tab after the branch - #44
Open
johnpangalos wants to merge 1 commit into
Open
Conversation
Ghostty's AppleScript surface configuration has no settable title, so `wt` now sets it the way any program does: it wraps the surface command to emit an `OSC 2 ; <branch> BEL` sequence, then execs the editor. Ghostty already runs the surface command as `bash -c "exec <cmd>"`, so the outer exec hands straight off to this wrapper with no lingering shell. The title is the branch name (or the worktree dir basename for a detached/bare checkout). It sticks for programs that leave the title alone (most editors); a shell with a prompt title hook overwrites it. On by default; set WT_NO_TITLE to opt out. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
johnpangalos
marked this pull request as ready for review
July 7, 2026 07:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
wt switch/wt rootnow name the new tab/window after the branch, on by default. SetWT_NO_TITLEto opt out.Why it's done this way
Ghostty's AppleScript surface configuration has no settable title — the
nameproperty on window/tab/terminal is read-only in the scripting dictionary, and thesurface configurationrecord only exposes cwd, command, initial input, wait-after-command, and env vars. So we can't set the title through the same AppleScript pathwtuses.Instead we set it the way any program does: wrap the surface command so it emits an
OSC 2 ; <branch> BELsequence before exec-ing the editor:```
/bin/bash -c 'printf "\033]2;branch\007"; exec /path/to/nvim'
```
This composes cleanly with the two existing quirks:
bash -c "exec <cmd>", so the outerexechands straight off to our wrapper — no lingering shell, andwait after commandsemantics are preserved (the editor is still the final process).\033/\007survive AppleScript'sasStringescaping becauseprintf(not AppleScript) interprets them.Caveat
The title only sticks for programs that don't set their own. Editors like Neovim (
'title'off by default) leave it alone, so it reads as the branch name. A shell with a prompt title hook (e.g. Ghostty shell integration) will overwrite it. This is documented in the README note and thewrapCmdWithTitledocstring.Title value
Branch name, falling back to the worktree's directory basename for a detached/bare checkout.
Tests
wrapCmdWithTitleis tested by actually running the wrapper throughbashexactly as Ghostty does and asserting the real OSC-2 bytes emitted — covering the full quoting pipeline, shell metacharacters/quotes in titles, and control-character stripping.WT_NO_TITLEopt-out.tsc --noEmitgreen.🤖 Generated with Claude Code