Version: @anthropic-ai/claude-agent-sdk 0.3.286 (via @agentclientprotocol/claude-agent-acp 0.85.1), macOS
Description
listSessions() gets cwd by searching for "cwd":" in only the first 64 KB of the transcript. When the first user message has an inline base64 image, that JSONL line can be hundreds of KB long. The cwd field sits at the end of the line, so it falls outside the 64 KB window. The session then comes back with cwd: undefined.
Example from one transcript:
line 1 len=138 queue-operation
line 2 len=138 queue-operation
line 3 len=274326 first user message (base64 screenshot), "cwd" at byte ~274204
Impact
Consumers that need cwd drop these sessions. For example, claude-agent-acp's session/list skips any entry without cwd, so ACP clients never see the session. From the user's side, sessions that start with a screenshot "disappear" from the list. On one machine 13 real sessions were hidden this way, even though the transcripts were complete and could still be resumed with claude --resume.
Steps to reproduce
- Start a session whose first prompt includes a screenshot. The base64 data needs to be larger than about 64 KB.
- Call
listSessions().
- That session's entry has
cwd: undefined. Sessions without an image in the first prompt are fine.
Proposed fix
If cwd is not found in the head buffer, keep reading forward from where the head ends until the first "cwd":" is found. This gives the same value as for normal sessions: the cwd of the first user record. The extra read only happens for these transcripts and costs about the size of the inline image, so normal sessions are not affected.
A cheaper partial fallback is to look in the tail buffer, which is already read. But the tail can hold a different cwd if the session switched directories mid-way (e.g. via EnterWorktree), so reading forward is the accurate option.
Workaround
Moving the cwd key to the start of the first user record (the JSON content stays the same) makes the session show up again.
Version:
@anthropic-ai/claude-agent-sdk0.3.286 (via@agentclientprotocol/claude-agent-acp0.85.1), macOSDescription
listSessions()getscwdby searching for"cwd":"in only the first 64 KB of the transcript. When the first user message has an inline base64 image, that JSONL line can be hundreds of KB long. Thecwdfield sits at the end of the line, so it falls outside the 64 KB window. The session then comes back withcwd: undefined.Example from one transcript:
Impact
Consumers that need
cwddrop these sessions. For example,claude-agent-acp'ssession/listskips any entry withoutcwd, so ACP clients never see the session. From the user's side, sessions that start with a screenshot "disappear" from the list. On one machine 13 real sessions were hidden this way, even though the transcripts were complete and could still be resumed withclaude --resume.Steps to reproduce
listSessions().cwd: undefined. Sessions without an image in the first prompt are fine.Proposed fix
If
cwdis not found in the head buffer, keep reading forward from where the head ends until the first"cwd":"is found. This gives the same value as for normal sessions: thecwdof the first user record. The extra read only happens for these transcripts and costs about the size of the inline image, so normal sessions are not affected.A cheaper partial fallback is to look in the tail buffer, which is already read. But the tail can hold a different
cwdif the session switched directories mid-way (e.g. via EnterWorktree), so reading forward is the accurate option.Workaround
Moving the
cwdkey to the start of the first user record (the JSON content stays the same) makes the session show up again.