From 041deebccabffd3d8adb20498bd4d56bdc67438c Mon Sep 17 00:00:00 2001 From: Hongyi Shen Date: Mon, 21 Sep 2026 11:12:21 -0700 Subject: [PATCH] claude: keep a sidechain record from claiming the session's directory #17 made the first cwd in a transcript the session's directory, but applyMeta runs before sidechain records are skipped. A subagent record ahead of the first main record with a cwd therefore set the directory, and no later record could replace it. Sidechain records no longer set the directory. Co-Authored-By: Claude Opus 5 --- internal/claude/claude.go | 5 +++-- internal/claude/claude_test.go | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) 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"}}