Last active
October 29, 2025 03:04
-
-
Save bebeal/ea0adb2c3cabdf8b8bc59b9063ed6560 to your computer and use it in GitHub Desktop.
Claude Status Line V0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Output format: {folder_icon} {dir} | {git_icon} {branch} S:{staged} U:{unstaged} A:{untracked} {padding} {model_icon} {model} | ${cost} | {context_pct}% | | |
| parse_transcript() { | |
| local transcript_path="$1" | |
| local model_id="$2" | |
| if [[ ! -f "$transcript_path" ]]; then | |
| echo "0 0" | |
| return | |
| fi | |
| local usage=$(tail -100 "$transcript_path" | tac | jq -s ' | |
| map(select(.message.usage != null and (.isSidechain // false) == false)) | .[0].message.usage' 2>/dev/null) | |
| if [[ -z "$usage" || "$usage" == "null" ]]; then | |
| echo "0 0" | |
| return | |
| fi | |
| local context_length=$(echo "$usage" | jq '(.input_tokens // 0) + (.cache_read_input_tokens // 0) + (.cache_creation_input_tokens // 0)') | |
| local total_tokens=$(echo "$usage" | jq '(.input_tokens // 0) + (.cache_read_input_tokens // 0) + (.cache_creation_input_tokens // 0) + (.output_tokens // 0)') | |
| local max_tokens=200000 | |
| local context_pct=$(echo "scale=1; ($context_length * 100) / $max_tokens" | bc 2>/dev/null || echo "0") | |
| echo "$context_pct $total_tokens" | |
| } | |
| shorten_dir() { | |
| local dir="${1/#$HOME/\~}" | |
| [[ ${#dir} -gt 60 ]] && echo "$dir" | awk -F'/' '{print $(NF-2)"/"$(NF-1)"/"$NF}' || echo "$dir" | |
| } | |
| input=$(cat) | |
| cwd=$(echo "$input" | jq -r '.workspace.current_dir') | |
| model=$(echo "$input" | jq -r '.model.display_name') | |
| model_id=$(echo "$input" | jq -r '.model.id') | |
| cost_usd=$(echo "$input" | jq -r '.cost.total_cost_usd // 0') | |
| transcript_path=$(echo "$input" | jq -r '.transcript_path') | |
| ICON_FOLDER=$(printf '\ue5ff') | |
| ICON_GIT=$(printf '\uf418') | |
| ICON_MODEL=$(printf '\uec10') | |
| short_dir=$(shorten_dir "$cwd") | |
| git_info="" | |
| if git --no-optional-locks -C "$cwd" rev-parse --git-dir > /dev/null 2>&1; then | |
| branch=$(git --no-optional-locks -C "$cwd" symbolic-ref --short HEAD 2>/dev/null || \ | |
| git --no-optional-locks -C "$cwd" rev-parse --short HEAD 2>/dev/null) | |
| staged=$(git --no-optional-locks -C "$cwd" diff --cached --numstat 2>/dev/null | wc -l | tr -d ' ') | |
| unstaged=$(git --no-optional-locks -C "$cwd" diff --numstat 2>/dev/null | wc -l | tr -d ' ') | |
| untracked=$(git --no-optional-locks -C "$cwd" ls-files --others --exclude-standard 2>/dev/null | wc -l | tr -d ' ') | |
| git_info="\033[33m${ICON_GIT} ${branch} S:${staged} U:${unstaged} A:${untracked}\033[0m" | |
| fi | |
| read context_pct token_count < <(parse_transcript "$transcript_path" "$model_id") | |
| left_output="\033[36m${ICON_FOLDER} ${short_dir}\033[0m" | |
| [[ -n "$git_info" ]] && left_output+=" | ${git_info}" | |
| right_output="${ICON_MODEL} ${model} | \$$(printf "%.2f" "$cost_usd")" | |
| [[ -n "$context_pct" && "$context_pct" != "0" ]] && right_output+=" | ${context_pct}%" | |
| right_output+=" |" | |
| term_width=$(stty size </dev/tty 2>/dev/null | cut -d' ' -f2) | |
| left_len=$(printf "%b" "$left_output" | sed 's/\x1b\[[0-9;]*m//g' | wc -m | tr -d ' ') | |
| right_len=$(printf "%b" "$right_output" | sed 's/\x1b\[[0-9;]*m//g' | wc -m | tr -d ' ') | |
| token_space=$(printf "${token_count} tokens" | wc -m | tr -d ' ') | |
| available=$((term_width - token_space - 2)) | |
| padding=$((available - left_len - right_len - 3)) | |
| printf "%b%*s%b\n" "$left_output" "$padding" "" "$right_output" |
Author
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nooo the spacing breaks with the right side popups (e.g. for thinking) :-(
