Skip to content

Generalize token tracking to Claude Code, Codex, and pi - #1

Open
nredd wants to merge 2 commits into
mainfrom
agent-token-tracking
Open

nredd wants to merge 2 commits into
mainfrom
agent-token-tracking

Conversation

@nredd

@nredd nredd commented Sep 17, 2026

Copy link
Copy Markdown
Owner

No description provided.

nredd and others added 2 commits September 17, 2026 11:27
`claude-metrics` only ever read one harness off one hardcoded schema, and the
live sessions table depended on Claude Code's own PID registry -- a mechanism
Codex and pi don't have. Rather than bolt Codex/pi tracking on as a second
special case, drop the Claude-only live path entirely and read every harness,
Claude included, the same lagging, tailed-transcript way.

Changes:
- Rename `crates/claude-metrics` to `crates/harness-metrics`. Add a `Harness`
  enum (Claude/Codex/Pi) and a generic `Ledger<Record>` engine (mtime-gated
  discovery, byte-offset tailing, windowed history, unbounded running
  cumulative totals) shared by all three backends via a small `HarnessRecord`
  trait
- Add the Codex backend: parses `~/.codex/sessions/**/rollout-*.jsonl` (+
  `archived_sessions`), prefers `token_count`'s cumulative `total_token_usage`
  and diffs it against the previous snapshot per file, folds reasoning tokens
  into output, and has no cache-write bucket since Codex doesn't expose one
- Add the pi backend: parses `~/.pi/agent/sessions/**/*.jsonl`, sums each
  assistant message's own `usage` object directly (no running-total trick
  needed, unlike Claude), and folds series by *provider* rather than model --
  pi is multi-provider by design, so a per-model series would balloon
- Delete the Claude live-session/PID-registry/statusline machinery outright:
  `session.rs`'s registry reader, `statusline.rs`, and the `claude` sessions
  table widget. No cost/context/rate-limit columns survive -- that data only
  ever came from the statusline tee this removes
- Replace the `claude`/`claude_graph`/`claude_stats` widgets with two
  harness-agnostic ones, `agent_graph`/`agent_stats`, each taking a per-instance
  `source = "claude" | "codex" | "pi" | "all"` on its layout entry.
  `source = "all"` merges every harness into one series per harness instead of
  one per model family. A layout can mix instances with different `source`s;
  time-series keys are namespaced `"{source}::{label}"` so two backends'
  `Other` buckets can't collide
- Rename `[claude]`/`[styles.claude]` config to `[agent]`/`[styles.agent]`
- Add `sample_configs/{codex,pi,all_harnesses}_config.toml` alongside a
  regenerated `claude_config.toml`, each drawing a stats graph and a rate graph
  and nothing else
- Add a `cargo run` Quickstart section to `README.md` covering every fork
  feature, with `all_harnesses_config.toml` as the flagship "track everything"
  example. Replace `docs/content/{usage/widgets,configuration/config-file}/
  claude.md` with `agent.md`, documenting all three harnesses' counting rules
- Regenerate `schema/nightly/bottom.json`

This is a breaking rename with no back-compat alias for the old widget names --
low risk given this fork's small, known user base.

Verified: `./scripts/smoke`'s four checks (`cargo fmt --all -- --check`,
`cargo clippy --workspace --all-targets --all-features -- -D warnings`,
`cargo test --workspace --all-features` [`nextest` unavailable in this
environment, `cargo test` covers the same 407 tests], `cargo doc --no-deps
--all-features --workspace`) are all clean, plus `harness-metrics`'s own
pedantic clippy pass. Ran all four sample configs through a real pty and
confirmed each renders without error.

Co-Authored-By: pi <noreply@pi.dev>
Changes:
- Pull the single `--pixel_graphs kitty` line out of the power-widget/marker bullets and
  give it its own Quickstart subsection with real commands: default layout, `demo_config.toml`
  (the one with the most graphs on screen, where the resolution jump reads the most obviously),
  an agent config, and the `auto` fallback
- State the terminal requirement (Kitty graphics protocol -- Ghostty/Kitty/WezTerm) and the
  tmux caveat inline, so a reader doesn't have to find the detailed writeup further down to
  know why `auto` won't cut it there
- Verified each new command in a real pty: default layout, `demo_config.toml`, and
  `all_harnesses_config.toml`, all with `--pixel_graphs kitty`, plus `--pixel_graphs auto`
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant