Claude Code Statusline Configuration
Settings Entry (~/.claude/settings.json)
"statusLine" : {
"type" : " command" ,
"command" : " sh ~/.claude/statusline-command.sh"
}
Script (~/.claude/statusline-command.sh)
#! /bin/bash
input=$( cat)
cwd=$( echo " $input " | jq -r ' .workspace.current_dir // .cwd // ""' )
model=$( echo " $input " | jq -r ' .model.display_name // ""' )
input_tokens=$( echo " $input " | jq -r ' .context_window.current_usage | ((.input_tokens // 0) + (.cache_creation_input_tokens // 0) + (.cache_read_input_tokens // 0))' )
window_size=$( echo " $input " | jq -r ' .context_window.context_window_size // empty' )
# Shorten home directory to ~
home=" $HOME "
short_cwd=" ${cwd/# $home / ~} "
# Get git branch
branch=" "
if [ -d " $cwd /.git" ] || git -C " $cwd " rev-parse --git-dir > /dev/null 2>&1 ; then
branch=$( git -C " $cwd " --no-optional-locks symbolic-ref --short HEAD 2> /dev/null)
fi
# Colors
GREEN=' \033[32m'
CYAN=' \033[36m'
MAGENTA=' \033[35m'
YELLOW=' \033[33m'
RED=' \033[31m'
RESET=' \033[0m'
# Git segment (cyan)
git_segment=" "
if [ -n " $branch " ]; then
git_segment=" ${CYAN} ($branch )${RESET} "
fi
# Model segment (magenta)
model_segment=" "
if [ -n " $model " ]; then
model_segment=" ${MAGENTA} [$model ]${RESET} "
fi
# Context segment (yellow, red if >80%)
context_segment=" "
if [ -n " $input_tokens " ]; then
tokens_k=$(( input_tokens / 1000 ))
if [ -n " $window_size " ]; then
window_k=$(( window_size / 1000 ))
pct=$(( input_tokens * 100 / window_size))
if [ " $pct " -ge 80 ]; then
color=" $RED "
else
color=" $YELLOW "
fi
context_segment=" ${color}${tokens_k} k/${window_k} k${RESET} "
else
context_segment=" ${YELLOW}${tokens_k} k${RESET} "
fi
fi
printf ' %b' " ${GREEN}${short_cwd}${RESET}${git_segment}${model_segment}${context_segment} "
Segment
Color
Example
Current directory
Green
~/Projects/myapp
Git branch
Cyan
(main)
Model name
Magenta
[Opus 4.6]
Context usage
Yellow (red >80%)
45k/1000k