{"slug": "claude-code-status-line", "title": "Claude Code status line", "summary": "A developer published a bash script that renders a custom Claude Code status line, parsing the tool's JSON session data with a single jq pass to display the current folder, git branch, model and effort level, a context-window usage bar, remaining 5-hour and 7-day rate limits, and a reset countdown. The script extracts numeric fields first so newlines in text values cannot corrupt the bash arithmetic, applies green/yellow/red coloring at 70% and 90% usage, and only shows the 7-day limit once half of it is consumed.", "body_md": "|  | #!/usr/bin/env bash | \n|  | # Claude Code status line: folder \\| branch \\| model · effort \\| context bar \\| 5-hour limit left \\| reset countdown \\| 7-day limit left (from 50% used) | \n|  |  | \n|  | # One jq pass: the numbers on the first line (\"-\" when absent), then text values one per line, the path last, | \n|  | # so a newline in any text value can't shift the numbers that reach bash arithmetic | \n|  | { read -r pct rate_used reset_secs week_used; IFS= read -r model; IFS= read -r effort; IFS= read -r full_dir; } < <(jq -r ' | \n|  | def whole: if . then floor else \"-\" end; | \n|  | .rate_limits as $r \\| | \n|  | \"\\(.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)\", | \n|  | (.model.display_name // \"\"), | \n|  | (.effort \\| if type == \"object\" then .level else . end // \"\"), | \n|  | (.workspace.current_dir // .cwd // \"\") | \n|  | ' 2>/dev/null) | \n|  | # Defaults for when jq printed nothing (input that isn't JSON) | \n|  | : \"${pct:=0}\" \"${rate_used:=-}\" \"${reset_secs:=-}\" \"${week_used:=-}\" \"${full_dir:=$PWD}\" | \n|  |  | \n|  | RED=$'\\033[31m'; YELLOW=$'\\033[33m'; GREEN=$'\\033[32m'; RESET=$'\\033[0m' | \n|  | # Colour for a percentage used: red from 90, yellow from 70 | \n|  | colour() { | \n|  | if (( $1 >= 90 )); then printf '%s' \"$RED\" | \n|  | elif (( $1 >= 70 )); then printf '%s' \"$YELLOW\" | \n|  | else printf '%s' \"$GREEN\"; fi | \n|  | } | \n|  | # \"<label> N% left\", coloured by the percentage used | \n|  | left() { printf '%s%s %s%% left%s' \"$(colour \"$2\")\" \"$1\" $(( 100 - $2 )) \"$RESET\"; } | \n|  |  | \n|  | # Folder: last two path components | \n|  | parent=${full_dir%/*} | \n|  | parts=(\"📁 ${parent##*/}/${full_dir##*/}\") | \n|  |  | \n|  | # Git branch (not in the JSON); empty when HEAD is detached | \n|  | branch=$(git -C \"$full_dir\" branch --show-current 2>/dev/null) | \n|  | [[ -n \"$branch\" ]] && parts+=(\"⎇ $branch\") | \n|  |  | \n|  | # Model, with the effort level when the model supports one | \n|  | [[ -n \"$model\" ]] && parts+=(\"🤖 $model${effort:+ · $effort}\") | \n|  |  | \n|  | # Context window bar | \n|  | filled=$(( pct / 10 )) | \n|  | printf -v bar_fill '%*s' \"$filled\" ''; printf -v bar_pad '%*s' $(( 10 - filled )) '' | \n|  | parts+=(\"$(colour \"$pct\")${bar_fill// /█}${bar_pad// /░}${RESET} ${pct}%\") | \n|  |  | \n|  | # 5-hour rate limit remaining and its reset countdown | \n|  | [[ $rate_used != - ]] && parts+=(\"$(left 5h \"$rate_used\")\") | \n|  | if [[ $reset_secs != - ]]; then | \n|  | if (( reset_secs <= 0 )); then parts+=(\"↺ now\") | \n|  | elif (( reset_secs >= 3600 )); then parts+=(\"↺ $(( reset_secs / 3600 ))h$(( reset_secs % 3600 / 60 ))m\") | \n|  | else parts+=(\"↺ $(( reset_secs / 60 ))m\"); fi | \n|  | fi | \n|  |  | \n|  | # 7-day rate limit remaining, only once half of it is used | \n|  | [[ $week_used != - ]] && (( week_used >= 50 )) && parts+=(\"$(left 7d \"$week_used\")\") | \n|  |  | \n|  | out=$(printf '%s  \\|  ' \"${parts[@]}\") | \n|  | printf '%s\\n' \"${out%  \\|  }\" |", "url": "https://wpnews.pro/news/claude-code-status-line", "canonical_source": "https://gist.github.com/burythehammer/bdd832c9b30a63f1e296a72a25e3b062", "published_at": "2026-11-12 11:18:09+00:00", "updated_at": "2026-11-24 08:43:03.055397+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents"], "entities": ["Claude Code", "Anthropic", "jq", "Git"], "also_reported_by": [], "takeaway": "Parsing Claude Code's status JSON with one jq pass that emits numeric fields before text values prevents newlines in paths or model names from shifting the numbers fed into bash arithmetic.", "recommendation": {"advice": "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.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/claude-code-status-line", "markdown": "https://wpnews.pro/news/claude-code-status-line.md", "text": "https://wpnews.pro/news/claude-code-status-line.txt", "jsonld": "https://wpnews.pro/news/claude-code-status-line.jsonld"}}