Public: anyone can read this; the crew can change it.

Traces: every conversation and run kept as a trace, imported from outside agents, and explored in the forge #17943

opened this in answer to

Merged 22h 19m ago, live in production

This pull is one small slice of #17929, not the whole issue. It reads a Claude Code session file as a trace and exports it as OTLP, from the terminal only. The issue is too big for one run, and the earlier parked attempt was declined for exactly that.

Notes

opened this

This pull is one small slice of #17929, not the whole issue. It reads a Claude Code session file as a trace and exports it as OTLP, from the terminal only. The issue is too big for one run, and the earlier parked attempt was declined for exactly that.

What changed

  • forge trace <session.jsonl> prints the tree: each turn's prompt, then one line per step (model reply or tool call), e.g. Edit a.ts +3 −1, with time, tokens in, cached and out, and outcome. A running total comes last.
  • forge trace <session.jsonl> --otlp prints OTLP/JSON using the OpenTelemetry GenAI conventions (gen_ai.*). Ids are derived from the session, so exporting the same file twice gives the same document.
  • The command works on the file alone: no login, nothing is sent anywhere. A file over 256 MB is refused before it is read, and a file with no session records exits 1.
  • A reply that Claude Code writes as several lines is counted once. Lines that are not records are skipped and counted in the output.
  • New modules, each one concept:
    • src/trace/model.ts: the thread → turns → steps shape and the totals.
    • src/trace/claude_code.ts: the reader.
    • src/trace/otlp.ts: the export.
    • src/cli/commands/trace.ts: the command.
  • Docs are docs/features/traces.md and a forge trace section in docs/CLI.md. test/trace.test.ts covers parsing, totals, OTLP and the command.

Checks

  • bun x tsc --noEmit passes.
  • Passing: test/trace.test.ts, cli-docs, cli-commands, dead-code*, doorless, feature-doors, feature-orphans and mcp-size.
  • I did not run the whole suite; the forge runs it on push.
  • gate.ts is clean except one note, oneLine resembling clip in src/crew/triage.ts. I did not merge them: clip is private to triage, and mine also strips control characters from untrusted input.
  • The commit says No door: because this is terminal-only. The terminal side exists; the web, API and MCP sides are not built yet.

Not done (left for follow-ups)

  • Codex import.
  • POST import into the archive, with attribution and private by default.
  • Normalizing Talk conversations and run logs into traces.
  • The /traces list and trace pages, the time-scaled strip, diffs, compare, permalinks and share links.
  • MCP tools and the iOS reads.
  • Facets, saved searches and full-text search.
  • Cost: a Claude Code file records none, so the tree shows tokens only.

Try it: forge trace ~/.claude/projects/<app>/<session>.jsonl, add --otlp for the OTLP form.

🤖 Generated with Claude Code

Closes #17929

2 earlier comments
commented

This pull is one small slice of #17929, not the whole issue. It reads a Claude Code session file as a trace and exports it as OTLP, from the terminal only. The issue is too big for one run, and the earlier parked attempt was declined for exactly that.

What changed

  • forge trace <session.jsonl> prints the tree: each turn's prompt, then one line per step (model reply or tool call), e.g. Edit a.ts +3 −1, with time, tokens in, cached and out, and outcome. A running total comes last.
  • forge trace <session.jsonl> --otlp prints OTLP/JSON using the OpenTelemetry GenAI conventions (gen_ai.*). Ids are derived from the session, so exporting the same file twice gives the same document.
  • The command works on the file alone: no login, nothing is sent anywhere. A file over 256 MB is refused before it is read, and a file with no session records exits 1.
  • A reply that Claude Code writes as several lines is counted once. Lines that are not records are skipped and counted in the output.
  • New modules, each one concept:
    • src/trace/model.ts: the thread → turns → steps shape and the totals.
    • src/trace/claude_code.ts: the reader.
    • src/trace/otlp.ts: the export.
    • src/cli/commands/trace.ts: the command.
  • Docs are docs/features/traces.md and a forge trace section in docs/CLI.md. test/trace.test.ts covers parsing, totals, OTLP and the command.

Checks

  • bun x tsc --noEmit passes.
  • Passing: test/trace.test.ts, cli-docs, cli-commands, dead-code*, doorless, feature-doors, feature-orphans and mcp-size.
  • I did not run the whole suite; the forge runs it on push.
  • gate.ts is clean except one note, oneLine resembling clip in src/crew/triage.ts. I did not merge them: clip is private to triage, and mine also strips control characters from untrusted input.
  • The commit says No door: because this is terminal-only. The terminal side exists; the web, API and MCP sides are not built yet.

Not done (left for follow-ups)

  • Codex import.
  • POST import into the archive, with attribution and private by default.
  • Normalizing Talk conversations and run logs into traces.
  • The /traces list and trace pages, the time-scaled strip, diffs, compare, permalinks and share links.
  • MCP tools and the iOS reads.
  • Facets, saved searches and full-text search.
  • Cost: a Claude Code file records none, so the tree shows tokens only.

Try it: forge trace ~/.claude/projects/<app>/<session>.jsonl, add --otlp for the OTLP form.

🤖 Generated with Claude Code

commented

I fixed the long-session crash and documented the memory limit. Streaming the read is not done. tsc is clean and test/trace.test.ts passes (4 tests).

  • Crash fix: totalsOf in src/trace/model.ts and toOtlp in src/trace/otlp.ts no longer spread arrays into Math.min and Math.max. They now track the earliest start and latest end in one loop, per turn and across the trace. An empty trace still gives 0 for both.
  • Test: test/trace.test.ts builds a trace with 200,000 steps. It checks that totalsOf returns the right step count, start and end, and that toOtlp returns 200,002 spans (the root, one turn, and the steps).
  • Memory limit: docs/features/traces.md now says the file is read whole, so the 256 MB limit is memory-bound.
  • Not done: streaming the read. I left it for a later slice because you marked it non-blocking.
  • Both doors: the commit carries a No door: line, since it only fixes a reader and export that already have their terminal side and how-to.
  • Gate: the commit names #17929, and scripts/gate.ts --fix ran with nothing to rewrap. The gate's only output was an advisory that oneLine in src/trace/claude_code.ts resembles clip in src/crew/triage.ts, which I did not change.
commented

Left #17929 open: 8 unticked items remain (Every Talk conversation, every crew run's log and every review is a trace, kept forever. The raw bytes are the record, and a normalized view is rebuilt from them: thread → turns → steps (model call, tool call, subagent), each with times, model, account, tokens in, cached and out, cost, and outcome.; Import: POST a session file from an outside agent (Claude Code's session JSONL first, then Codex), so the owner's own sessions from his Mac and phone join the same archive, attributed and private by default.; One list of every trace, with facets: repository, app, file touched, tool, model or account, outcome, cost, date, person or agent. Saved searches. Full-text over titles and summaries, and over archived turns when asked.; …).

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs