Skip to content

feat(import): import Claude Code and Codex sessions (M3 + M4) - #1134

Open
elio-neto wants to merge 1 commit into
mainfrom
feat/import-external-sessions
Open

elio-neto wants to merge 1 commit into
mainfrom
feat/import-external-sessions

Conversation

@elio-neto

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

M3 adds packages/teamcode/src/import: a scanner for ~/.claude/projects and ~/.codex/sessions, parsers for Claude Code JSONL and Codex rollouts, a pure normalizer to Session.Info + MessageV2 with deterministic ids, and an idempotent incremental storage writer through the existing drizzle tables.
M4 adds teamcode import --from claude-code|codex, an origin column (claude / codex / teamcode) in the TUI session list and in teamcode session list, and the external_session tool for reading imported sessions from an active session.
Origin is derived from the version column (claude-code@<v>, codex@<v>), so there is no schema change or migration.
Spike/design notes are in docs/rewrite/spec-m3-m4-import-spike.md.

How did you verify your code works?

bun run typecheck clean. bun test test/import: 35 pass (JSONL fixtures included). Full bun test of packages/teamcode: 2740 tests, 3 environment-dependent failures that also fail on the base commit (two rely on chmod 0o444 denying writes, which root ignores; one timing-sensitive compaction test passes alone).

Screenshots / recordings

CLI/TUI text-only change, no screenshot.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

https://claude.ai/code/session_014qrCGqHYZnWc7uAVroctQF

M3 — scanner and converters (packages/teamcode/src/import/):
- scanner: discovers ~/.claude/projects/<slug>/<sessionId>.jsonl (plus the
  sessions/ and subagents/ layouts) and ~/.codex/sessions/**/rollout-*.jsonl
- parser/claude-code: typed view of the Claude Code JSONL (one line per
  content block, tool results as user lines, telemetry lines skipped)
- parser/codex: typed view of Codex rollouts (enveloped and legacy layouts)
- normalizer: pure mapping to Session.Info + MessageV2.WithParts; assistant
  blocks grouped by message.id, tool_result folded into ToolPart state,
  synthetic step-start/step-finish carrying usage, deterministic ids in the
  id.ts layout so re-import is a set difference on id
- storage: idempotent, incremental upsert through the existing drizzle
  tables; refreshes only the newest existing message (late tool results);
  creates a project row when the transcript cwd matches no worktree
- origin: claude / codex / teamcode derived from the version column
  (claude-code@<v>, codex@<v>); no schema change

M4 — TS surface:
- `teamcode import --from claude-code|codex [--session <prefix>] [--dry-run] [--json]`
  on the existing import command; `import <file>` behaviour unchanged
- origin column in the TUI session dialog and in `teamcode session list`
- `external_session` tool: list sessions by origin/search and read a
  transcript (prompts, text, reasoning, tool calls) from an active session

Tests: test/import/* with JSONL fixtures (sanitized Claude Code sample,
subagent transcript, invented Codex rollout) covering parser, normalizer,
ids, scanner, storage idempotency/incremental re-import, orchestrator and
the tool. Spike document in docs/rewrite/spec-m3-m4-import-spike.md.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014qrCGqHYZnWc7uAVroctQF
@elio-neto
elio-neto requested a review from ElioNeto as a code owner September 22, 2026 17:02
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
D Security Rating on New Code (required ≥ A)
D Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

This branch has not been deployed

No deployments
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.

2 participants