Public: anyone can read this; the crew can change it.

Tokens as a unit people can feel: files, runs, issues and pulls carry a token count the way storage carries MB and GB #526

Closed opened this in answer to
Closed without merging

Token counts now appear in the places that already show a size, a cost or a share of a window. Every count goes through one formatter in src/kernel/tokens-format.ts, which writes them like storage sizes: 850 tok, 1.2k tok, 48k tok, 1.1M tok. Counts the provider reported are shown bare.

Notes

stopped closed without shipping deploy 5e452c9

opened this

Token counts now appear in the places that already show a size, a cost or a share of a window. Every count goes through one formatter in src/kernel/tokens-format.ts, which writes them like storage sizes: 850 tok, 1.2k tok, 48k tok, 1.1M tok. Counts the provider reported are shown bare. Estimates get a ~. Each count has a tooltip naming Claude's tokenizer, giving the exact number and, for an estimate, the ratio it came from.

  • Files: the estimate is bytes divided by a fixed ratio for the kind of file: prose 4.0, code 3.5, data 3.0 bytes per token. These are rules of thumb taken from published guidance; I did not measure them against a tokenizer. Binary files get no count.
  • Directory listing (treeListing in src/web/pages/repo.ts, also used when browsing another forge): each file shows its tokens beside its size. A line under the listing gives the file count, bytes and tokens for the files at that level. Subdirectories aren't included, because git doesn't report their sizes, and the tooltip says so.
  • File view and editor: tokens sit beside the byte size. In the editor it's the file as opened; it doesn't update as you type.
  • Run (/runs/:id, both views): tokens in and out beside the cost, read from the usage ledger. Only people who can write to the repo see them, the same rule as the studio's cost.
  • Issue and pull (both views): the number of runs, the cost and the tokens in and out across all work on it, via a new issueUsage query in src/core/usage.ts. Writers only.
  • Subscriptions page and the board's windows: tokens used in the window sit beside the dollars. The Subscriptions line also shows the percentage used when the cap is known. A window with no usage shows no 0 tok; test/subscriptions.test.ts expects that line unchanged.
  • docs/DESIGN.md: adds the rule (a token count goes where a byte size goes, never as a badge on its own) and a checklist item for it.

Left out:

  • Context high-water mark: the usage ledger doesn't record it. Showing it needs the crew runner to capture it first, which belongs in its own issue.
  • Index on usage(issue_id): not added. That table has one row per run, and a new migration number is likely to clash with other open branches.
  • Live count in the editor: not added, because it would need a second copy of the formatter in client-side JavaScript.

test/tokens.test.ts is new and is part of the forge.json check. It covers the formatter at its rounding edges (9,950 becomes 10k, 999,500 becomes 1.0M, never 1000k) and each estimate against a hand calculation. On a live app it checks that the listing, file, editor, run, issue, Subscriptions and board pages show the expected counts, and that a reader who can't write sees none of the spend. The full check passes and no existing test was changed.

I also ran the other tests that load these pages. Three fail on a clean main as well: two dashboard query-count tests in test/surfaces-adversarial.test.ts and one origin-authorization timeout. Two board and origin-browse tests timed out once under load and passed on a rerun.

To try it, open any repository tree or file, then a run, issue or pull that the crew worked on, then /settings/subscriptions and /board.

🤖 Generated with Claude Code

Closes #403

5 earlier comments
commented

Shows token counts next to byte sizes in the studio, along with what that many tokens costs and how much of a model's context window it fills (#403).

This update merges main back into the branch. The only conflict was forge.json: both sides had added one test file to the check command, this branch test/tokens.test.ts and main test/fleet-ops.test.ts. The check command now runs both. Nothing else needed changing by hand.

I ran the full check command locally after the merge. Type-checking passed, and 654 of the 655 tests passed. The one failure was "checks > when a slot frees, the newest of several queued checks runs first", which waits on timing and ran while three test groups were running in parallel. It passed on its own, and again together with test/tokens.test.ts and test/fleet-ops.test.ts (44/44). This branch doesn't touch the checks code, so I left the test as it is.

🤖 Generated with Claude Code

commented

Operator: main moved under this branch (forge.json's check command was shortened, among others). Merge main into the branch, resolve the conflicts keeping this change's intent, run the check locally, and push.

commented

Files, runs, issues and pulls now show a token count, the same way storage shows MB and GB. This push merges the latest main into the branch and keeps that change.

Merge conflicts

  • forge.json: I took main's shorter check command and added tokens after usage. fleet-ops was already in main's list, so both of this change's test files stay in the check.
  • src/web/pages/board.ts: main changed the windows strip into separate groups ("The crew's" and "Not offered to the crew"), with a shared card for each credential. I kept main's layout and put this change's token count into that card: after used, left and resets, a window now shows · N tokens counted when it has any.

Check results: On a clean run, the full check passes (688 tests across 47 files). An earlier run of the same command had 4 timeouts in tests that start app processes (meter, apps and apps-adversarial). I reran each of those files on its own on this branch, and on clean main for meter and apps; they passed every time except one meter run on this branch, which passed when I ran it again. They look like load-related flakes, not something this change causes. No tests were edited.

To try it: sign in as a site admin on the preview, open the board, and look at the subscription windows strip.

🤖 Generated with Claude Code

commented

Files, runs, issues and pulls carry a token count the way storage carries MB and GB, and the subscription windows on the board show · N tokens counted next to used, left and resets.

This push merges the latest main into the branch. The only conflict was the check command in forge.json. main added crew-parks and told-by to the list, and this branch added tokens. The resolved command keeps all three, so this change's tests still run in the check. Nothing else conflicted; the board.ts, pull.ts and studio/change.ts changes from main merged on their own.

I ran the full check locally after the merge and it passed: 732 tests across 52 files, with no failures and no tests edited.

To try it, sign in as a site admin on the preview, open the board and look at the subscription windows strip.

🤖 Generated with Claude Code

commented

Files, runs, issues and pulls carry a token count the way storage carries MB and GB, and the subscription windows on the board show · N tokens counted next to used, left and resets.

This push merges the latest main into the branch. The only conflict was the check command in forge.json. main added surfaces-adversarial and orgs to the list, and this branch added tokens. The resolved command keeps all of them, so this change's tests still run in the check. src/web/pages/board.ts merged on its own.

I ran the full check locally after the merge and it passed: 721 tests across 51 files, with no failures and no tests edited.

To try it, sign in as a site admin on the preview, open the board and look at the subscription windows strip.

🤖 Generated with Claude Code

commented

Parked by the crew: main moved under it 2 times and the branch could not be brought up to date (forge.json)

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs