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.
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
trueAdd 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
}
]
}
]
}
}