diff --git a/bin/loop-claude b/bin/loop-claude index 1c30b686..e088fbf9 100755 --- a/bin/loop-claude +++ b/bin/loop-claude @@ -26,7 +26,8 @@ boundary, once the new file answers --help. Claude Code internals this rests on, observed on 2.1.282: - The transcript is ~/.claude/projects/*/.jsonl, one JSON object per line. A / folder and .superseded-*/ and .orphaned-*.jsonl siblings belong to the same session. -- Claude Code writes "user" entries of its own into the transcript; typed() tells a human's from them. +- Claude Code writes "user" entries of its own into the transcript, and a `claude -p` prompt lands as one + with promptSource "sdk"; typed() tells a human's from them. - An "assistant" entry, in the transcript and in --output-format stream-json, carries message.content parts of type "text" (text) and "tool_use" (name, input); stream-json ends with a "result" event. - `claude -p --output-format json --json-schema` returns the verdict under "structured_output". @@ -173,13 +174,13 @@ def render(entries): lines += [line for part in entry.get("message", {}).get("content", []) if (line := said(part))] elif typed(entry): content = entry["message"]["content"] - lines.append("[human] " + (content if isinstance(content, str) else "".join(part["text"] for part in content))) + lines.append("[human] " + (content if isinstance(content, str) else "".join(part.get("text", "") for part in content))) return "\n\n".join(lines) def typed(entry): - """A human turn: a "user" entry, not isMeta, whose message.content is a string not starting with "<" ( and its kind) or one or more text parts, none starting with "[Request interrupted".""" - if entry.get("type") != "user" or entry.get("isMeta"): + """A human turn: a "user" entry, not isMeta, not promptSource "sdk" (the loop's own prompts), whose message.content is a string not starting with "<" ( and its kind) or one or more text parts, none starting with "[Request interrupted".""" + if entry.get("type") != "user" or entry.get("isMeta") or entry.get("promptSource") == "sdk": return False content = entry.get("message", {}).get("content") if isinstance(content, str):