tokendiet
v1.16.0
Published
Token optimization gateway CLI for Claude Code
Readme
tokendiet
Token optimization gateway CLI for Claude Code. Runs as a local proxy between Claude Code and the Anthropic API, automatically stripping unnecessary tokens before each request — saving you money without changing how you work.
Install
npm install -g tokendietOr run directly with npx:
npx tokendiet@latest startUsage
# Start the gateway
tokendiet start --org-token <token>
# Start with custom options
tokendiet start --org-token <token> --port 3200 --verbose
# Dry-run mode (no stripping — measure baseline)
tokendiet start --org-token <token> --dry-run
# Stop the gateway and restore Claude settings
tokendiet stopIf you don't pass --org-token, the CLI will check for a saved token or prompt you interactively.
Commands
| Command | Description |
|---------|-------------|
| start | Start the local TokenDiet gateway |
| stop | Stop the running gateway and restore Claude settings |
Start options
| Flag | Default | Description |
|------|---------|-------------|
| --org-token <token> | — | Your organization API token |
| --cloud-url <url> | https://tokendiet-production.up.railway.app | Cloud API URL |
| --port <port> | 10741 | Port to listen on |
| --verbose | off | Show full NestJS logs |
| --dry-run | off | Disable all stripping (baseline measurement) |
Stop options
| Flag | Default | Description |
|------|---------|-------------|
| --port <port> | 10741 | Port the gateway is running on |
How it works
- Starts a local proxy on
localhost:10741 - Patches
~/.claude/settings.jsonto route Claude Code traffic through it - Applies stripping strategies to each request before forwarding to Anthropic
- Reports token savings to the cloud API
- Displays live savings feedback in the terminal
- Restores original Claude settings on exit (Ctrl+C) or
tokendiet stop
Token resolution order
--org-tokenCLI flag (highest priority)- Saved token from
~/.tokendiet/.env - Interactive prompt
If a token is rejected (401), the saved token is cleared and you're prompted again.
Stripping strategies
| Strategy | What it removes |
|----------|----------------|
| Whitespace normalization | Unnecessary whitespace from message content and tool results |
| Schema metadata stripping | JSON Schema metadata (descriptions, titles, examples) from the tools array |
Both strategies are deterministic and idempotent — they never change the semantic meaning of your requests.
Data & Privacy
TokenDiet is designed so that your prompts, code, and conversation content never leave your machine via TokenDiet.
What stays on your machine
- Your Anthropic API key — passed directly to Anthropic, never sent to TokenDiet servers
- All prompt and message content — the full request body goes straight to the Anthropic API
- Your code and file contents — TokenDiet strips tokens locally but never reads or stores your code
What is sent to the TokenDiet cloud API
Only usage metadata is reported, so we can calculate your savings:
- Token counts (original, stripped, and actual from the API response)
- Model name (e.g.
claude-opus-4-6) - Cache usage statistics (read/write token counts)
- Which stripping strategies were applied and how many tokens they reduced
- Gateway version and request timestamp
- A session identifier (random UUID) to group requests within the same Claude Code conversation for accurate savings tracking — this ID contains no personal information
What is never sent
- Message content, prompts, or system instructions
- Code, file contents, or tool results
- Your Anthropic API key
Local storage
- Your org token is saved to
~/.tokendiet/.env(file permissions: owner-only read/write) - Claude Code settings are temporarily patched while the gateway runs and restored on exit
Development
# Build and run the CLI with dev defaults (localhost:3001 cloud API)
npm run startLicense
MIT
