Skip to content

feat: display token usage and duration after job execution#35

Open
mtibbits wants to merge 1 commit into
JCSnap:mainfrom
mtibbits:feat/session-stats
Open

feat: display token usage and duration after job execution#35
mtibbits wants to merge 1 commit into
JCSnap:mainfrom
mtibbits:feat/session-stats

Conversation

@mtibbits

@mtibbits mtibbits commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Problem

When running claude-queue start with a batch of jobs, there's no visibility
into how many tokens each job consumed or how long it took. This makes it hard
to identify which jobs are burning through the token budget, estimate costs,
or diagnose unexpectedly slow executions.

Solution

After each job execution, print duration and token usage to the console.
Token counts are extracted from Claude Code's existing JSONL conversation logs
(~/.claude/projects/), so this requires no changes to the subprocess
invocation — claude_interface.py is untouched.

Console output

✓ Prompt abc12345 completed successfully
    Duration: 2m 34s | Input: 23,349,905 tokens | Output: 51,568 tokens

Execution log (persisted in .md file)

[2026-03-15 10:30:00] Token usage: 402 input + 19,093,602 cache-write + 4,255,901 cache-read = 23,349,905 total input, 51,568 output (297 API turns)

Stats are best-effort — if the JSONL can't be found (e.g., older CLI version,
killed process), only duration is shown. Extraction failures never break the
execution-result pipeline.

Test plan

  • 27 new tests in tests/test_session_stats.py
  • All 573 existing tests pass unchanged (0 modifications to test_claude_interface.py)
  • Verified against real JSONL files from single-turn and multi-turn sessions

🤖 Generated with Claude Code

@mtibbits mtibbits force-pushed the feat/session-stats branch from 1217a67 to a4e5417 Compare March 16, 2026 02:21
After each job completes during `claude-queue start`, print duration and
token usage (input + output) extracted from Claude Code's JSONL conversation
logs. Detailed cache breakdowns are persisted in the prompt's execution log.

Uses the existing JSONL files under ~/.claude/projects/ rather than switching
to --output-format json, preserving text-mode stdout, Fix 2 rate-limit
detection, and all existing tests unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Matthew Tibbits <mtibbits@users.noreply.github.com>
@mtibbits mtibbits force-pushed the feat/session-stats branch from a4e5417 to 69cb187 Compare March 16, 2026 02:26
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