Skip to content

Subagent session filenames collide due to session_id[:8] truncation #53

Description

@fabianyvidal

Bug

In extract_claude_logs.py (1.1.2), output filenames are generated as:

filename = f"claude-conversation-{date_str}-{session_id[:8]}.md"

For most sessions session_id is a UUID and [:8] gives a unique hex prefix. But Claude Code's subagent sessions use named IDs like agent-aabb12cd, where [:8] strips the disambiguating tail and yields agent-aa. Different subagents on the same date with the same 8-char prefix collide — the second write silently overwrites the first.

Repro

On my machine (~/.claude/projects/ contains 3009 session JSONLs):

  • 1366 of them are subagent sessions (agent-*.jsonl)
  • After claude-extract --all --output ~/exports, only ~2030 markdown files remain
  • ~979 subagent sessions are silently lost (33% of total history)

Distribution of 8-char prefixes among subagent files:

```
209 agent-ac
87 agent-aa
85 agent-af
82 agent-a8
82 agent-a0
81 agent-a7
79 agent-a5
78 agent-ad
78 agent-a6
76 agent-a9
```

Each row above represents one surviving file out of N originals.

Fix

Use the full `session_id` stem rather than `[:8]`. Optionally append a short hash of the parent project directory to disambiguate sessions from different projects that happen to share an agent name.

I implemented a standalone replacement here — happy to send a PR against this repo if useful.

Impact

For users of subagents (which is most heavy users of Claude Code's Task tool), this means a third or more of their conversation history is missing from exports without any warning or error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions