Blog / claude code
See which branch each Claude Code session is on
With several Claude Code sessions in several worktrees, every window looks the same. A short status line script shows folder, branch and uncommitted files.
On this page
- The script
- Turn it on
- What it looks like
- Name your sessions
- Add how full the context is
- Keep it current
- See all your worktrees at once
- Where Joxo fits
- Frequently asked questions
- How do I show the git branch in Claude Code?
- Why doesn't my Claude Code status line update?
- How do I name a Claude Code session?
- Does the status line work in git worktrees?
- Try it with your team
Four Claude Code sessions, four git worktrees, four windows that look identical. You type "ship it" into the one you think is the login fix, and it's the one on the billing branch. Claude Code shows the folder in its banner when it starts, but that scrolls away within a few minutes.
Claude Code has a status line: a line under the prompt that runs a script of yours and shows what it prints. Put the folder, the git branch and the number of uncommitted files there, and every session says where it is, all the time.
The script#
Save this as ~/.claude/statusline.sh:
#!/bin/sh
# Claude Code status line: folder, branch, uncommitted files, session name.
input=$(cat)
dir=$(printf '%s' "$input" | jq -r '.workspace.current_dir // .cwd')
name=$(printf '%s' "$input" | jq -r '.session_name // empty')
line=$(basename "$dir")
if branch=$(git -C "$dir" branch --show-current 2>/dev/null); then
[ -z "$branch" ] && branch="detached at $(git -C "$dir" rev-parse --short HEAD)"
changed=$(git -C "$dir" status --porcelain 2>/dev/null | wc -l | tr -d ' ')
line="$line · $branch"
[ "$changed" != "0" ] && line="$line · $changed changed"
fi
[ -n "$name" ] && line="$line · $name"
printf '%s\n' "$line"Make it executable:
chmod +x ~/.claude/statusline.shClaude Code sends the script a JSON object on standard input with the session's details: workspace.current_dir is the folder the session is working in, and session_name is the name you gave it (without one, Claude Code uses a title it made up). The script asks git for the branch and counts the lines of git status --porcelain, one per changed or new file. Outside a git repository it prints just the folder. It needs jq.
Turn it on#
Add this to ~/.claude/settings.json to use it in every project:
{
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.sh"
}
}Or put the same block in a project's .claude/settings.json to use it only there. You can also type /statusline in Claude Code and describe what you want; it writes a script for you.
What it looks like#
We made a repository on main, added a worktree on a fix-login branch, changed a file in each, and fed the script the same input Claude Code sends. It printed:
repo · main · 1 changed · login bug
wt-login · fix-login · 1 changed · login bug
tmp · login bug
repo · detached at 560a32e · 1 changedThe third line is a folder outside git; the fourth is a checkout with no branch. Then we started Claude Code in the worktree with claude --name "login bug". Under the prompt it showed:
wt-login · fix-login · 2 changed · login bugTwo changed this time, because the new .claude/settings.json was an uncommitted file too.
Name your sessions#
The branch tells you where a session is; a name tells you what it's for. Start a session with claude --name "login bug", or type /rename in a running one. The name shows in the status line through session_name, and claude --resume lists sessions by name, so you can find the right one again tomorrow.
Add how full the context is#
Long sessions slow down and forget earlier instructions as the context window fills. The same input carries context_window.used_percentage, so two more lines before the last printf add it:
used=$(printf '%s' "$input" | jq -r '.context_window.used_percentage // empty | floor')
[ -n "$used" ] && line="$line · context $used%"With 41.7% used, our test printed wt-login · fix-login · 2 changed · login bug · context 41%. The field is empty until the session's first reply, and the script then leaves it out. When a session gets close to full, it's a good moment to commit and start a fresh one; Claude Code prompt is too long covers what to do when it's already there.
Keep it current#
Claude Code re-runs the script when something changes in the session, such as a new message, and batches updates that arrive within 300 ms. When the main session is idle, nothing triggers it, so a change made by a background subagent, or by you in another window, won't show until the next message. If that matters, add "refreshInterval": 5 to the statusLine block to re-run the script every 5 seconds as well. Keep the script fast: Claude Code cancels a run that's still going when the next update arrives.
See all your worktrees at once#
The status line answers "where is this session?" For the other direction, "which folder has which branch?", git lists them:
git worktree list/private/tmp/b3sl/repo 560a32e (detached HEAD)
/private/tmp/b3sl/wt-login 560a32e [fix-login]If you're setting up worktrees for parallel sessions, Run multiple Claude Code sessions in parallel without conflicts covers the setup, including the ports and databases they would otherwise share.
Where Joxo fits#
A status line tells you about the sessions on your own screen. With Joxo, you see every session on your computers, and your teammates' agents on the same project, from one list on your phone or desktop, with the ones waiting for an answer at the top. Setup is one line pasted into your agent.
Frequently asked questions#
How do I show the git branch in Claude Code?#
Set statusLine in ~/.claude/settings.json to a script that reads workspace.current_dir from its input and prints git branch --show-current for that folder. The script above does that and adds the count of uncommitted files.
Why doesn't my Claude Code status line update?#
It updates on session events, such as a new message. When the session is idle, set refreshInterval in the statusLine block to re-run the script every few seconds.
How do I name a Claude Code session?#
Start it with claude --name "your name", or type /rename in a running session. The status line receives it as session_name.
Does the status line work in git worktrees?#
Yes. Each session reports its own folder, so a session in a worktree shows that worktree's branch.