Skip to content

feat(statusline): show context-token usage below the buddy - #123

Open
skpalan wants to merge 1 commit into
ramarivera:mainfrom
skpalan:feat/statusline-token-usage
Open

feat(statusline): show context-token usage below the buddy#123
skpalan wants to merge 1 commit into
ramarivera:mainfrom
skpalan:feat/statusline-token-usage

Conversation

@skpalan

@skpalan skpalan commented May 30, 2026

Copy link
Copy Markdown

What

Adds a small context-token readout under the buddy in the status line, e.g.:

   /^\
  /\_/\
 ( ×   ×)
 (  ω  )
 (")_(")
    BBQ
  77.3k 7%      ← new: current context tokens + % of the model's window

How

The status line script already received Claude Code's status JSON on stdin but discarded it (cat > /dev/null). This captures it instead and:

  1. Reads transcript_path + model.id from the status JSON.
  2. Greps the last usage block in the transcript JSONL and sums input_tokens + cache_read_input_tokens + cache_creation_input_tokens to approximate the live context size.
  3. Picks the denominator from the model id — 1m/[1m] → 1,000,000, otherwise 200,000 — and renders <tokens> <pct>%, centered under the name.

Safety / compatibility

  • Degrades silently. No transcript, no usage block, or empty stdin → no line is added, so behaviour is unchanged when the data isn't there.
  • Touches only the two existing insertion points (stdin drain + the name-line append); the server-rendered frame pipeline is untouched.
  • bash -n clean; verified rendering against a synthetic transcript on both 1M and 200k models.

Open question for maintainers

It's currently always-on. Happy to gate it behind a showTokens flag in config.json (and a /buddy statusline tokens on|off toggle) if you'd prefer it opt-in — let me know and I'll add it.

Capture the Claude Code status JSON from stdin (previously drained to
/dev/null), read the latest usage block from the session transcript, and
render a centered "<tokens> <pct>%" line under the buddy name, e.g.
"77.3k 7%".

- Sums input_tokens + cache_read_input_tokens + cache_creation_input_tokens
  to approximate the current context size.
- Detects 1M-context models (id contains "1m"/"[1m]") for the percentage
  denominator; defaults to 200k otherwise.
- Degrades silently: no transcript / no usage / empty stdin yields no line,
  so existing behaviour is unchanged when the data is absent.
@ramarivera

Copy link
Copy Markdown
Owner

Hey @skpalan — thanks for this fix! The only thing blocking it from getting CI + review is the DCO check: the commit(s) are missing a Signed-off-by line.

Quick fix from your branch:

git commit --amend -s --no-edit   # single commit
# or, for multiple commits:
git rebase --signoff origin/main
git push --force-with-lease

Once DCO goes green we can run CI and get this reviewed — it's a small, wanted change.

🤖 Created with the help of AI (Claude Fable 5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants