Adds a live cost tracker to the Claude Code CLI status bar:
Request: $0.0023 | Session: $0.0042 | Total: $1.2345
1. Create the script
cat > ~/.claude/statusline.sh << 'EOF'
#!/usr/bin/env bash
PREV_COST_FILE="/tmp/claude_prev_cost"
GRAND_TOTAL_FILE="$HOME/.claude/grand_total_cost"
input=$(cat)
current=$(echo "$input" | jq -r '.cost.total_cost_usd // 0')
if [ -f "$PREV_COST_FILE" ]; then
prev=$(cat "$PREV_COST_FILE")
else
prev=0
fi
echo "$current" > "$PREV_COST_FILE"
delta=$(awk "BEGIN { printf \"%.10f\", $current - $prev }")
if [ -f "$GRAND_TOTAL_FILE" ]; then
grand=$(cat "$GRAND_TOTAL_FILE")
else
grand=0
fi
grand=$(awk "BEGIN { printf \"%.10f\", $grand + $delta }")
echo "$grand" > "$GRAND_TOTAL_FILE"
if awk "BEGIN { exit !($delta == 0) }"; then
printf "Session: \$%.4f | Total: \$%.4f" "$current" "$grand"
else
printf "Request: \$%.4f | Session: \$%.4f | Total: \$%.4f" "$delta" "$current" "$grand"
fi
EOF
chmod +x ~/.claude/statusline.sh2. Add to ~/.claude/settings.json
Add this inside the top-level {}:
"statusLine": {
"type": "command",
"command": "bash ~/.claude/statusline.sh"
}3. Restart Claude Code
The status bar appears at the bottom of the interface.
Note: Grand total persists in
~/.claude/grand_total_costacross restarts. Requiresjq(brew install jqon macOS).
rm ~/.claude/statusline.sh
rm ~/.claude/grand_total_cost # optional — deletes cost historyThen remove the "statusLine": { ... } block from ~/.claude/settings.json and restart Claude Code.