Skip to content

feat(usage): Show live orchestrator tokens on the statusline - #113

Merged
4ndreello merged 14 commits into
mainfrom
feat/orchestrator-live-tokens
Sep 23, 2026
Merged

4ndreello merged 14 commits into
mainfrom
feat/orchestrator-live-tokens

Conversation

@4ndreello

Copy link
Copy Markdown
Owner

Summary

In codedeck open, the statusline tok field counted worker tokens only, so a run with no workers showed 0 tok while run $ already included the orchestrator. The statusline payload's context_window tokens describe the current window, not the session, so they cannot be summed. This PR reads the orchestrator transcript incrementally and records its cumulative tokens through the same high-water ledger as cost.

  • statusline: passes transcript_path as --transcript <session_id>=<path>; tok = worker totalTokens + orchestrator.totalTokens; with an active run and no valid summary, tok is omitted instead of showing the smaller context-window snapshot
  • CLI/protocol: --transcript flag and optional transcript param on usage.get
  • transcript reader: consumeTranscriptChunk, 1 MiB chunk cap, 4 MiB pending-line cap, dedupe by message.id + requestId across chunks
  • daemon: in-memory cursor per native id with a per-id lock; the path must resolve under ~/.claude/projects, be named <id>.jsonl and be a regular file; reset on inode change or shrink; ledger commit before the cursor moves; earlier-id reconciliation runs after the response and is not duplicated while in flight
  • after a daemon restart the reader starts at byte 0; the ledger high-water marks keep the displayed total from dropping while it catches up

Spec, design, tasks and the run report are in .specs/features/orchestrator-live-tokens/.

Known risk (spec open question): an assistant line without message.id or requestId is counted again if the transcript is replaced or shrinks.

Test plan

  • npx vitest run tests/statusline.test.ts tests/usage-statusline-contract.test.ts tests/usage-cli.test.ts: 3 files, 53 tests passed
  • npx vitest run tests/orchestrator-usage-daemon.test.ts tests/usage-daemon.test.ts tests/claude-transcript.test.ts tests/pricing.test.ts tests/usage.test.ts tests/usage-query.test.ts tests/usage-ledger.test.ts: 7 files, 103 tests passed
  • npx tsc --noEmit -p .: clean
  • one mutation probe per task, all killed (dedupe key, flag split, orchestrator term, path containment, in-flight filter)
  • not run: a real codedeck open session against a real transcript

4ndreello and others added 14 commits September 22, 2026 23:31
Use harness-aware totals in run usage and query buckets.
Expose worker and orchestrator totals while keeping the statusline fallback for older daemons.

Co-Authored-By: Codex <noreply@anthropic.com>
Define bounded transcript ingestion, path validation, and token-ledger reconciliation for live orchestrator usage.

Co-Authored-By: Codex <noreply@anthropic.com>
Align the live-token spec and design with the approved simplifications. Add task ownership, dependencies, interfaces, and scoped verification gates.

Co-Authored-By: Codex <noreply@anthropic.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@anthropic.com>
…-cli-b09d' into ra/orchestrator-live-tokens-spec-e174
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Track queued reconciliations by session and native id so repeated statusline requests do not reread earlier transcripts.

Co-Authored-By: Codex <noreply@openai.com>
…e-tokens

# Conflicts:
#	plugin/statusline.sh
#	tests/statusline.test.ts
@sonarqubecloud

Copy link
Copy Markdown

@4ndreello
4ndreello merged commit 4e36e9e into main Sep 23, 2026
4 checks passed
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