Claude Code status line: set up and customize it

Set up a custom Claude Code status line with /statusline or settings.json. Show context use, cost, git branch and rate limits, and fix a blank bar.

on this page

The Claude Code status line is a bar at the bottom of the terminal that runs a shell script you choose. Claude Code sends your script session data as JSON. Whatever the script prints becomes the bar. It is the cheapest way to keep context use, cost and git branch in view all the time.

This guide shows two ways to set it up, lists the fields you can use, and gives four scripts we tested. It ends with fixes for a blank bar. We checked every field and setting against the official status line docs on 2026-11-23.

What you’ll learn

  • How to create a status line with /statusline, and how to do it by hand
  • How and when Claude Code runs your script
  • Which JSON fields exist, and which can be missing or null
  • Scripts for a context bar, a cached git branch, rate limits and colors
  • How to fix a blank or broken status line

Prerequisites

  • Claude Code installed and signed in
  • jq for the Bash examples (brew install jq on macOS, apt install jq on Debian and Ubuntu). Python and Node.js have JSON parsing built in.
  • A terminal that supports ANSI colors

How the status line works

The status line runs locally. It does not use API tokens.

Claude Code runs your script once when a session starts, including a resumed session. After that it runs again when:

  • a new assistant message arrives
  • /compact finishes
  • the permission mode changes
  • vim mode toggles
  • you change the command in your statusLine settings
  • a refreshInterval timer you set runs out

Updates are debounced at 300 ms, so quick changes run your script once. If a new update starts while your script is still running, Claude Code cancels the running script. It shows your output only after the script exits with code 0. A script that fails or prints nothing leaves the bar blank.

The bar hides for a moment during some screens, such as the help menu and permission prompts. With a custom status line, Claude Code also stops showing a few footer hints, such as ? for shortcuts.

Set it up with /statusline

The quickest way is to ask Claude Code to write the script. Run /statusline with a plain description:

/statusline show model name, git branch, context percentage bar and session cost

Claude Code writes a script in ~/.claude/ and updates your settings. Approve the file edit prompts if they appear. There is nothing to install first.

To remove the status line, run /statusline and ask it to delete or clear the bar. You can also delete the statusLine field from your settings file yourself.

Set it up by hand

Add a statusLine field to ~/.claude/settings.json, or to a project settings file:

{
  "statusLine": {
    "type": "command",
    "command": "~/.claude/statusline.sh",
    "padding": 2
  }
}
FieldMeaning
typeMust be "command".
commandA script path, or an inline shell command.
paddingOptional. Extra horizontal spacing in characters. Default 0.
refreshIntervalOptional. Re-runs the command every N seconds (minimum 1). Use it for a clock, or when background subagents change git state while the main session is idle.
hideVimModeIndicatorOptional. Set true if your script prints vim.mode itself, so the mode does not show twice.

The command runs in a shell, so a short job needs no script file. This inline command prints the model and the context percentage:

{
  "statusLine": {
    "type": "command",
    "command": "jq -r '\"[\\(.model.display_name)] \\(.context_window.used_percentage // 0)% context\"'"
  }
}

Claude Code reloads settings on its own and runs the script as soon as you save the file. Make a script file executable first with chmod +x ~/.claude/statusline.sh.

Test with mock input

You can test a script without Claude Code. Pipe in a sample payload:

echo '{"model":{"display_name":"Opus"},"workspace":{"current_dir":"/home/user/project"},"context_window":{"used_percentage":25},"session_id":"test-session-abc"}' | ~/.claude/statusline.sh

Fields you can use

Claude Code sends this JSON on stdin. The fields below are the ones we use most. The docs list more, including session_name, output_style.name, effort.level, pr.number and prompt_cache.

FieldNotes
model.id, model.display_nameCurrent model
workspace.current_dirWorking directory (cwd has the same value)
workspace.project_dirDirectory where Claude Code was launched
cost.total_cost_usdEstimated session cost, computed on the client at list price. It can differ from your bill.
cost.total_duration_msSession time in milliseconds
cost.total_lines_added, cost.total_lines_removedLines changed
context_window.used_percentagePercent of the window used. Can be null early in a session.
context_window.remaining_percentagePercent left. Can be null early in a session.
context_window.current_usageToken counts from the last API call. null until the first response, and null or zeros right after /compact.
rate_limits.five_hour, rate_limits.seven_dayUsed percentage and reset time. Only for claude.ai Pro, Max and Ultra plans (or behind a Claude apps gateway with a spend limit), and only after the first response.
session_idStable for the life of one session
vim.mode, agent.name, worktree.*Present only when vim mode, an agent or a worktree session is active

Three rules keep scripts safe:

  1. Give every field that can be null a fallback, such as // 0 in jq.
  2. Treat optional fields as missing: jq -r '.rate_limits.five_hour.used_percentage // empty'.
  3. used_percentage counts input tokens only: input_tokens, cache_creation_input_tokens and cache_read_input_tokens. It leaves out output tokens. If you calculate it yourself, use the same formula.

The percentage can also differ a little from /context. The status line reports the counts from the last API response, and /context adds an estimate for messages since then. For why this number matters, see context window management in Claude Code and how auto-compact works.

Four scripts that work

Save each one as ~/.claude/statusline.sh, run chmod +x on it, and point command at it. We ran each script with the mock input shown above.

A context bar

#!/bin/bash
input=$(cat)

MODEL=$(echo "$input" | jq -r '.model.display_name')
PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)

