diff --git a/internal/claude/claude.go b/internal/claude/claude.go index 0ca422b..db731c7 100644 --- a/internal/claude/claude.go +++ b/internal/claude/claude.go @@ -317,8 +317,9 @@ func applyMeta(src *session.Source, line claudeLine) { // directory it was started in, and Claude Code stamps every record with // wherever the agent stands at the time, so a cd into a subdirectory or a // worktree would otherwise move the whole session out of the listing run - // where the user began it. - if line.Cwd != "" && src.Metadata["cwd"] == "" { + // where the user began it. A sidechain record is a subagent's, not the + // session's, so it never claims the directory. + if line.Cwd != "" && !line.IsSidechain && src.Metadata["cwd"] == "" { src.Metadata["cwd"] = line.Cwd } if line.GitBranch != "" { diff --git a/internal/claude/claude_test.go b/internal/claude/claude_test.go index 27b8a3e..da7826d 100644 --- a/internal/claude/claude_test.go +++ b/internal/claude/claude_test.go @@ -87,8 +87,10 @@ func TestReadThread(t *testing.T) { // A session that cd's away keeps the directory it was started in: the records // below walk into a subdirectory, on to a sibling repo, and back, and the // first cwd is the one a listing must find it under. The empty cwd ahead of -// them stands for a record that carries the field without a value. +// them stands for a record that carries the field without a value, and the +// sidechain record after it for a subagent that started elsewhere. const wanderer = `{"type":"user","sessionId":"sess-w","cwd":"","timestamp":"2026-06-26T10:00:00Z","message":{"role":"user","content":"start here"}} +{"type":"user","sessionId":"sess-w","cwd":"/home/u/src/catchup/internal","isSidechain":true,"timestamp":"2026-06-26T10:00:02Z","message":{"role":"user","content":"subagent task"}} {"type":"assistant","sessionId":"sess-w","cwd":"/home/u/src/catchup","timestamp":"2026-06-26T10:00:05Z","message":{"role":"assistant","content":[{"type":"text","text":"ok"}]}} {"type":"user","sessionId":"sess-w","cwd":"/home/u/src/catchup/internal","timestamp":"2026-06-26T10:01:00Z","message":{"role":"user","content":"now the subdirectory"}} {"type":"user","sessionId":"sess-w","cwd":"/home/u/src/other","timestamp":"2026-06-26T10:02:00Z","message":{"role":"user","content":"now the sibling"}}