{"slug": "retok-token-efficiency-analyzer-for-claude-code-and-codex-cli-zero-deps", "title": "Retok: Token-efficiency analyzer for Claude Code and Codex CLI (zero deps)", "summary": "Retok, a zero-dependency Python CLI tool for analyzing token efficiency in Claude Code and OpenAI Codex CLI usage logs, has been released on GitHub. The tool estimates costs, measures cache hit rates, and provides actionable recommendations to reduce AI coding agent expenses. It requires Python 3.7+ and scans local transcript directories to generate reports.", "body_md": "**English** | [日本語](/d-date/retok/blob/main/README.ja.md)\n\nA CLI tool that analyzes your AI coding agent usage logs — **Claude Code** and **OpenAI Codex CLI** — to measure **token efficiency**, estimate cost, and print actionable recommendations.\n\nRuns on Python 3 with the standard library only — no dependencies.\n\n```\n══════════════════════════════════════════════════════════════════════════\n  retok — Token Efficiency Report (last 30 days / 472 files)\n══════════════════════════════════════════════════════════════════════════\n\n■ Overview\n  Estimated cost            $2,119.66\n  Claude Code / Codex       $2,091.00 / $28.66\n  Cache hit rate            89.4%\n  Cost per prompt           $1.593\n  ...\n\n■ Recommendations\n\n  ! Re-caching after cache TTL expiry: ~135.0M tokens ($873.49)\n    Returning to a session left idle beyond the cache TTL (usually 1\n    hour) re-caches the entire context at twice the input rate. ...\n```\n\nRequires Python 3.7+. No dependencies.\n\n```\ngit clone https://github.com/d-date/retok.git\ncd retok\n./retok\n```\n\nTo run it from anywhere, symlink it into your `PATH`\n\n(the symlink is resolved, so translations in `locales/`\n\nkeep working):\n\n```\nln -s \"$(pwd)/retok\" ~/.local/bin/retok   # or /usr/local/bin/retok\nretok\n```\n\nAlternatively, grab just the script — everything works, but the report falls back to English because `locales/`\n\nis not present:\n\n```\ncurl -fsSLo ~/.local/bin/retok https://raw.githubusercontent.com/d-date/retok/main/retok\nchmod +x ~/.local/bin/retok\n./retok                    # report for the last 30 days\n./retok --days 7           # change the window\n./retok --project myapp    # filter by project name (substring)\n./retok --provider codex   # only one provider (claude | codex)\n./retok --lang en          # report language (default: $LANG)\n./retok --json             # JSON output for other tools\n./retok --top 20           # rows in ranking tables\n./retok --dirs ~/somewhere/projects       # override Claude Code roots\n./retok --codex-dirs ~/somewhere/sessions # override Codex roots\n```\n\nBy default it scans Claude Code transcripts in `~/.claude/projects`\n\n(plus `$CLAUDE_CONFIG_DIR/projects`\n\nwhen that environment variable is set) and Codex CLI rollouts in `~/.codex/sessions`\n\n. If you keep transcripts elsewhere (multiple profiles, custom config dirs), pass every root with `--dirs`\n\n/ `--codex-dirs`\n\n. Usage records are deduplicated globally, so overlapping roots are never double-counted.\n\n| Metric | Meaning |\n|---|---|\n| Estimated cost | USD estimate based on published per-model pricing (table below) |\n| Cache hit rate | `cache_read / (input + cache_read + cache_write)` — higher is cheaper |\n| Cost per prompt | Cost consumed per human instruction |\n| Subagent share | Consumption by subagents (Task/Explore; `<session>/subagents/agent-*.jsonl` ) |\n| maxCtx | Peak context size within a session — the bigger, the more each request costs |\n\n**Cache TTL expiry**— a large cache write (majority of the context) right after a gap longer than the write's TTL (1h/5m, detected from the usage buckets) means an expired prefix was re-cached from scratch. Suggests`/compact`\n\n/`/clear`\n\n**Oversized contexts**— sessions exceeding 120k tokens, with at least 3 prompts in the session. Suggests`/clear`\n\nbetween tasks**Under-delegation**— high Read/Grep/Glob share on the main thread with little subagent use** Retry loops**— the same Bash command executed 5+ times within a session** Frequent interruptions**—`[Request interrupted by user]`\n\nabove 12% of prompts, only evaluated once the period has 30+ prompts. Suggests clearer prompts and Plan Mode**Premium models on tiny sessions**— one-shot Q&A on Opus/Fable-class models, 10 or more such sessions in the period** Premium-tier concentration**— a single model priced above the median (currently Fable/Mythos) accounts for 90%+ of total cost, once total cost reaches $50. Suggests delegating light work to a cheaper model\n\nClaude prices (USD / MTok, as of 2026-06):\n\n| Model | input | output |\n|---|---|---|\n| Fable 5 / Mythos 5 | $10 | $50 |\n| Opus 4.x | $5 | $25 |\n| Sonnet 4.x / 5 | $3 | $15 |\n| Haiku 4.5 | $1 | $5 |\n\n- Cache read =\n**0.1×** input rate - Cache write =\n**1.25×** input rate (5-minute TTL) /**2×**(1-hour TTL) — detected from the`cache_creation`\n\nbuckets in usage - One API response is written to the transcript as multiple entries; usage is deduplicated by\n`message.id`\n\nOpenAI (Codex) prices (USD / MTok, as of 2026-07):\n\n| Model | input | output |\n|---|---|---|\n| gpt-5.5 | $5 | $30 |\n| gpt-5.4 | $2.50 | $15 |\n| gpt-5.3 / 5.2 (codex) | $1.75 | $14 |\n| gpt-5.1 / 5.1-codex-max / 5 | $1.25 | $10 |\n| gpt-5-mini / nano | $0.25 / $0.05 | $2 / $0.40 |\n\n- Cached input =\n**0.1×** input rate (no cache-write premium);`cached_input_tokens`\n\nis a subset of`input_tokens`\n\nand is unbundled before pricing - Usage comes from\n`token_count`\n\nevents in`~/.codex/sessions`\n\nrollout files, deduplicated by the cumulative token counter\n\nNote: figures are estimates based on published API pricing. If you are on a subscription plan (e.g. Max), read them as \"how much compute you used in API terms\", not what you actually paid.\n\nThe report language follows `--lang`\n\n, then `RETOK_LANG`\n\n, then `LC_ALL`\n\n/ `LC_MESSAGES`\n\n/ `LANG`\n\n, falling back to English.\n\nAvailable: `en`\n\n(built-in), `ja`\n\n, `zh-CN`\n\n, `zh-TW`\n\n, `ko`\n\n, `es`\n\n, `fr`\n\n, `de`\n\n, `pt-BR`\n\n.\n\n- Copy\n`locales/ja.json`\n\nto`locales/<tag>.json`\n\n(BCP 47-ish tag, e.g.`it`\n\n,`pt-PT`\n\n) - Translate the values — keep the\n`{placeholders}`\n\nintact - Test with\n`./retok --lang <tag>`\n\nand open a pull request\n\nMissing keys fall back to English automatically, so partial translations are fine.", "url": "https://wpnews.pro/news/retok-token-efficiency-analyzer-for-claude-code-and-codex-cli-zero-deps", "canonical_source": "https://github.com/d-date/retok", "published_at": "2026-07-17 13:07:02+00:00", "updated_at": "2026-07-17 13:21:05.524221+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "large-language-models"], "entities": ["Retok", "Claude Code", "OpenAI Codex CLI", "GitHub", "Python"], "alternates": {"html": "https://wpnews.pro/news/retok-token-efficiency-analyzer-for-claude-code-and-codex-cli-zero-deps", "markdown": "https://wpnews.pro/news/retok-token-efficiency-analyzer-for-claude-code-and-codex-cli-zero-deps.md", "text": "https://wpnews.pro/news/retok-token-efficiency-analyzer-for-claude-code-and-codex-cli-zero-deps.txt", "jsonld": "https://wpnews.pro/news/retok-token-efficiency-analyzer-for-claude-code-and-codex-cli-zero-deps.jsonld"}}