BAR_WIDTH=10
FILLED=$((PCT * BAR_WIDTH / 100))
EMPTY=$((BAR_WIDTH - FILLED))
BAR=""
[ "$FILLED" -gt 0 ] && printf -v FILL "%${FILLED}s" && BAR="${FILL// /▓}"
[ "$EMPTY" -gt 0 ] && printf -v PAD "%${EMPTY}s" && BAR="${BAR}${PAD// /░}"

echo "[$MODEL] $BAR ${PCT}%"

At 42.7% used, this prints:

[Opus] ▓▓▓▓░░░░░░ 42%

The git branch, cached

git status and git diff can be slow in a big repository, and your script runs often. This script caches the branch for five seconds:

#!/bin/bash
input=$(cat)

SESSION_ID=$(echo "$input" | jq -r '.session_id')
DIR=$(echo "$input" | jq -r '.workspace.current_dir')
MODEL=$(echo "$input" | jq -r '.model.display_name')

# One cache file per session, so concurrent sessions do not mix branches
CACHE_FILE="/tmp/statusline-git-cache-$SESSION_ID"
CACHE_MAX_AGE=5  # seconds

cache_is_stale() {
  [ ! -f "$CACHE_FILE" ] || \
  [ $(($(date +%s) - $(stat -c %Y "$CACHE_FILE" 2>/dev/null || stat -f %m "$CACHE_FILE" 2>/dev/null || echo 0))) -gt $CACHE_MAX_AGE ]
}

if cache_is_stale; then
  git -C "$DIR" branch --show-current > "$CACHE_FILE" 2>/dev/null || : > "$CACHE_FILE"
fi

BRANCH=$(cat "$CACHE_FILE")
echo "[$MODEL] ${BRANCH:-no branch}"

The cache name uses session_id on purpose. A name built from the process ID changes on every run, which defeats the cache. A fixed name shared by all sessions would show one repository’s branch in another. The stat line tries the GNU form first and falls back to the macOS form.

Rate limits

For claude.ai subscribers, the 5-hour and 7-day usage windows are often the number you want to see. The fields are missing for other users, so the script prints only what exists:

#!/bin/bash
input=$(cat)

MODEL=$(echo "$input" | jq -r '.model.display_name')
FIVE_H=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
WEEK=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')

LIMITS=""
[ -n "$FIVE_H" ] && LIMITS="5h: $(printf '%.0f' "$FIVE_H")%"
[ -n "$WEEK" ] && LIMITS="${LIMITS:+$LIMITS }7d: $(printf '%.0f' "$WEEK")%"

[ -n "$LIMITS" ] && echo "[$MODEL] | $LIMITS" || echo "[$MODEL]"

Sample output: [Opus] | 5h: 24% 7d: 41%. Without rate_limits it prints just [Opus].

Two lines, with color

Each line your script prints becomes a row. This one shows the model and folder on the first row, and a colored context bar with cost on the second:

#!/bin/bash
input=$(cat)

MODEL=$(echo "$input" | jq -r '.model.display_name')
DIR=$(echo "$input" | jq -r '.workspace.current_dir')
COST=$(echo "$input" | jq -r '.cost.total_cost_usd // 0')
PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)

CYAN='\033[36m'; GREEN='\033[32m'; YELLOW='\033[33m'; RED='\033[31m'; RESET='\033[0m'

# Bar color by context use: green under 70%, yellow 70-89%, red 90% and up
if [ "$PCT" -ge 90 ]; then COLOR="$RED"
elif [ "$PCT" -ge 70 ]; then COLOR="$YELLOW"
else COLOR="$GREEN"; fi

FILLED=$((PCT / 10)); EMPTY=$((10 - FILLED))
printf -v FILL "%${FILLED}s"; printf -v PAD "%${EMPTY}s"
BAR="${FILL// /█}${PAD// /░}"

echo -e "${CYAN}[$MODEL]${RESET} ${DIR##*/}"
echo -e "${COLOR}${BAR}${RESET} ${PCT}% | $(printf '$%.2f' "$COST")"

Colors need a terminal that supports ANSI codes. Clickable links use OSC 8 escape sequences and need a terminal such as iTerm2, Kitty or WezTerm. Terminal.app does not support them, and SSH or tmux can strip them. Multi-line output with escape codes is also more likely to glitch than plain text. If text looks garbled, try plain output first.

To size output to the terminal, read the COLUMNS and LINES environment variables. Claude Code sets them before each run. tput cols does not work, because Claude Code captures your script’s output instead of connecting it to the terminal.

Troubleshooting a blank status line

Work down this list.

  1. Is the script executable and does it print to stdout? Run chmod +x, and run the script yourself with mock input.
  2. Did you accept the workspace trust dialog? The status line runs a shell command, so it follows the same trust rule as hooks. Until you accept the dialog for the folder, the bar stays blank. claude --debug logs Status line command skipped: workspace trust not accepted.
  3. Does the script exit with code 0? A non-zero exit or empty output blanks the bar.
  4. Is a hook setting turning it off? If disableAllHooks is true outside managed settings, only a statusLine from managed settings runs. If your organization sets allowManagedHooksOnly, your own status line disappears without a warning.
  5. Are you on Windows? Use forward slashes in the command path. Git Bash treats backslashes as escape characters and the command fails with no visible error.
  6. Still stuck? Run claude --debug. It logs your script’s stderr on every run, and its exit code on the first run of a session.

If values show as -- or empty, a field was probably null before the first API response. Add fallbacks. On a narrow terminal, notifications such as MCP errors and update notices share the same row and can cut your output, so keep the first line short.

Where to go next