This repository provides a local Codex token calculator that allows you to perform an exact Codex token check even when you are signed in with a ChatGPT login instead of using OpenAI API keys. If you need a Codex CLI token calculator to figure out exactly how many tokens your projects are consuming locally, this tool reads your session logs and does the math for you.
If you use Codex through a ChatGPT login usage check flows are usually hidden because you don't have the standard API usage dashboard that comes with direct API billing. This repo fills that gap by acting as a read-only Codex token calculator. It parses the local session logs that Codex stores on disk and turns them into:
- An overall token total (Codex token check)
- A top-level per-project breakdown
- An exact per-directory breakdown
- A CSV export you can sort, filter, and graph later
Note: The script is entirely read-only. It calculates your Codex CLI usage locally and does not call the OpenAI API.
codex_usage_report.py walks through ~/.codex/sessions, reads each .jsonl session log, and:
- Finds the working directory for the session from
session_metaorturn_context - Finds the last non-null
token_count.total_token_usagesnapshot - Attributes that session to your chosen base directory
- Aggregates totals for:
- Everything under the base directory
- The first path segment under the base directory
- The exact relative directory
- Writes all of it to
codex_usage_report.csv
Older sessions are still counted in the summary if they are missing fields, but they are reported as missing attribution instead of being guessed.
Clone or copy this repo somewhere convenient, then run the script against the directory tree you care about.
python3 codex_usage_report.py /path/to/workspaceIf you are already inside the directory you want to summarize:
python3 /path/to/codex-usage-chatgpt-login/codex_usage_report.py .Command:
python3 codex_usage_report.py /path/to/workspace --limit 5Example terminal summary:
Base directory: /path/to/workspace
Sessions root: /home/you/.codex/sessions
Summary
session files seen: 312
sessions in base: 284
sessions attributed: 271
missing usage: 13
missing cwd: 7
outside base: 21
These numbers are illustrative. Your real output will vary as your local session logs grow.
Example top-level table:
| path | sessions | total_tokens | input_tokens | cached_input_tokens | output_tokens | reasoning_output_tokens |
|---|---|---|---|---|---|---|
| client-alpha | 48 | 418,592,114 | 410,215,223 | 356,482,710 | 8,376,891 | 4,201,450 |
| research-lab | 22 | 191,042,887 | 187,998,552 | 154,201,984 | 3,044,335 | 1,622,948 |
| web-redesign | 35 | 129,774,502 | 127,420,111 | 102,840,320 | 2,354,391 | 1,211,674 |
| automation | 17 | 74,203,918 | 72,916,009 | 60,114,432 | 1,287,909 | 592,477 |
| sandbox-demo | 9 | 33,921,405 | 33,110,447 | 29,804,544 | 810,958 | 407,103 |
Example exact-directory table:
| path | sessions | total_tokens |
|---|---|---|
| client-alpha/incident-review | 8 | 84,772,440 |
| research-lab/model-tuning | 5 | 63,194,002 |
| web-redesign/homepage-refresh | 7 | 41,559,881 |
| automation/reporting-pipeline | 4 | 29,830,144 |
| sandbox-demo/prototype-a | 3 | 18,112,503 |
Every run writes a CSV unless you pass --no-csv.
Default output file:
./codex_usage_report.csv
The CSV contains:
- one
overallrow with global totals and summary counters - one row per top-level directory
- one row per exact relative directory
Example CSV columns:
| section | path | sessions | total_tokens | input_tokens | cached_input_tokens | output_tokens | reasoning_output_tokens |
|---|---|---|---|---|---|---|---|
| overall | . | 271 | 847,534,901 | 831,660,342 | 703,144,960 | 15,874,559 | 8,036,877 |
| top_level | client-alpha | 48 | 418,592,114 | 410,215,223 | 356,482,710 | 8,376,891 | 4,201,450 |
| exact | client-alpha/incident-review | 8 | 84,772,440 | 82,914,106 | 70,118,912 | 1,858,334 | 902,551 |
| Option | Purpose |
|---|---|
--limit 20 |
Show only the first 20 rows in each printed table |
--sort-by sessions |
Sort by session count instead of total tokens |
--csv-path report.csv |
Write the CSV somewhere else |
--no-csv |
Skip CSV export |
--json |
Print the full report as JSON |
--sessions-root /path/to/sessions |
Use a different Codex session directory |
- The report depends on what your local Codex client wrote to disk.
- Some older sessions may be missing
cwdor token snapshots. - Cached input tokens are reported separately because Codex logs them separately.
- This is a local estimate from session logs, not a billing statement from OpenAI.
- The generated CSV is intentionally gitignored because it can contain private folder names from your machine.