-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem
Currently, RetroChat assumes "1 conversation = 1 file" when importing Claude Code conversations. However, Claude Code stores subagent conversations (spawned via the Task tool) in separate files, breaking this assumption.
How Claude Stores Subagent Conversations
File Structure
~/.claude/projects/{project}/
├── {sessionId}.jsonl # Main conversation
└── agent-{agentId}.jsonl # Subagent conversations (separate files)
Linking Mechanism
Main conversation contains a Task tool invocation and result:
// Task tool invocation (in assistant message)
{
"type": "tool_use",
"name": "Task",
"input": {
"description": "Explore data model structure",
"prompt": "...",
"subagent_type": "Explore"
}
}
// Tool result with agentId reference (in user message)
{
"toolUseResult": {
"status": "completed",
"agentId": "aadaaea", // Links to agent-aadaaea.jsonl
"prompt": "...",
"totalDurationMs": 63921,
"totalToolUseCount": 26
}
}Agent file (agent-{agentId}.jsonl) contains:
{
"sessionId": "20b86564-...", // Same sessionId as parent!
"agentId": "aadaaea",
"isSidechain": true, // Marks as subagent conversation
"parentUuid": "...", // Message chain within agent
...
}Key Fields
| Field | Location | Purpose |
|---|---|---|
sessionId |
Both files | Shared identifier grouping parent + agents |
agentId |
Agent file | Unique identifier (filename: agent-{agentId}.jsonl) |
isSidechain |
Agent file | Boolean flag marking messages as subagent context |
toolUseResult.agentId |
Parent file | Links to which agent file has the full conversation |
Current Behavior
agent-*.jsonlfiles are completely ignored during import- Subagent conversations are lost
- The
toolUseResultin the parent conversation contains only the final summary, not the full agent conversation
Proposed Solution
Schema Changes
ALTER TABLE chat_sessions ADD COLUMN parent_session_id TEXT
REFERENCES chat_sessions(id) ON DELETE CASCADE;
ALTER TABLE chat_sessions ADD COLUMN agent_id TEXT;
ALTER TABLE chat_sessions ADD COLUMN is_sidechain BOOLEAN DEFAULT FALSE;
ALTER TABLE chat_sessions ADD COLUMN spawn_tool_use_id TEXT;Relationship Model
┌─────────────────────────────────────────────────────────┐
│ Main Session: 20b86564-d913-435b-ae5f-970dc6781821 │
│ file: 20b86564-....jsonl │
│ │
│ msg1 → msg2 → [Task tool: spawn agent-aadaaea] → msg3 │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────┐ │
│ │ Subagent Session: aadaaea │ │
│ │ file: agent-aadaaea.jsonl │ │
│ │ parent_session_id: 20b86564-... │ │
│ │ is_sidechain: true │ │
│ │ │ │
│ │ agent_msg1 → agent_msg2 → ... │ │
│ └─────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
Implementation Tasks
- Update
ClaudeCodeParserto detect and parseagent-*.jsonlfiles - Add new fields to
ChatSessionmodel - Create database migration for new schema
- Link agent sessions to parent sessions via
toolUseResult.agentId - Update TUI to display session hierarchy (collapsible subagents?)
- Update MCP server to expose subagent relationships
- Consider analytics implications (aggregate parent+children?)
Notes
The "1 conversation = 1 file" paradigm still holds in a sense - Claude treats subagents as separate conversations that share a session context. The sessionId is a grouping identifier, not a file identifier.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels