Skip to main content

tōks

PyPI version Python versions License Platform CI Downloads

tōks ("tokes" as in "tokens") counts tokens for files and directories across LLM providers. See how much of a model's context window your content will consume before you spend the tokens. This is particularly useful for context engineering & token budgeting when building software using AI agents.

Installation

Install as a tool with uv:

uv tool install toks

OR, if you're still a "pipper"

pip install toks

The ct ("count tokens") shorthand alias is also available — ct src/ is equivalent to toks src/.

Quick Start

1. Configure your providers

toks setup

The interactive wizard walks you through selecting providers, entering API keys, and choosing models.

2. Count tokens

# Single file
toks src/main.py --for claude

# Entire directory with glob filter
toks src/ --for claude --glob "*.py"

# Quiet mode (just the number)
toks README.md --for claude -q

# Pipe from stdin
cat file.py | toks - --for claude

Output

Provider: claude (claude-opus-5-5)

File                   Tokens  Agent    Web    API
toks/                [17,911]   1.8%   1.8%   1.8%
├── providers/        [4,174]   0.4%   0.4%   0.4%
│   ├── __init__.py       324  <0.1%  <0.1%  <0.1%
│   ├── base.py           474  <0.1%  <0.1%  <0.1%
│   ├── claude.py         600  <0.1%  <0.1%  <0.1%
│   ├── gemini.py         643  <0.1%  <0.1%  <0.1%
│   ├── grok.py         1,315   0.1%   0.1%   0.1%
│   └── openai.py         818  <0.1%  <0.1%  <0.1%
├── __init__.py            33  <0.1%  <0.1%  <0.1%
├── __main__.py            28  <0.1%  <0.1%  <0.1%
├── cli.py              3,188   0.3%   0.3%   0.3%
├── config.py           1,338   0.1%   0.1%   0.1%
├── output.py           2,260   0.2%   0.2%   0.2%
├── registry.py           978  <0.1%  <0.1%  <0.1%
├── runner.py           1,146   0.1%   0.1%   0.1%
├── scanner.py          1,318   0.1%   0.1%   0.1%
└── setup.py            3,448   0.3%   0.3%   0.3%

Total: 17,911 tokens
  Agent (1M):  1.8%
  Web (1M):    1.8%
  API (1M):    1.8%

Three percentage columns show context window usage for each provider's interfaces: coding agent, web chat, and API. The Agent and Web columns populate when you configure your plan and coding agent model via toks setup.

Supported Providers

Provider Text Images PDF Office Docs
Claude (Anthropic) Yes JPEG, PNG, GIF, WebP Yes No
OpenAI Yes JPEG, PNG, GIF, WebP Yes DOCX, XLSX, PPTX
Gemini (Google) Yes JPEG, PNG, GIF, WebP + more Yes No
Grok (xAI) Yes JPEG, PNG (local calc) No No

All token counting is done via each provider's REST API. No local tokenizer libraries are needed.

File Handling

When scanning directories, toks respects .gitignore rules by default — files matching gitignore patterns are skipped. Nested .gitignore files are also respected. Use --no-gitignore to include all files regardless. Binary files are excluded by default (--include-binary to override), and files over 50MB are skipped (--max-size to adjust).

Configuration

Config files live in ~/.config/toks/:

  • config.toml -- provider settings, default model, plan tier
  • .env -- API keys

Re-run toks setup at any time to update your configuration.

Commands

toks <target> [options]    # Count tokens (default command)
toks setup                 # Interactive configuration wizard
toks models --refresh      # List known models / refresh registry

ct can be used anywhere in place of toks.

Options

Flag Description
--for <provider> Provider to use (claude, openai, gemini, grok)
--model <model> Specific model (provider inferred from registry)
--glob <pattern> Filter files by glob pattern
--max-size <size> Exclude files larger than size (default: 50MB)
--depth <n> Limit directory recursion depth (0 = target dir only)
-q / --quiet Output only the total token count
--summary Totals without the tree
--no-progress Suppress progress bar
--concurrency <n> Concurrent API requests (default: 10)
--retries <n> Retry count for transient errors (default: 3)

Documentation

Releasing (maintainer)

Releases are cut from the project root with release X.Y.Z (or release for an interactive version prompt). The tool bumps pyproject.toml, commits, tags, pushes -- which triggers the PyPI publish workflow via GitHub Actions Trusted Publishing. Release notes auto-generate from commit messages between tags, so commits should read well as changelog entries.

License

MIT

Metadata

Release files for toks 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for toks 0.3.5
File Size Uploaded Provenance Actions
toks-0.3.5.tar.gz 19.2 kB Without provenance Details for toks-0.3.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for toks 0.3.5
File Interpreter ABI Platform Actions
toks-0.3.5-py3-none-any.whl Python 3 none any Details for toks-0.3.5-py3-none-any.whl

Total release size: 44.8 kB

Release files / toks-0.3.5.tar.gz

Download URL toks-0.3.5.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
056ac2b8a325a059035e241effb701390d1ff6a35e22496693c3f8171bb29702
BLAKE2b-256 checksum
How to use checksums
b1b7a459c87335d8c3e5df1e5ba716fb10c05b213eed8206f86f63cc738b7356
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / toks-0.3.5-py3-none-any.whl

Download URL toks-0.3.5-py3-none-any.whl
Size 25.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b5b3ee3ce8bd3082ea1a498a5b6239a5df90dda1f3868bfba166f5ec0dde3742
BLAKE2b-256 checksum
How to use checksums
6f36b78b59f7aa03b8f8a89b5fe009d4039bafdf597927db74ecb5a05d35a921
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for toks 0.3.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page