Last active
January 21, 2026 00:31
-
-
Save tmokmss/dc02cd6f94495ab92a46b1dbc9e24e0d to your computer and use it in GitHub Desktop.
My statusline.sh for Claude Code
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 | |
| # Put this file in ~/.claude/statusline.sh | |
| # Read JSON input once | |
| input=$(cat) | |
| # Helper functions for common extractions | |
| get_model_name() { echo "$input" | jq -r '.model.display_name'; } | |
| get_current_dir() { echo "$input" | jq -r '.workspace.current_dir'; } | |
| get_project_dir() { echo "$input" | jq -r '.workspace.project_dir'; } | |
| get_version() { echo "$input" | jq -r '.version'; } | |
| get_cost() { echo "$input" | jq -r '.cost.total_cost_usd'; } | |
| get_duration() { echo "$input" | jq -r '.cost.total_duration_ms'; } | |
| get_lines_added() { echo "$input" | jq -r '.cost.total_lines_added'; } | |
| get_lines_removed() { echo "$input" | jq -r '.cost.total_lines_removed'; } | |
| get_input_tokens() { echo "$input" | jq -r '.context_window.total_input_tokens'; } | |
| get_output_tokens() { echo "$input" | jq -r '.context_window.total_output_tokens'; } | |
| get_context_window_size() { echo "$input" | jq -r '.context_window.context_window_size'; } | |
| get_current_usage() { echo "$input" | jq -r '.context_window.current_usage'; } | |
| get_input_usage() { echo "$input" | jq -r '.context_window.current_usage.input_tokens'; } | |
| get_cache_w_usage() { echo "$input" | jq -r '.context_window.current_usage.cache_creation_input_tokens'; } | |
| get_cache_r_usage() { echo "$input" | jq -r '.context_window.current_usage.cache_read_input_tokens'; } | |
| MODEL=$(get_model_name) | |
| CONTEXT_SIZE=$(get_context_window_size) | |
| USAGE=$(get_current_usage) | |
| USAGE_IN=$(($(get_input_tokens) / 1000)) | |
| USAGE_OUT=$(($(get_output_tokens) / 1000)) | |
| # Format number with k suffix if >= 1000 | |
| format_k() { | |
| local val=$1 | |
| if [ "$val" -ge 1000 ]; then | |
| echo "$((val / 1000))k" | |
| else | |
| echo "$val" | |
| fi | |
| } | |
| INPUT_USAGE_RAW=$(($(get_input_usage))) | |
| CACHE_W_USAGE_RAW=$(($(get_cache_w_usage))) | |
| CACHE_R_USAGE_RAW=$(($(get_cache_r_usage))) | |
| INPUT_USAGE=$(format_k $INPUT_USAGE_RAW) | |
| CACHE_W_USAGE=$(format_k $CACHE_W_USAGE_RAW) | |
| CACHE_R_USAGE=$(format_k $CACHE_R_USAGE_RAW) | |
| PERCENT_USED=$(echo "$input" | jq -r '.context_window.used_percentage // 0') | |
| # ANSI color codes | |
| GREEN='\033[32m' | |
| YELLOW='\033[33m' | |
| RED='\033[31m' | |
| DIM='\033[90m' | |
| RESET='\033[0m' | |
| # Color based on usage percentage | |
| PERCENT_INT=${PERCENT_USED%.*} | |
| if [ "$PERCENT_INT" -ge 80 ]; then | |
| PERCENT_COLOR=$RED | |
| elif [ "$PERCENT_INT" -ge 50 ]; then | |
| PERCENT_COLOR=$YELLOW | |
| else | |
| PERCENT_COLOR=$GREEN | |
| fi | |
| COLORED_PERCENT="${PERCENT_COLOR}${PERCENT_USED}%${RESET}" | |
| COST=$(printf "%.3f\n" $(get_cost)) | |
| VERSION=$(get_version) | |
| WINDOW=$(($(get_context_window_size) / 1000)) | |
| echo -e "[$MODEL] ${COLORED_PERCENT} (${INPUT_USAGE}+${CACHE_W_USAGE}+${CACHE_R_USAGE}/${WINDOW}k) \$$COST ${DIM}v$VERSION${RESET}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment