#11: Custom Status Lines 📊
Today we'll look at customizing the bar at the bottom of Claude Code with a status line.
A status line is a shell command that Claude Code runs for us. It receives session data as JSON on stdin, and whatever it prints shows up in its own row above the built-in footer. It runs locally, so it doesn't use any API tokens.
Let's dive in.
Let Claude Write It
The quickest way to get one is to describe what we want with the /statusline command:
/statusline show model name and context percentage with a progress barClaude Code writes a script into ~/.claude/ and updates our settings for us. To get rid of it later, /statusline clear (or /statusline delete) removes it.
The Setting
Under the hood, it's just a statusLine entry in ~/.claude/settings.json or our project settings:
{
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.sh",
"padding": 2,
"refreshInterval": 5
}
}type is always "command", and command can be a script path or an inline shell command. padding adds a little horizontal spacing. refreshInterval re-runs the command every N seconds, which is handy for clocks or anything that changes while the session sits idle. Without it, the script only runs on events, like a new assistant message, /compact finishing, or a permission mode change.
Writing Our Own
Here's a small script that shows the model, the folder we're in, and how full the context window is:
#!/bin/bash
input=$(cat)
MODEL=$(echo "$input" | jq -r '.model.display_name')
DIR=$(echo "$input" | jq -r '.workspace.current_dir')
PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)
echo "[$MODEL] ${DIR##*/} | ${PCT}% context"We make it executable and we're done. Claude Code reloads settings automatically, so the bar shows up as soon as we save:
chmod +x ~/.claude/statusline.shEvery echo becomes its own row, so multi-line status lines work too. ANSI color codes like \033[32m work as well.
Fields Worth Knowing
The JSON has quite a bit in it. A few favorites:
cost.total_cost_usdandcost.total_duration_msfor an estimated session cost and running timecontext_window.used_percentageandcontext_window.context_window_sizerate_limits.five_hour.used_percentagefor Pro, Max, and Ultra subscriberssession_name,effort.level, andpr.numberworktree.nameandworktree.branchwhile we're in a worktree session
Here's a cost and time readout:
#!/bin/bash
input=$(cat)
COST=$(echo "$input" | jq -r '.cost.total_cost_usd // 0')
MS=$(echo "$input" | jq -r '.cost.total_duration_ms // 0')
SECS=$((MS / 1000))
printf '$%.2f | %dm %ds\n' "$COST" $((SECS / 60)) $((SECS % 60))Some fields are absent or null depending on the session. rate_limits only appears after the first API response, and vim only appears with vim mode on. The // 0 and // empty fallbacks in jq keep things from breaking.
Testing And Gotchas
We don't need a live session to try a script. We can pipe in some mock JSON ourselves:
echo '{"model":{"display_name":"Hal"},"workspace":{"current_dir":"/home/dave/discovery"},"context_window":{"used_percentage":25}}' \
| ~/.claude/statusline.shNeat! A few things to watch for:
- The output only shows when the script exits with code
0. An error or empty output leaves the bar blank. - The script runs often, so slow commands like
git statuscan lag. The docs suggest caching results in a file keyed bysession_id. tput colscan't see the terminal from inside the script. We read theCOLUMNSenvironment variable instead.- Until we accept the workspace trust dialog for a folder, the status line stays blank.
More info about status lines can be found at the Claude Code docs.