# Claude Code status line

> Source: <https://gist.github.com/burythehammer/bdd832c9b30a63f1e296a72a25e3b062>
> Published: 2026-11-12 11:18:09+00:00

**Recommendation:** When building a Claude Code status line, emit numeric fields first from a single jq pass and default them with ': ${var:=...}' so malformed or non-JSON input can't break the arithmetic.
More in the playbook "Working with AI coding agents": <https://wpnews.pro/playbooks/coding-agents>

|  | #!/usr/bin/env bash | 
|  | # Claude Code status line: folder \| branch \| model · effort \| context bar \| 5-hour limit left \| reset countdown \| 7-day limit left (from 50% used) | 
|  |  | 
|  | # One jq pass: the numbers on the first line ("-" when absent), then text values one per line, the path last, | 
|  | # so a newline in any text value can't shift the numbers that reach bash arithmetic | 
|  | { read -r pct rate_used reset_secs week_used; IFS= read -r model; IFS= read -r effort; IFS= read -r full_dir; } < <(jq -r ' | 
|  | def whole: if . then floor else "-" end; | 
|  | .rate_limits as $r \| | 
|  | "\(.context_window.used_percentage // 0 \| floor) \($r.five_hour.used_percentage \| whole) \($r.five_hour.resets_at \| if . then floor - (now \| floor) else "-" end) \($r.seven_day.used_percentage \| whole)", | 
|  | (.model.display_name // ""), | 
|  | (.effort \| if type == "object" then .level else . end // ""), | 
|  | (.workspace.current_dir // .cwd // "") | 
|  | ' 2>/dev/null) | 
|  | # Defaults for when jq printed nothing (input that isn't JSON) | 
|  | : "${pct:=0}" "${rate_used:=-}" "${reset_secs:=-}" "${week_used:=-}" "${full_dir:=$PWD}" | 
|  |  | 
|  | RED=$'\033[31m'; YELLOW=$'\033[33m'; GREEN=$'\033[32m'; RESET=$'\033[0m' | 
|  | # Colour for a percentage used: red from 90, yellow from 70 | 
|  | colour() { | 
|  | if (( $1 >= 90 )); then printf '%s' "$RED" | 
|  | elif (( $1 >= 70 )); then printf '%s' "$YELLOW" | 
|  | else printf '%s' "$GREEN"; fi | 
|  | } | 
|  | # "<label> N% left", coloured by the percentage used | 
|  | left() { printf '%s%s %s%% left%s' "$(colour "$2")" "$1" $(( 100 - $2 )) "$RESET"; } | 
|  |  | 
|  | # Folder: last two path components | 
|  | parent=${full_dir%/*} | 
|  | parts=("📁 ${parent##*/}/${full_dir##*/}") | 
|  |  | 
|  | # Git branch (not in the JSON); empty when HEAD is detached | 
|  | branch=$(git -C "$full_dir" branch --show-current 2>/dev/null) | 
|  | [[ -n "$branch" ]] && parts+=("⎇ $branch") | 
|  |  | 
|  | # Model, with the effort level when the model supports one | 
|  | [[ -n "$model" ]] && parts+=("🤖 $model${effort:+ · $effort}") | 
|  |  | 
|  | # Context window bar | 
|  | filled=$(( pct / 10 )) | 
|  | printf -v bar_fill '%*s' "$filled" ''; printf -v bar_pad '%*s' $(( 10 - filled )) '' | 
|  | parts+=("$(colour "$pct")${bar_fill// /█}${bar_pad// /░}${RESET} ${pct}%") | 
|  |  | 
|  | # 5-hour rate limit remaining and its reset countdown | 
|  | [[ $rate_used != - ]] && parts+=("$(left 5h "$rate_used")") | 
|  | if [[ $reset_secs != - ]]; then | 
|  | if (( reset_secs <= 0 )); then parts+=("↺ now") | 
|  | elif (( reset_secs >= 3600 )); then parts+=("↺ $(( reset_secs / 3600 ))h$(( reset_secs % 3600 / 60 ))m") | 
|  | else parts+=("↺ $(( reset_secs / 60 ))m"); fi | 
|  | fi | 
|  |  | 
|  | # 7-day rate limit remaining, only once half of it is used | 
|  | [[ $week_used != - ]] && (( week_used >= 50 )) && parts+=("$(left 7d "$week_used")") | 
|  |  | 
|  | out=$(printf '%s  \|  ' "${parts[@]}") | 
|  | printf '%s\n' "${out%  \|  }" |
