Local AI usage observability CLI for Codex sessions.
Project description
codex-stats
codex-stats is a local analytics CLI for Codex usage.
It reads your local Codex state from ~/.codex and surfaces:
- session summaries
- rolling usage totals across today, week, month, or the last
Ndays - model and project breakdowns
- project-specific drilldowns
- recent session history
- estimated token-based cost
- anomaly-aware usage insights and recommendations
- export and import for cross-device snapshots
- merged export snapshots for multi-device rollups
- OTLP metrics export for Grafana and OpenTelemetry collectors
- shareable weekly and monthly reports
Install
pipx install codex-stats
Or with pip:
python3 -m pip install codex-stats
Command Reference
codex-statsShow the default usage summary for today.codex-stats todayShow today's usage summary explicitly.codex-stats weekShow usage totals for the last 7 days.codex-stats monthShow usage totals for the last 30 days.codex-stats --days 14Show a rolling summary for the lastNdays.codex-stats sessionShow the most recent session in detail.codex-stats session --id <session_id>Show one specific session by ID.codex-stats modelsBreak usage down by model.codex-stats projectBreak usage down by project.codex-stats project backend-apiShow a single project's summary across all available local data.codex-stats project backend-api --days 30Show a single project's summary for a rolling time window.codex-stats dailyShow per-day usage with an ASCII trend graph.codex-stats compareCompare the last 7 days against the previous 7 days.codex-stats compare today yesterdayCompare named time windows directly.codex-stats historyShow recent session history.codex-stats topShow the largest sessions by token usage.codex-stats top --project backend-apiShow the largest sessions for one project.codex-stats costsShow estimated cost totals and monthly projection.codex-stats insightsShow anomaly-aware insights and recommended next steps.codex-stats doctorValidate local Codex data sources and config.codex-stats doctor --strictReturn a non-zero exit code if any doctor check fails.codex-stats initCreate a default config file under~/.config/codex-stats/.codex-stats config showShow the effective config, including pricing and display defaults.codex-stats report weeklyGenerate a weekly shareable report.codex-stats report weekly --format markdownGenerate a weekly report in Markdown.codex-stats report weekly --format htmlGenerate a standalone HTML report for sharing, including inline charts.codex-stats report weekly --format svgGenerate a poster-style SVG asset for sharing in docs, social posts, or release notes. By default it writescodex-stats-weekly.svgin the current working directory.codex-stats report weekly --project backend-apiGenerate a weekly report for one project.codex-stats report weekly --format markdown --output weekly-report.mdWrite a formatted report to a file.codex-stats report weekly --format html --output weekly-report.htmlWrite a polished standalone HTML report to a file.codex-stats report weekly --format svg --output weekly-report.svgWrite a standalone SVG share card to a file.codex-stats report weekly --format html --renderGenerate an HTML report, write it to a temp file, and open it in the default browser.codex-stats report weekly --format svg --renderGenerate an SVG report, write it to a temp file, and open it in the default browser.codex-stats export codex-stats-export.jsonExport normalized local stats to JSON.codex-stats export codex-stats-export.json --since 30dExport only a rolling window of recent sessions.codex-stats import laptop.json desktop.jsonRead one or more exported snapshots and summarize them.codex-stats merge merged.json laptop.json desktop.jsonMerge multiple exported snapshots into one deduplicated file.codex-stats merge merged.json laptop.json desktop.json --jsonMerge snapshots and return a machine-readable merge summary.codex-stats otel --output otlp-metrics.jsonWrite OTLP JSON metrics derived from local Codex session data.codex-stats otel --endpoint http://localhost:4318/v1/metricsPush OTLP JSON metrics directly to an OTLP/HTTP collector endpoint.codex-stats otel --since 30d --daily-days 14 --resource-attr deployment.environment=devExport a rolling window plus daily history with additional resource metadata.codex-stats watchRun a live terminal dashboard that refreshes usage summaries continuously.codex-stats watch --project backend-api --days 14 --interval 2Watch one project with a shorter refresh interval and a custom rolling window.codex-stats watch --alert-cost-usd 20 --alert-tokens 500000 --alert-delta-pct 50Raise live alerts when the rolling window crosses your chosen thresholds.codex-stats watch --reset-stateIgnore the saved watch baseline for this scope and rebuild it from the current snapshot.codex-stats completions zshPrint shell completion setup for your shell.codex-stats --color alwaysForce ANSI color output.codex-stats --jsonReturn machine-readable JSON output for supported commands.
How It Works
codex-stats does not proxy or intercept Codex API traffic.
It reads local Codex artifacts, including:
state_5.sqlitefor session metadata- rollout JSONL files for request and token snapshots
Notes
- Costs are estimates, not billing values.
- Output depends on local Codex file formats remaining compatible.
exportandimportlet you move normalized snapshots between machines.mergelets you deduplicate and combine exported snapshots into one file.export --since Ndlimits snapshots to a rolling window before sharing.otelemits OTLP/HTTP JSON metrics, including aggregate token counters and daily historical gauges.watchis intended for interactive terminals and exits cleanly onCtrl-C.watchpersists alert/session baseline state under the config directory soNEWmarkers survive restarts unless you pass--reset-state.doctor --strictis useful in scripts and CI because it returns a non-zero exit code on failed checks.--color auto|always|nevercontrols ANSI styling.
OpenTelemetry Export
The otel command converts local Codex session data into OTLP JSON metrics so you can feed them into Grafana, Grafana Alloy, or any OTLP/HTTP collector.
Write the payload to disk:
codex-stats otel --output otlp-metrics.json
Push directly to an OTLP/HTTP endpoint:
codex-stats otel --endpoint http://localhost:4318/v1/metrics
Add resource metadata or restrict the export window:
codex-stats otel \
--since 30d \
--daily-days 14 \
--resource-attr deployment.environment=dev \
--resource-attr service.namespace=developer-tools
Exported metrics include aggregate sums such as codex_stats_tokens, codex_stats_requests, and codex_stats_estimated_cost_usd, plus daily gauges such as codex_stats_daily_tokens.
Grafana Starter Kit
This repo now includes starter assets under examples/grafana/codex-stats-dashboard.json and examples/grafana/grafana-alloy.alloy.
Quick local loop:
alloy run examples/grafana/grafana-alloy.alloy
codex-stats otel --endpoint http://localhost:4318/v1/metrics --since 30d
Then import the dashboard JSON into Grafana and point it at your Prometheus-compatible datasource. The dashboard includes:
- topline stats for tokens, requests, sessions, and estimated cost
- daily token, request, and cost charts
- table views for token usage by project and estimated cost by model
Roadmap
The current priority list lives in docs/roadmap.md.
Shareable Assets
Share-ready assets now live under docs/assets/codex-stats-share-card.svg, and report --format svg can generate poster-style report visuals directly from local usage data.
Watch Alerts
watch can surface live warnings and critical alerts directly in the terminal dashboard.
Example:
codex-stats watch \
--days 7 \
--alert-cost-usd 20 \
--alert-tokens 500000 \
--alert-requests 20 \
--alert-delta-pct 50
Alerts currently cover:
- explicit cost, token, request, and delta thresholds
- large usage spikes versus the previous window
- anomaly conditions already detected by the insights engine
- stateful marking of newly triggered conditions and newly observed sessions across watch restarts for the same scope
Pricing Config
Optional pricing config lives at ~/.config/codex-stats/config.toml.
[pricing]
default_usd_per_1k_tokens = 0.01
[pricing.model_usd_per_1k_tokens]
gpt-5.4 = 0.02
gpt-5-mini = 0.005
To create the config file automatically:
codex-stats init
To inspect the effective config:
codex-stats config show
codex-stats config show --json
JSON Schemas
Machine-readable output is intended to stay stable across patch releases.
summaryJSON: time-window totals such as sessions, requests, tokens, cost estimate, and top modelreportJSON: period, optional project scope, summary, comparison, projects, top sessions, costs, and insightsexportJSON:schema_version,exported_at, and normalizedsessionsdoctorJSON: a list of checks withname,ok,detail, andseverityconfigJSON: config path, whether the file exists, pricing defaults, overrides, and display defaultsimportandmergeJSON: import summary plus deduped session counts
Full field documentation lives in docs/json-schema.md.
Development
For local development from the repo:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -U pip setuptools
python -m pip install -e .
Run without installing:
PYTHONPATH=src python3 -m codex_stats
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codex_stats-1.4.1.tar.gz.
File metadata
- Download URL: codex_stats-1.4.1.tar.gz
- Upload date:
- Size: 45.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59a34a72a64eab4d7bb95ef3fd53212bc5d5b5e62a48a77324e3802aebd2caef
|
|
| MD5 |
dc78ef42aec914bfde6174ad83da0603
|
|
| BLAKE2b-256 |
ab813fdb903db99618017819d03a0d4d33ed97dfe0e0e2934a1884edfe5f610a
|
Provenance
The following attestation bundles were made for codex_stats-1.4.1.tar.gz:
Publisher:
publish.yml on vivek378521/codex-stats
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_stats-1.4.1.tar.gz -
Subject digest:
59a34a72a64eab4d7bb95ef3fd53212bc5d5b5e62a48a77324e3802aebd2caef - Sigstore transparency entry: 1239224195
- Sigstore integration time:
-
Permalink:
vivek378521/codex-stats@db2fb420d0d94ce4dcf059a2e3d44dece8d7bd4e -
Branch / Tag:
refs/tags/v1.4.1 - Owner: https://github.com/vivek378521
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@db2fb420d0d94ce4dcf059a2e3d44dece8d7bd4e -
Trigger Event:
release
-
Statement type:
File details
Details for the file codex_stats-1.4.1-py3-none-any.whl.
File metadata
- Download URL: codex_stats-1.4.1-py3-none-any.whl
- Upload date:
- Size: 39.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f3c80f1cc0b47f119c9414b989403ad80f77c1645a34350bf6e865fc5a6f8fe
|
|
| MD5 |
f3f5092a500e6c89e4bfee948e2148a2
|
|
| BLAKE2b-256 |
ce8c52f7278c48204df5073bf585f9697abdc535cfe14b9a521a4c0759237e13
|
Provenance
The following attestation bundles were made for codex_stats-1.4.1-py3-none-any.whl:
Publisher:
publish.yml on vivek378521/codex-stats
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_stats-1.4.1-py3-none-any.whl -
Subject digest:
0f3c80f1cc0b47f119c9414b989403ad80f77c1645a34350bf6e865fc5a6f8fe - Sigstore transparency entry: 1239224199
- Sigstore integration time:
-
Permalink:
vivek378521/codex-stats@db2fb420d0d94ce4dcf059a2e3d44dece8d7bd4e -
Branch / Tag:
refs/tags/v1.4.1 - Owner: https://github.com/vivek378521
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@db2fb420d0d94ce4dcf059a2e3d44dece8d7bd4e -
Trigger Event:
release
-
Statement type: