Created
May 26, 2026 10:03
-
-
Save nucliweb/d93d0a4075b586156ec45a1700cdeeb1 to your computer and use it in GitHub Desktop.
Claude Code Statusline
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 | |
| # Read JSON input from stdin | |
| input=$(cat) | |
| # Extract values using jq | |
| MODEL=$(echo "$input" | jq -r '.model.display_name') | |
| CONTEXT_SIZE=$(echo "$input" | jq -r '.context_window.context_window_size') | |
| USAGE=$(echo "$input" | jq '.context_window.current_usage') | |
| CWD=$(echo "$input" | jq -r '.cwd') | |
| # --- Catppuccin Mocha palette (ANSI 24-bit colors) --- | |
| # peach=#fab387 yellow=#f9e2af green=#a6e3a1 red=#f38ba8 sapphire=#74c7ec crust=#11111b | |
| FG_CRUST="\033[38;2;17;17;27m" | |
| BG_PEACH="\033[48;2;250;179;135m" | |
| BG_YELLOW="\033[48;2;249;226;175m" | |
| BG_GREEN="\033[48;2;166;227;161m" | |
| BG_RED="\033[48;2;243;139;168m" | |
| BG_SAPPHIRE="\033[48;2;116;199;236m" | |
| FG_PEACH="\033[38;2;250;179;135m" | |
| FG_YELLOW="\033[38;2;249;226;175m" | |
| FG_GREEN="\033[38;2;166;227;161m" | |
| FG_RED="\033[38;2;243;139;168m" | |
| FG_SAPPHIRE="\033[38;2;116;199;236m" | |
| RESET="\033[0m" | |
| SEP="" # Powerline right-arrow (U+E0B0) | |
| # --- Directory (truncated to last 2 parts, like Starship) --- | |
| HOME_REPLACED="${CWD/#$HOME/~}" | |
| IFS='/' read -ra PARTS <<< "$HOME_REPLACED" | |
| NUM_PARTS=${#PARTS[@]} | |
| if [ "$NUM_PARTS" -le 2 ]; then | |
| SHORT_DIR="$HOME_REPLACED" | |
| else | |
| SHORT_DIR="…/${PARTS[$((NUM_PARTS-2))]}/${PARTS[$((NUM_PARTS-1))]}" | |
| fi | |
| # --- Git branch and richer status --- | |
| IN_GIT=false | |
| GIT_TEXT="" | |
| if git -C "$CWD" rev-parse --git-dir >/dev/null 2>&1; then | |
| IN_GIT=true | |
| BRANCH=$(git -C "$CWD" symbolic-ref --short HEAD 2>/dev/null || git -C "$CWD" rev-parse --short HEAD 2>/dev/null) | |
| STAGED=$(git -C "$CWD" diff --cached --name-only 2>/dev/null | wc -l | tr -d ' ') | |
| MODIFIED=$(git -C "$CWD" diff --name-only 2>/dev/null | wc -l | tr -d ' ') | |
| UNPUSHED=$(git -C "$CWD" rev-list --no-walk --count @{u}..HEAD 2>/dev/null || echo 0) | |
| GIT_TEXT=" ${BRANCH}" | |
| [ "$STAGED" -gt 0 ] && GIT_TEXT="${GIT_TEXT} +${STAGED}" | |
| [ "$MODIFIED" -gt 0 ] && GIT_TEXT="${GIT_TEXT} ~${MODIFIED}" | |
| [ "$UNPUSHED" -gt 0 ] && GIT_TEXT="${GIT_TEXT} ↑${UNPUSHED}" | |
| GIT_TEXT="${GIT_TEXT} " | |
| fi | |
| # --- Context window --- | |
| if [ "$USAGE" != "null" ]; then | |
| CURRENT_TOKENS=$(echo "$USAGE" | jq '.input_tokens + .output_tokens + .cache_creation_input_tokens + .cache_read_input_tokens') | |
| PERCENT_REAL=$(echo "scale=0; ($CURRENT_TOKENS * 100 + $CONTEXT_SIZE / 2) / $CONTEXT_SIZE" | bc) | |
| else | |
| PERCENT_REAL=10 | |
| fi | |
| # Dynamic context background and matching foreground | |
| # Green: <60% Yellow: 60-79% Red: 80%+ | |
| if [ "$PERCENT_REAL" -ge 80 ]; then | |
| BG_CTX="$BG_RED" | |
| FG_CTX="$FG_RED" | |
| elif [ "$PERCENT_REAL" -ge 60 ]; then | |
| BG_CTX="$BG_YELLOW" | |
| FG_CTX="$FG_YELLOW" | |
| else | |
| BG_CTX="$BG_GREEN" | |
| FG_CTX="$FG_GREEN" | |
| fi | |
| # --- Assemble status line with Powerline separators --- | |
| # Segment order: dir (peach) → git (yellow) → model (sapphire) → ctx (dynamic) | |
| # Each separator: FG = prev segment BG color, BG = next segment BG color | |
| if $IN_GIT; then | |
| # dir → git → model → ctx | |
| printf "${BG_PEACH}${FG_CRUST} ${SHORT_DIR} " | |
| printf "${BG_YELLOW}${FG_PEACH}${SEP}" | |
| printf "${FG_CRUST}${GIT_TEXT}" | |
| printf "${BG_SAPPHIRE}${FG_YELLOW}${SEP}" | |
| printf "${FG_CRUST} ${MODEL} " | |
| printf "${BG_CTX}${FG_SAPPHIRE}${SEP}" | |
| printf "${FG_CRUST} ${PERCENT_REAL}%% ctx " | |
| printf "${RESET}${FG_CTX}${SEP}${RESET}" | |
| else | |
| # dir → model → ctx | |
| printf "${BG_PEACH}${FG_CRUST} ${SHORT_DIR} " | |
| printf "${BG_SAPPHIRE}${FG_PEACH}${SEP}" | |
| printf "${FG_CRUST} ${MODEL} " | |
| printf "${BG_CTX}${FG_SAPPHIRE}${SEP}" | |
| printf "${FG_CRUST} ${PERCENT_REAL}%% ctx " | |
| printf "${RESET}${FG_CTX}${SEP}${RESET}" | |
| fi | |
| printf "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment