claude/hooks/statusline.sh
bastien 35ea5c1a49 audit fixes: RTK hook, settings unification, graphifyy, statusline
- Add RTK PreToolUse hook (rtk-rewrite.sh) and fix missing config
- Unify settings.json: merge hooks, marketplaces, model into project file
  so link.sh symlink is the single source of truth
- Add statusline: model, folder, git branch, context % progress bar
- Add graphifyy support: detect, install (pipx), lock, doctor, session-start
- Clarify ctx7/ruflo as standalone CLI (not MCP servers)
- Fix install-plugins.sh step numbering (duplicate step 6)
- Add version check in session-start (local vs origin/master)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 13:28:30 +02:00

49 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Claude Code statusline — folder, git branch, model, context %
# Receives JSON on stdin from Claude Code.
INPUT=$(cat)
MODEL=$(echo "$INPUT" | jq -r '.model.display_name // "?"')
DIR=$(echo "$INPUT" | jq -r '.cwd // "?"')
FOLDER="${DIR##*/}"
PCT=$(echo "$INPUT" | jq -r \
'.context_window.used_percentage // 0' \
| cut -d. -f1)
# Git branch (fast, no network)
BRANCH=""
if [ -d "$DIR" ]; then
BRANCH=$(git -C "$DIR" branch --show-current 2>/dev/null)
fi
BRANCH_STR="${BRANCH:+ ($BRANCH)}"
# Progress bar (20 chars wide)
WIDTH=20
FILLED=$((PCT * WIDTH / 100))
EMPTY=$((WIDTH - FILLED))
if [ "$FILLED" -gt 0 ]; then
printf -v FILL "%${FILLED}s"
else
FILL=""
fi
if [ "$EMPTY" -gt 0 ]; then
printf -v PAD "%${EMPTY}s"
else
PAD=""
fi
BAR="${FILL// /█}${PAD// /░}"
# Color: green <50%, yellow 50-79%, red >=80%
if [ "$PCT" -ge 80 ]; then
COLOR="\033[31m"
elif [ "$PCT" -ge 50 ]; then
COLOR="\033[33m"
else
COLOR="\033[32m"
fi
RESET="\033[0m"
# Output: single line
echo -e "$MODEL | $FOLDER${BRANCH_STR} | ${COLOR}${BAR}${RESET} ${PCT}%"