The Capacity Dock design doc gains the band, the switch and the two new code boundaries; the Claude provider doc explains what the detection reads, how the local history is derived from stored reset times, and why it stays quiet, so the next person changing the snapshot store knows what depends on it. Refs #725, rather than Closes: that issue is a five-part epic and this is one slice of its surfaces, so it should not close on this PR. No issue tracks early-reset detection on its own.
5 KiB
Claude
Anthropic Claude Code CLI and Claude Desktop's local agent mode.
- Source:
src/providers/claude.ts - Loading: eager (
src/providers/index.ts:1) - Test: none directly. Coverage comes from
tests/parser-claude-cwd.test.ts,tests/parser-filter.test.ts, andtests/parser-mcp-inventory.test.ts, which exercisesrc/parser.tsend-to-end against fixture session files.
Where it reads from
| Source | Path |
|---|---|
| Claude Code CLI | $CLAUDE_CONFIG_DIR if set, otherwise ~/.claude/projects/ |
| Claude Desktop (macOS) | ~/Library/Application Support/Claude/local-agent-mode-sessions/ |
| Claude Desktop (Windows, classic) | %APPDATA%/Claude/local-agent-mode-sessions/ |
| Claude Desktop (Windows, MSIX) | %LOCALAPPDATA%/Packages/<Claude package>/LocalCache/Roaming/Claude/local-agent-mode-sessions/ |
| Claude Desktop (Linux) | ~/.config/Claude/local-agent-mode-sessions/ |
For Desktop, findDesktopProjectDirs walks up to 8 levels deep looking for projects/ subdirectories, skipping node_modules and .git.
Desktop session roots are resolved in this order:
- A non-empty
CODEBURN_DESKTOP_SESSIONS_DIRoverrides discovery and is the only returned root. - macOS uses the single path shown above.
- Windows always includes the classic path first. It then scans
%LOCALAPPDATA%/Packagesfor package directories whose names start withClaude_or contain.Claude_, sorted by package name, and includes only packages whose full MSIX sessions path exists as a directory. - Other platforms use the single Linux path shown above.
All returned roots are absolute, resolved, and deduplicated. Missing or unreadable Windows package directories are ignored.
Storage format
JSONL, one event per line, per session file. Sessions live under <project>/<sessionId>.jsonl.
Parser
createSessionParser returns an empty async generator (claude.ts:101-105). Claude is a special case: src/parser.ts reads Claude JSONL files directly with full turn grouping, dedup of streaming message IDs, and MCP tool inventory extraction. The provider object exists only so discoverSessions can return Claude session sources alongside the others.
Pricing
Claude Code reports total cache-write tokens in usage.cache_creation_input_tokens.
When available, it also splits those writes by duration in
usage.cache_creation.ephemeral_5m_input_tokens and
usage.cache_creation.ephemeral_1h_input_tokens. CodeBurn keeps the existing
aggregate cache-write token total for reports, but prices the 1-hour portion at
2x base input cost (1.6x the 5-minute cache-write rate exposed by LiteLLM).
If the split fields are missing, the parser falls back to the legacy behavior
and prices every cache write at the 5-minute rate.
Caching
None at the provider level. The daily aggregation cache (src/daily-cache.ts) reuses prior computed days.
Quirks
- The parser is in
src/parser.ts, not insrc/providers/claude.ts. Anything that changes Claude parsing belongs inparser.ts. - Streaming responses produce duplicate message IDs across resumed sessions;
parser.tsstrips them via the globalseenMsgIdsSet. - Model display names are mapped in
claude.ts:7-20; add new versions there when Anthropic releases them.
Early quota resets
Anthropic sometimes resets a usage window before its scheduled time. The menubar
notices on the existing refresh lifecycle — no extra request — by comparing each
fetch's windows against the previous fetch's readings, which are kept per window
in UserDefaults alongside the record of what has already been announced.
SubscriptionSnapshotStore's 30 days of snapshots then give the local history
caption ("Last 3 weekly resets came ~18h early"), derived from the stored reset
times alone: a fixed window that starts at t ends at t + length, so a cycle
that ends sooner than a full window after the previous cycle's scheduled end
began early by the difference. Everything is local; nothing is fetched to
produce it.
The detection is deliberately quiet. It needs a validated window length (the
fixed 5-hour and 7-day limits), a stored reset that has not yet passed, and
either a reset time anchored to a genuinely new cycle or a fall of at least 40
points that lands at or under 10%. A scheduled reset, a plan change, clock or
timestamp skew, a window appearing or disappearing, a first observation and a
reconnect after a terminal failure all produce nothing. Short windows get no
history summary, the same discipline QuotaPace applies to its ETA.
When fixing a bug here
- Confirm whether the bug is in discovery (sessions not picked up) or parsing (sessions found but data wrong).
- Discovery bugs live in
claude.ts:78-99. Verify the directory layout you expect actually matches what Claude writes today. - Parsing bugs live in
src/parser.ts. Look forparseSessionFile,groupIntoTurns, anddedupeStreamingMessageIds. - Add a fixture under
tests/fixtures/and a test undertests/parser-claude-cwd.test.ts(or a new file). Do not mock the filesystem.