Skip to content

feat(cli): add /tokens to estimate token count of arbitrary text#174

Merged
emal-avala merged 1 commit intomainfrom
feat/cmd-tokens
Apr 23, 2026
Merged

feat(cli): add /tokens to estimate token count of arbitrary text#174
emal-avala merged 1 commit intomainfrom
feat/cmd-tokens

Conversation

@emal-avala
Copy link
Copy Markdown
Member

Summary

Adds `/tokens ` — prints token count, character count, byte count, and chars/token ratio for arbitrary text.

Uses `services::tokens::estimate_tokens` — same counter the query engine uses for budget tracking, so the number matches what `/cost` and `/usage` report.

Why

Two common uses:

  1. "Is this file small enough to read in one tool call, or should I grep first?" — quick check without firing a read
  2. Comparing two phrasings of a prompt to see which compresses better (the `chars/token` ratio makes this explicit)

Test plan

  • `cargo fmt --all` clean
  • `cargo check` passes
  • `cargo clippy --no-deps` clean
  • Manual: `/tokens hello world` prints a plausible token count
  • Manual: `/tokens` with no args prints usage

Useful for prompt engineering and "how much of the context window will
this take?" checks. Prints tokens, chars, bytes, and the chars/token
ratio — the ratio is the interesting number when comparing how well
different phrasings compress.

Uses the existing `services::tokens::estimate_tokens` — same counter
the engine uses for budget tracking.
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@emal-avala emal-avala merged commit 6269971 into main Apr 23, 2026
13 of 14 checks passed
@emal-avala emal-avala deleted the feat/cmd-tokens branch April 23, 2026 01:30
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.

1 participant