Directory Compare FCRS-1.0 /llms.txt
← Back to Directory

ttok

$ ttok Community Low Risk
Simon Willison · Agent Bridges & Meta · Apache-2.0 · macos / linux / windows

ttok (simonw/ttok) is a fast Unix pipeline utility built on tiktoken that counts tokens from stdin or -i files and truncates text cleanly to a -t <tokens> budget. Also supports --encode, --decode, and --model tokenizer selection.

FCRS-1.0 Score
89 /100
Good
Medium Confidence
Zero-Friction Install
brew install ttok
CLI vs MCP Decision CLI Only

ttok enforces strict token budgets on logs, diffs, or files-to-prompt bundles in one local pipe before calling an LLM.

Agent-Readiness Checklist

— JSON Output
— Field Filtering
✓ Non-Interactive
— Dry-Run
— Read-Only Mode
✓ NO_COLOR Clean
✓ Self-Describing
— Official SKILL.md

Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.

FCRS-1.0 6-Dimension Breakdown

Agent-Readiness 22 / 25

Clean Unix stdin/stdout filter returning an exact integer or truncated text with -t, -i, -m, --encode, and --decode.

  • Pure Unix stdin/stdout filter with -t, -i, -m, --encode, --decode
Trust & Safety 25 / 25

100% read-only stateless tokenizer with zero filesystem writes or network calls (once tiktoken BPE cache exists).

  • Stateless read-only tokenizer filter
Setup & Portability 14 / 15

Available via Homebrew, PyPI (pip), and uvx across macOS, Linux, and Windows.

  • Published on Homebrew and PyPI (simonw/ttok)
Utility & Efficiency 13 / 15

Solves exact token counting and -t truncation cleanly in shell scripts without writing Python boilerplate.

  • One-line token budgeting and truncation in Unix pipes
Maintenance & Lineage 8 / 10

Maintained by Simon Willison (simonw/ttok) under Apache-2.0.

  • Active simonw/ttok repository
Docs & Verifiability 7 / 10

Crisp README and --help examples.

  • Official README at github.com/simonw/ttok

Security, Auth & Guardrails

Auth Modes
No Auth
Credential Storage

None; local stateless tokenizer pipeline utility.

Side Effects
Read-Only
Cost & Quotas

100% free and Apache-2.0 open-source.

Copyable Guardrail for CLAUDE.md / AGENTS.md
# ttok Agent Rules
- Pipe large outputs through `ttok` first to check token size before loading into context.
- Use `ttok -t <max_tokens>` to enforce hard token caps on dynamic command output.
- Note `tiktoken` counts are exact for OpenAI encodings (`o200k_base`) and close approximations for Claude/Gemini.

Agent-Ready Command Recipes

Safe Read-Only Queries

Count tokens in a file or stdin stream
ttok -i README.md

Prints the exact integer token count for a file using tiktoken.

Truncate a large log or prompt stream to a token cap
git diff | ttok -t 4000

Trims piped text at exact token boundaries to fit a 4,000-token context budget.

Strengths for Agents

  • + Exact tiktoken-backed token counting and -t truncation in Unix pipes.
  • + Zero-boilerplate companion to files-to-prompt, git diff, and log streams.
  • + Supports --encode, --decode, and --model tokenizer selection.

Caveats & Pitfalls

  • ! Uses OpenAI's tiktoken encodings (o200k_base etc.), so counts for Anthropic/Google models are close estimates rather than exact.
  • ! First run for a new encoding downloads BPE data into tiktoken's local cache.

Tested Agent Hosts

Claude Code Codex CLI Gemini CLI