Skip to main content

Module claude_code

Module claude_code 

Source
Expand description

Claude Code adapter — the MVP’s fully implemented one.

Reads ~/.claude/projects/<url-encoded-cwd>/*.jsonl (READ-ONLY). Sub-agent transcripts live in <project>/<parent-session-uuid>/subagents/agent-<id>.jsonl and are attributed back to the parent via Session::parent_session.

Schema notes, VERIFIED against real local files (Claude Code v2.1.162, 2026-06-13):

  • A single API request is written as 2–10 assistant lines (one per content block) that all repeat message.usage and share one requestId. Observed real ratios: 83 lines -> 26 requests; 642 -> 262. Accounting MUST dedup (CLAUDE.md §8.1) — that happens in analysis::dedup, not here; the adapter preserves the raw lines as events.
  • message.usage keys: input_tokens, output_tokens, cache_creation_input_tokens, cache_read_input_tokens, plus a cache_creation: { ephemeral_5m_input_tokens, ephemeral_1h_input_tokens } breakdown (the TTLs are priced differently — see pricing).
  • API-error lines have model: "<synthetic>" / isApiErrorMessage: true with zeroed usage that never hit the API; their usage is dropped.
  • Sub-agent spawns are tool_use blocks named Task (legacy) or Agent (current), with input.description / input.subagent_type.
  • output_tokens ALREADY includes extended-thinking tokens (VERIFIED on real v2.1.178 data: thinking-only requests report output far larger than the visible text alone) — do NOT add an estimate on top, or known_total double-counts. Thinking blocks are frequently encrypted ("thinking": "" + signature; ~85% of thinking requests on the sampled machine), so the thinking SHARE of output is usually unmeasurable; that is surfaced honestly (encrypted-thinking count), never guessed.
  • Bookkeeping line types carrying no spend (VERIFIED on real files): summary, mode, permission-mode, last-prompt, file-history-snapshot, ai-title, custom-title, queue-operation, agent-name — ignored without counting as “skipped” so the skip stat means unexpected.
  • attachment lines (deferred-tool/skill listings, MCP instruction blocks, IDE/file context, reminders) carry no spend but ARE kept as EventKind::Attachment events — their category/size feed analysis::context (verified attachment.type ∈ {deferred_tools_delta, skill_listing, mcp_instructions_delta, task_reminder, file, …}).
  • TODO(verify): compaction markers (subtype: "compact_boundary" system lines, isCompactSummary user lines) were not present in sampled files; the mapping below is best-effort from documentation.

Structs§

ClaudeCode
Claude Code (~/.claude).