Skip to content

Store subagent transcripts as separate prompt records#562

Open
jwiegley wants to merge 5 commits intomainfrom
johnw/fix-371
Open

Store subagent transcripts as separate prompt records#562
jwiegley wants to merge 5 commits intomainfrom
johnw/fix-371

Conversation

@jwiegley
Copy link
Collaborator

@jwiegley jwiegley commented Feb 19, 2026

Summary

  • Parse Claude Code subagent transcripts from <session>/subagents/agent-<id>.jsonl into separate SubagentInfo structs instead of merging them into the parent transcript
  • Add parent_id field to PromptRecord and PromptDbRecord to link subagent prompt records back to their parent
  • Expand subagent metadata into separate prompt records at post-commit time and in virtual attributions, preserving thread hierarchy

Closes #371

Design

Subagent transcripts stored in Claude Code's subagents/ directory are now collected as SubagentInfo structs during JSONL parsing rather than being flattened into the parent transcript. These are propagated through the checkpoint pipeline via PromptUpdateResult::Updated and stored as JSON metadata (__subagents key) on the parent checkpoint.

At post-commit time (and in virtual attributions), the subagent metadata is expanded into separate PromptDbRecord entries, each with a unique hash ID and a parent_id linking back to the parent prompt. This preserves the natural thread structure of agentic coding sessions.

DB schema migrated from version 3 to 4 to add the parent_id TEXT column to the prompts table.

Test plan

  • cargo clippy — no warnings
  • cargo test --test claude_code — all 24 tests pass
  • cargo test --test agent_presets_comprehensive — all 58 tests pass
  • New test: test_parse_claude_code_jsonl_with_subagents verifies subagents are returned separately
  • Updated test: test_parse_claude_code_jsonl_without_subagents_dir verifies empty vec for no subagents
  • New test fixtures: claude-code-with-subagents.jsonl and subagents/agent-test-sub-1.jsonl

🤖 Generated with Claude Code

@git-ai-cloud-dev
Copy link

git-ai-cloud-dev bot commented Feb 19, 2026

Stats powered by Git AI

🧠 you    ███░░░░░░░░░░░░░░░░░  15%
🤖 ai     ░░░█████████████████  85%
More stats
  • 0.0 lines generated for every 1 accepted
  • 1 minute waiting for AI
  • Top model: claude::claude-opus-4-6 (282 accepted lines, 5 generated lines)

AI code tracked with git-ai

@git-ai-cloud
Copy link

git-ai-cloud bot commented Feb 19, 2026

Stats powered by Git AI

🧠 you    ███░░░░░░░░░░░░░░░░░  15%
🤖 ai     ░░░█████████████████  85%
More stats
  • 0.0 lines generated for every 1 accepted
  • 0 seconds waiting for AI
  • Top model: claude::claude-opus-4-6 (282 accepted lines, 0 generated lines)

AI code tracked with git-ai

@jwiegley jwiegley marked this pull request as ready for review February 19, 2026 03:27
devin-ai-integration[bot]

This comment was marked as resolved.

Base automatically changed from johnw/fix-370 to main February 19, 2026 04:14
@svarlamov
Copy link
Member

svarlamov commented Feb 19, 2026

Append subagent messages to the main transcript in sorted filename order for deterministic results

I'm not a huge fan of this Claude... May have mentioned it elsewhere, but can we add them as normal prompts into the authorship log but just include a parentId that will point to the parent prompt?

devin-ai-integration[bot]

This comment was marked as resolved.

@jwiegley jwiegley changed the title Include subagent transcripts in Claude Code JSONL parsing Store subagent transcripts as separate prompt records Feb 19, 2026
@jwiegley jwiegley requested a review from svarlamov February 20, 2026 03:04
jwiegley and others added 5 commits February 19, 2026 23:13
Claude Code stores subagent (Task tool) transcripts in separate JSONL
files at <session-uuid>/subagents/agent-<id>.jsonl, but the transcript
parser only read the main session file. This meant all subagent
conversation content was silently dropped from git-ai authorship records.

Extract the JSONL line parsing into a reusable parse_claude_jsonl_content
helper, then after parsing the main transcript, discover and parse any
subagent JSONL files from the sibling subagents directory. Subagent
messages are appended to the main transcript in sorted filename order
for deterministic results.

Fixes #371

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds an optional parent_id field to both PromptRecord (git notes) and
PromptDbRecord (SQLite). This links subagent prompt records back to
their parent prompt, enabling hierarchical transcript storage.

Includes DB migration 3→4 (ALTER TABLE prompts ADD COLUMN parent_id)
and updates all construction sites with parent_id: None.

Refs: #371

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of merging Claude Code subagent messages into the parent
transcript, each subagent now produces a separate PromptRecord with
parent_id linking it to the parent prompt.

- Add SubagentInfo struct; parser returns subagents separately
- Propagate subagents through PromptUpdateResult pipeline
- Serialize subagent info into checkpoint agent_metadata
- Expand into separate PromptDbRecords at post-commit DB upsert
- Expand into separate PromptRecords in VirtualAttributions

Fixes: #371

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update all test files for the new 3-tuple return type from
transcript_and_model_from_claude_code_jsonl and the parent_id
field on PromptRecord/PromptDbRecord.

The subagent test now verifies that subagents are returned
separately (not merged) and that the main transcript contains
only main-session messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Run cargo fmt on all changed files. Fix
test_claude_transcript_parsing_malformed_json which incorrectly
expected Err — the parser skips unparseable lines by design,
returning Ok with an empty transcript.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Claude Code Subagent transcripts not saved in the transcript

2 participants

Comments