Skip to content

Commit 7490697

Browse files
shahinyanmclaude
andcommitted
fix(statusline): label cumulative savings + show efficiency %% so the badge can't be misread
The badge rendered ` s:<session> · <project>` — two unlabeled numbers that read like a saved/total ratio (e.g. `s:12.4k · 970.0k` looks like 1.3% saved). Both are SAVINGS: session-saved · project-saved. Label the cumulative one `saved` and append the structural-read efficiency (saved ÷ would-be-raw, from tool-calls), so it's unmistakably a savings number and its real ratio is visible: before: [TP s:12.4k · 970.0k] after: [TP s:17.1k · saved 970.0k 90%] Adds a `wouldbe` sum mode to sum_log for the % baseline. Shell syntax + render verified. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012GujqUM9Rzsu9dmhee8fQy
1 parent 1905f2a commit 7490697

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

hooks/tp-statusline.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ sum_log() {
6464
if (match($0, /"savedTokens"[[:space:]]*:[[:space:]]*-?[0-9]+/)) {
6565
t = substr($0, RSTART, RLENGTH); gsub(/[^0-9-]/, "", t); total += t + 0
6666
}
67+
} else if (mode == "wouldbe") {
68+
# Raw-equivalent tokens the structural reads stood in for (the baseline
69+
# the savings % is measured against): sum of tokensWouldBe.
70+
if (match($0, /"tokensWouldBe"[[:space:]]*:[[:space:]]*-?[0-9]+/)) {
71+
t = substr($0, RSTART, RLENGTH); gsub(/[^0-9-]/, "", t); total += t + 0
72+
}
6773
} else {
6874
rw = 0; rt = 0
6975
if (match($0, /"tokensWouldBe"[[:space:]]*:[[:space:]]*-?[0-9]+/)) {
@@ -165,13 +171,25 @@ if [ -n "$PROJECT_ROOT" ]; then
165171
SESSION_TOTAL=$(($(sum_log "$EVENTS_FILE" saved "$SESSION_ID") + $(sum_log "$TOOLS_FILE" delta "$SESSION_ID")))
166172
fi
167173

174+
# Efficiency of the structural reads: saved ÷ would-be-raw (tool-calls — the
175+
# source with a real baseline). Shown as a % so the savings number reads as a
176+
# RATIO of what those reads WOULD have cost, not a fraction of the whole context.
177+
WOULDBE=$(sum_log "$TOOLS_FILE" wouldbe "")
178+
TOOLS_SAVED=$(sum_log "$TOOLS_FILE" delta "")
179+
EFF=""
180+
if [ "$WOULDBE" -gt 0 ] 2>/dev/null; then
181+
EFF=" $((TOOLS_SAVED * 100 / WOULDBE))%"
182+
fi
183+
184+
# Label the cumulative number "saved" + append the efficiency %, so it can't be
185+
# misread as "saved / total-context". `s:` is the live per-session figure.
168186
if [ "$SESSION_TOTAL" -gt 0 ] 2>/dev/null && [ "$PROJECT_TOTAL" -gt 0 ] 2>/dev/null; then
169-
SAVED_SUFFIX=" s:$(fmt_tokens "$SESSION_TOTAL") · $(fmt_tokens "$PROJECT_TOTAL")"
187+
SAVED_SUFFIX=" s:$(fmt_tokens "$SESSION_TOTAL") · saved $(fmt_tokens "$PROJECT_TOTAL")$EFF"
170188
elif [ "$PROJECT_TOTAL" -gt 0 ] 2>/dev/null; then
171189
# Fresh session, nothing saved yet — show the project total alone.
172-
SAVED_SUFFIX=" $(fmt_tokens "$PROJECT_TOTAL")"
190+
SAVED_SUFFIX=" saved $(fmt_tokens "$PROJECT_TOTAL")$EFF"
173191
elif [ "$SESSION_TOTAL" -gt 0 ] 2>/dev/null; then
174-
SAVED_SUFFIX=" s:$(fmt_tokens "$SESSION_TOTAL")"
192+
SAVED_SUFFIX=" s:$(fmt_tokens "$SESSION_TOTAL") saved"
175193
fi
176194
fi
177195

0 commit comments

Comments
 (0)