Understand exactly how your Codex sessions consume tokens.
βΉοΈ Codex is an OpenAI product. This project is an independent local analyzer for Codex session logs.
This tool scans your local Codex logs and generates a clear, structured analysis of usage, costs, prompts, and agent behavior. It also supports localized console/report output with English as the default base language.
Analyzes .jsonl session logs from:
~/.codex/sessions~/.codex/archived_sessions
Then generates:
A complete breakdown of:
- π’ Total tokens (input, output, cached, reasoning)
- π Usage by project
- πΈ Most expensive sessions
- π€ Subagent usage & overhead
- π Subagents without parent in selected range
- βοΈ Input vs output ratios
- π§ Instruction-heavy sessions
- π Optimization insights
- π§Ύ Structured JSON output for automation
Creates a /prompts folder with:
- All user prompts
- Organized by project
- Sorted by time
- Python 3.10+
- No external dependencies
python analyze-codex-tokens.pyor on Windows:
py analyze-codex-tokens.pyDefault location:
./reports/<lang>-YYYY-MM-DD_HHMMSS/
Files generated:
token_report.mdtoken_report.json/prompts/*.md
You can run with direct CLI flags (recommended for CI/scripts):
python analyze-codex-tokens.py \
--since-days 7 \
--lang pt-br \
--output-dir ./reports \
--redact-prompts \
--jsonWindows PowerShell:
py analyze-codex-tokens.py --since-days 7 --lang pt-br --output-dir .\reports --redact-prompts --jsonAvailable flags:
--since-days N--since-date YYYY-MM-DD--codex-home PATH--output-dir PATH--lang en|pt-br|pt-pt|es--redact-prompts/--no-redact-prompts--json/--no-json
export SINCE_DAYS=7$env:SINCE_DAYS="7"export SINCE_DATE="2026-03-30"$env:SINCE_DATE="2026-03-30"export CODEX_HOME="/path/to/.codex"$env:CODEX_HOME="C:\path\to\.codex"export OUTPUT_DIR="/path/to/output"$env:OUTPUT_DIR="C:\path\to\output"If OUTPUT_DIR is not set and --output-dir is not provided, the script creates a language-prefixed timestamped folder under:
./reports/<lang>-<timestamp>/
export REDACT_PROMPTS=true$env:REDACT_PROMPTS="true"export WRITE_JSON=true$env:WRITE_JSON="true"export REPORT_LANG="pt-br"$env:REPORT_LANG="pt-br"Supported values:
en(default)pt-brpt-ptes
Examples:
Generate report in Brazilian Portuguese with automatic folder naming (PowerShell):
py analyze-codex-tokens.py --lang pt-brGenerate report in European Portuguese with automatic folder naming (Bash):
python analyze-codex-tokens.py --lang pt-ptUse environment variable in PowerShell, then run normally:
$env:REPORT_LANG="es"
py analyze-codex-tokens.pyUse environment variable in Windows CMD:
set REPORT_LANG=en
py analyze-codex-tokens.py--lang takes precedence over REPORT_LANG when both are set.
If you use --output-dir .\reports (or ./reports/<lang>), the tool also auto-creates <lang>-<timestamp> inside reports.
- π Recursive
.jsonldiscovery (works with VS Code extension) - π€ Subagent tracking and cost analysis
- π§± Markdown-safe report formatting (better organization/readability)
- π§Ύ JSON report export (
token_report.json) - π Optional prompt redaction mode
- π Deep token breakdown
- π Identify inefficiencies fast
- Requires local Codex logs
- Only sessions with
total_tokens > 0are included in the analysis - If no data appears, check your
.codexfolder - VS Code extension may store additional data in
.sqlite(not parsed yet)
Run unit tests:
python -m unittest discover -s tests -vPowerShell:
py -m unittest discover -s tests -v- Initial release.
- INformigados: https://github.com/informigados/
- Alex Brito: https://github.com/alexbritodev
This project is licensed under the MIT License - see the LICENSE file for details.