Skip to content

Commit 9183bed

Browse files
committed
feat(statusline): replace progress bar with token count display
Show used/total tokens (e.g. 30k/200k) instead of a block progress bar.
1 parent 82baee4 commit 9183bed

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

home/.claude/statusline.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@
33
input=$(cat)
44

55
MODEL=$(echo "$input" | jq -r '.model.display_name')
6+
TOTAL=$(echo "$input" | jq -r '.context_window.context_window_size // 0')
67
PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)
8+
USED=$((PCT * TOTAL / 100))
79

8-
BAR_WIDTH=10
9-
FILLED=$((PCT * BAR_WIDTH / 100))
10-
EMPTY=$((BAR_WIDTH - FILLED))
11-
BAR=""
12-
[ "$FILLED" -gt 0 ] && BAR=$(printf "%${FILLED}s" | tr ' ' '')
13-
[ "$EMPTY" -gt 0 ] && BAR="${BAR}$(printf "%${EMPTY}s" | tr ' ' '')"
10+
fmt_k() {
11+
local n=$1
12+
if [ "$n" -ge 1000000 ]; then
13+
echo "$((n / 1000000))M"
14+
elif [ "$n" -ge 1000 ]; then
15+
echo "$((n / 1000))k"
16+
else
17+
echo "${n}"
18+
fi
19+
}
20+
21+
USED_FMT=$(fmt_k "$USED")
22+
TOTAL_FMT=$(fmt_k "$TOTAL")
1423

1524
CWD=$(echo "$input" | jq -r ".workspace.current_dir")
1625
DIR=$(basename "$CWD")
1726
BRANCH=$(git rev-parse --git-dir >/dev/null 2>&1 && git branch --show-current 2>/dev/null)
1827

19-
echo "[$MODEL] $BAR $PCT% | $DIR${BRANCH:+ ($BRANCH)}"
28+
echo "$MODEL · ${USED_FMT}/${TOTAL_FMT} (${PCT}%) · $DIR${BRANCH:+ ($BRANCH)}"

0 commit comments

Comments
 (0)