Two things quietly derail long Claude Code sessions: the context window fills up and auto-compacts before you notice, wiping out critical decisions; or you forget about uncommitted Git changes and let Claude work on top of a dirty tree.
The default status line only shows the model name and context percentage. You cannot see your Git state, how fast you are burning tokens, or whether prompt caching is actually hitting—all essentials for long sessions.
Claude Code supports custom status lines: drop a script at a configured path and it refreshes every 5 seconds. Here is my full implementation, along with the key design decisions and the pitfalls I hit along the way.
Restart Claude Code for the changes to take effect. The script depends on jq for JSON parsing—install it via sudo apt install jq -y if it is not already available.
if [ "$cache_hit" -ge 0 ]; then if [ "$cache_hit" -ge 80 ]; then cache_color="$GREEN" elif [ "$cache_hit" -ge 50 ]; then cache_color="$YELLOW" else cache_color="$RED"; fi cache_part=" ${DIM}|${RESET} 📦${cache_color}${cache_hit}%${RESET}" else cache_part=""; fi
if [ "$api_pct" -ge 60 ]; then api_part=" ${DIM}|${RESET} ⏳${RED}${api_pct}%${RESET}" elif [ "$api_pct" -ge 30 ]; then api_part=" ${DIM}|${RESET} ⏳${YELLOW}${api_pct}%${RESET}" else api_part=" ${DIM}|${RESET} ⏳${GREEN}${api_pct}%${RESET}"; fi
if [ "$used_int" -ge 84 ]; then warn="${RED}[Critical → run /compact now to keep current progress & key decisions]${RESET}" elif [ "$used_int" -ge 75 ]; then warn="${YELLOW}[High → /compact to keep current progress & key decisions]${RESET}" elif [ "$used_int" -ge 60 ]; then warn="${YELLOW}[Elevated → /compact to keep current progress & key decisions]${RESET}" else warn="${GREEN}[OK]${RESET}" fi
line2="${emoji}${bar}${pct_color}${used_int}%${RESET}${size_part}${warn}${speed_part}${cache_part}${api_part}" else line2="🟢 \033[38;2;60;60;60m░░░░░░░░░░░░░░░░░░░░${RESET} --% ${GREEN}[OK]${RESET}" fi
printf'%b\n'"$line1" printf'%b\n'"$line2"
Design Decisions & Pitfalls
From 15 jq Calls Down to 1
My first draft used 15 separate jq -r invocations to pull out each field—spawning 15 subprocesses every 5 seconds. For a high-frequency status line, that overhead was immediately noticeable.
Switching to join("\u0001") extracts every field in one pass, using ASCII SOH (\x01) as the delimiter. Why not tab? Bash’s read collapses consecutive whitespace characters by default, which silently drops empty fields and shifts every variable after them out of alignment. \x01 is an invisible control character that will not appear in JSON values.
I added this flag only after getting burned without it. When the status line ran git diff every 5 seconds, it occasionally collided with a git add or git commit executed by Claude Code, causing intermittent index.lock file exists failures.
--no-optional-locks tells Git: “This is a read-only inspection—do not lock the index.” Because the status line never mutates the repository, adding this flag eliminated the lock collisions completely.
Cache Hit Rate: Not What It Looks Like
The cache_read_input_tokens and cache_creation_input_tokens values that Claude Code passes in are scoped to the single most recent API call, not the cumulative session total. Computing a hit rate directly from per-call numbers causes the percentage to bounce wildly every 5 seconds, making it useless.
My workaround: persist the previous token total in a temp file. Whenever total_tokens changes (indicating a new API call completed), accumulate the new cache read and creation counts. That gives you a true cumulative hit rate across the whole session.
Clickable Repo Links with OSC 8
Clicking (Ctrl+Click) the repository name opens the repo directly on GitHub via the terminal OSC 8 hyperlink escape sequence:
The format is \e]8;;URL\aTEXT\e]8;;\a. It works out of the box in iTerm2, Windows Terminal, and the VS Code integrated terminal. Terminals that do not support OSC 8 simply render plain text with no visual breakage.
Cleaning Up Temporary Files
Both the Git status cache and the cache-hit accumulator write state files under /tmp, which would pile up over time. Running find /tmp -delete on every refresh is wasteful, so the script triggers cleanup probabilistically: RANDOM % 100 runs the sweep roughly 1% of the time. Runtime overhead stays near zero, while stale files never grow unbounded.
Summary
Signal
Purpose
What to Watch For
Git staged / modified / untracked / stash
Workspace state
Catch uncommitted edits or stray files before prompting
>60% means most of the session is spent waiting on the API
Feel free to adapt the script to your own workflow—for example, displaying MCP server health or the active Skill name. Claude Code passes a rich JSON payload on stdin; pipe it through echo "$input" | jq . to inspect every available field.