Skip to content

Instantly share code, notes, and snippets.

@kevinansfield
Created March 18, 2026 16:58
Show Gist options
  • Select an option

  • Save kevinansfield/36c3f94a6b6a5550d290887ef9716897 to your computer and use it in GitHub Desktop.

Select an option

Save kevinansfield/36c3f94a6b6a5550d290887ef9716897 to your computer and use it in GitHub Desktop.
Claude Code hook: set Ghostty tab title to worktree name on SessionStart

Claude Code Hook: Set Terminal Tab Title to Worktree Name

Sets your terminal tab title (e.g. Ghostty) to the git worktree name when Claude Code starts a session in a worktree. Useful when running multiple claude -w <name> sessions.

Requires jq.

Hook command (readable)

input=$(cat)
cwd=$(echo "$input" | jq -r '.cwd // empty' 2>/dev/null)

if [ -z "$cwd" ]; then
  cwd=$(pwd)
fi

if git -C "$cwd" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
  wt=$(git -C "$cwd" worktree list --porcelain 2>/dev/null | grep -A0 "^worktree $cwd$")
  if [ -n "$wt" ]; then
    name=$(basename "$cwd")
    [ -n "$name" ] && [ -e /dev/tty ] && printf '\e]2;%s\a' "$name" > /dev/tty 2>/dev/null
  fi
fi

true

settings.json

Add this to ~/.claude/settings.json (or ~/.claude/settings.local.json):

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "input=$(cat); cwd=$(echo \"$input\" | jq -r '.cwd // empty' 2>/dev/null); if [ -z \"$cwd\" ]; then cwd=$(pwd); fi; if git -C \"$cwd\" rev-parse --is-inside-work-tree >/dev/null 2>&1; then wt=$(git -C \"$cwd\" worktree list --porcelain 2>/dev/null | grep -A0 \"^worktree $cwd$\"); if [ -n \"$wt\" ]; then name=$(basename \"$cwd\"); [ -n \"$name\" ] && [ -e /dev/tty ] && printf '\\e]2;%s\\a' \"$name\" > /dev/tty 2>/dev/null; fi; fi; true",
            "timeout": 5000
          }
        ]
      }
    ]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment