explaingit

d-date/retok

Analysis updated 2026-05-18

29PythonAudience · developerComplexity · 1/5LicenseSetup · easy

TLDR

A local command line report card for your Claude Code and Codex CLI usage, showing token cost and where you are wasting tokens.

Mindmap

mindmap
  root((retok))
    What it does
      Reads agent logs
      Estimates cost
      Flags waste
    Tech stack
      Python standard library
      No dependencies
    Use cases
      Track token cost
      Find cache waste
      Spot retry loops
    Audience
      Claude Code users
      Codex CLI users

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

See how much your Claude Code or Codex CLI sessions are actually costing you.

USE CASE 2

Find sessions where the cache expired and got expensively re-written from scratch.

USE CASE 3

Spot oversized contexts and retry loops that are wasting tokens.

USE CASE 4

Get a recommendation on when to use a cheaper model instead of a premium one.

What is it built with?

Python

How does it compare?

d-date/retokadityasharmadotai-hash/docs-reader-rag-agentalekseiul/hermes-researcher-agent
Stars292929
LanguagePythonPythonPython
Setup difficultyeasyeasymoderate
Complexity1/52/52/5
Audiencedevelopervibe coderresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Zero dependencies, just Python 3.7+ and a clone or a single downloaded script.

MIT license: free to use, modify, and distribute for any purpose, including commercial use, as long as the copyright notice is kept.

In plain English

retok is a command line tool that reads the local log files created by AI coding agents, specifically Claude Code and OpenAI Codex CLI, and turns them into a report on how efficiently tokens are being spent. It scans the transcript files these agents already save on your machine, so it works entirely offline against data you already have rather than calling any external service. The report it prints covers estimated dollar cost, a breakdown between the two agents, the cache hit rate, cost per prompt, and the peak context size reached in a session. Beyond the raw numbers, it prints specific recommendations tied to patterns it detects, such as a large cache write happening right after a session sat idle past its cache expiry window, sessions that grew past 120,000 tokens without ever being cleared, heavy use of file reading tools on the main thread instead of delegating to subagents, the same command being retried five or more times, a high rate of interrupted prompts, and small one off questions being sent to expensive top tier models when a cheaper model would do. Cost estimates are built from a table of published per model pricing for both Claude and OpenAI Codex models, with separate multipliers for cached reads and for cache writes under the five minute and one hour cache windows. The tool notes that these numbers are estimates based on API list pricing, so if someone is on a flat rate subscription plan the numbers should be read as how much compute was used rather than money actually spent. retok runs on Python 3.7 or newer with no external dependencies, and it supports report output in several languages beyond English. It is aimed at developers who use Claude Code or Codex CLI regularly and want a clear, local view of where their token budget is going.

Copy-paste prompts

Prompt 1
Run retok on my Claude Code logs and summarize the top three ways I am wasting tokens.
Prompt 2
Explain what retok's cache TTL expiry recommendation means and how I should respond to it.
Prompt 3
Show me how to add a new language translation to retok.
Prompt 4
Walk me through installing retok and running it with a 7 day window filtered to one project.

Frequently asked questions

What is retok?

A local command line report card for your Claude Code and Codex CLI usage, showing token cost and where you are wasting tokens.

What language is retok written in?

Mainly Python. The stack also includes Python.

What license does retok use?

MIT license: free to use, modify, and distribute for any purpose, including commercial use, as long as the copyright notice is kept.

How hard is retok to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is retok for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.