You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: Group a session's model calls into user prompts, in the recording and the timeline #1922
The timeline's unit is one model call (Turn, core/session/timeline/timeline.go:78). A user prompt usually causes many
calls: tool loops, subagents, retries. Some calls are not the user's at all:
the agent's own title, suggestion and away-summary calls show up as main.
Replay and analysis need "what did the person ask, and what did it cost",
plus the user's think time between prompts. Nothing in the archive or the
timeline groups calls that way today.
Proposal
Derive prompts from the request bodies. A new prompt starts at a request
whose newest user message is new human text, not a tool result or an
injected message. Filter out the messages the agent injects that look like
user input (system reminders, command scaffolding, away summaries,
suggestion and compaction text). Handle compaction and --resume.
A prompt is the group of model calls caused by one human instruction: the tool loop, the subagents and the retries until the agent answers. Cortex's timeline Turn is one model call (core/session/timeline/timeline.go:78), so this note says "prompt". The name is open (§7).
1. What we already know (measured, in our own recorder)
The text is in the bodies. Claude Code resends the whole conversation on each call, so the human's text is in the request bodies the proxy sees.
A body-derived reconstruction works. On our own recorded Claude Code sessions, the rule below recovered about 96% of the turns that Claude Code's own telemetry records (claude_code.interaction). Most of the misses were correctly not human: slash commands with no model call (/clear, /exit), and task notifications.
Think time (end of the previous prompt's last call to the start of the next prompt's first call) matched Claude Code's claude_code.interaction timing within 0.4 s on 13 of 13 gaps. Prompt duration matched within 0.4 s on 14 of 15. That's a small sample, so the parity test below re-checks it.
We have a working version of this rule in Go from an earlier recorder of ours; it's what this note ports, plus the fixes below.
2. The heuristic (Claude Code)
Input: the timeline's main-agent calls, in order (agentRole == main), with Cortex's existing filters already applied. Progress labels (progressPrompt) and away recaps (recapPrompt) are already told apart in timeline/agents.go, and Resent already marks retries.
Rule. A new prompt starts at a main-agent request whose newest user message holds new human text: text that no earlier request of the session carried at that position. It does NOT start for:
a tool result: a user message made only of tool_result blocks, images included. An image returned by Read is a tool result, not a caption;
the away recap, [SUGGESTION MODE, the progress label, and the "new conversation topic" title probe;
skill and tool documents that Claude Code inlines.
A message holding only these is no prompt. A message holding these and human text is one, judged on the text left after removing them;
a resend (Resent): the same conversation again;
side calls: title generation, suggestion mode and the topic probe. They come from the same agent, but their own request is not the main conversation. Detect them by their last user message, as progressPrompt is.
Compaction. After a compaction the first request starts with the summary (isCompactSummary in the transcript; in the body, a first user message that is the summary). That request is not a new prompt. The prompt it serves continues.
--resume. A resumed session's first request carries the old history. The "new text" test compares against what this recording saw. With an archive the earlier calls are there; without one, the resume's first request would look new. So: a request whose newest human text appears in earlier messages of the same request (it's history) doesn't start a prompt.
Subagents. A subagent's calls belong to the prompt that was open when its spawning Agent tool call was made. The timeline already links them (SpawnTool).
Think time for prompt n is start(n) − end(n−1), where the end is the last main-agent call of n−1 to finish. Away recaps and suggestion calls in between don't count; without that exclusion, 5 gaps were about 187 s short. Unset for the first prompt.
3. Where it lives
Computed on demand, like the timeline. Prompts are another span kind built in timeline.Build from the same events: Timeline.Prompts []Prompt, omitted when empty so an older agentop is unaffected. Not stored. Reasons:
the rules will change (each new injected marker is a rule change), and stored prompts would go stale;
the archive's fold already replays history;
the timeline is cached per session.
typePromptstruct {
Indexint`json:"index"`// 1-based within the sessionStart time.Time`json:"start"`// first call's requestEnd*time.Time`json:"end,omitempty"`// last call's response; nil while runningFirstSequint64`json:"firstSeq"`LastSequint64`json:"lastSeq,omitempty"`ThinkMsint64`json:"thinkMs,omitempty"`// gap since the previous prompt endedSourcestring`json:"source"`// "derived" | "telemetry"
}
The prompt's text is not in the timeline (it's content). The timeline has none today, and a reader takes it from the first call's body when needed.
When Claude Code's claude_code.interaction span is present for the session, it wins:
Boundaries and duration come from the span (interaction.sequence, duration_ms), with Source: "telemetry".
Calls are assigned to it by time: a call whose request falls inside the span.
The heuristic still runs, for prompts whose spans were lost (span pipelines can drop under load; we've seen it), and to cross-check. A disagreement is a test signal, not shown to users.
Human time inside a prompt (tool.blocked_on_user) can then be subtracted, which the bodies alone can't do.
5. Tests
Golden sessions: real Claude Code bodies, already in core/plugins/inferenceparser/testdata/claude-code/…, plus new short fixtures. Each needs the expected prompt boundaries and think time. Cases:
a tool loop;
a subagent;
a retry;
an away recap and a suggestion call between prompts;
a compaction;
a --resume;
an image returned by Read;
a <task-notification>;
a slash command (no prompt);
a message that is both a system reminder and human text.
Rule tests for each injected marker: alone (no prompt) and mixed with text (a prompt).
Think-time tests: gaps that contain a recap or suggestion call.
Parity (dev-only, not CI): the 13-gap measurement, re-run against a dual-recorded session: within 0.4 s.
A shape test:Prompts is omitted when empty, and an older agentop decodes the timeline unchanged.
6. PR split (small)
PR A:timeline.Prompts: the heuristic for Claude Code, think time, and the golden and rule tests. Docs in session-api.md (timeline section). No UI, no export.
PR B: agentop shows prompts above the turns, with think time.
Later: other agents, each with its own injected markers (Codex, OpenCode, Pi, Bob), checked against real bodies first.
7. Open questions
Name: Cortex's Turn is one model call. We need a name for "everything from one Enter to the next". "Prompt", or "Interaction" (Claude Code's span name)?
Where: a layer in /timeline above the turns (proposed), or a route of its own?
Computed or stored: derived when the timeline is built (proposed; one cheap pass, and old sessions benefit when the rules improve), or stored with the session?
Text preview: show a short preview of what the user typed, like the session title, or only the prompt number? It's content, so a privacy call.
Activity
michaljacovi commentedon Nov 20, 2026
Design before the first PR
A prompt is the group of model calls caused by one human instruction: the tool loop, the subagents and the retries until the agent answers. Cortex's timeline
Turnis one model call (core/session/timeline/timeline.go:78), so this note says "prompt". The name is open (§7).1. What we already know (measured, in our own recorder)
claude_code.interaction). Most of the misses were correctly not human: slash commands with no model call (/clear,/exit), and task notifications.claude_code.interactiontiming within 0.4 s on 13 of 13 gaps. Prompt duration matched within 0.4 s on 14 of 15. That's a small sample, so the parity test below re-checks it.2. The heuristic (Claude Code)
Input: the timeline's main-agent calls, in order (
agentRole == main), with Cortex's existing filters already applied. Progress labels (progressPrompt) and away recaps (recapPrompt) are already told apart intimeline/agents.go, andResentalready marks retries.Rule. A new prompt starts at a main-agent request whose newest user message holds new human text: text that no earlier request of the session carried at that position. It does NOT start for:
a tool result: a user message made only of
tool_resultblocks, images included. An image returned byReadis a tool result, not a caption;injected look-alikes:
<system-reminder>blocks;<command-name>,<command-message>,<local-command-stdout>);<task-notification>and<agent-message …>;[SUGGESTION MODE, the progress label, and the "new conversation topic" title probe;A message holding only these is no prompt. A message holding these and human text is one, judged on the text left after removing them;
a resend (
Resent): the same conversation again;side calls: title generation, suggestion mode and the topic probe. They come from the same agent, but their own request is not the main conversation. Detect them by their last user message, as
progressPromptis.Compaction. After a compaction the first request starts with the summary (
isCompactSummaryin the transcript; in the body, a first user message that is the summary). That request is not a new prompt. The prompt it serves continues.--resume. A resumed session's first request carries the old history. The "new text" test compares against what this recording saw. With an archive the earlier calls are there; without one, the resume's first request would look new. So: a request whose newest human text appears in earlier messages of the same request (it's history) doesn't start a prompt.Subagents. A subagent's calls belong to the prompt that was open when its spawning
Agenttool call was made. The timeline already links them (SpawnTool).Think time for prompt n is
start(n) − end(n−1), where the end is the last main-agent call of n−1 to finish. Away recaps and suggestion calls in between don't count; without that exclusion, 5 gaps were about 187 s short. Unset for the first prompt.3. Where it lives
Computed on demand, like the timeline. Prompts are another span kind built in
timeline.Buildfrom the same events:Timeline.Prompts []Prompt, omitted when empty so an older agentop is unaffected. Not stored. Reasons:promptIndex. The content-free export (feature: export session events for post-processing — content-free per-event projection, NDJSON sink, archive-replayable #1810) could carry it too, since an index is not content (open, §7).4. With telemetry (#1924)
When Claude Code's
claude_code.interactionspan is present for the session, it wins:interaction.sequence,duration_ms), withSource: "telemetry".tool.blocked_on_user) can then be subtracted, which the bodies alone can't do.5. Tests
core/plugins/inferenceparser/testdata/claude-code/…, plus new short fixtures. Each needs the expected prompt boundaries and think time. Cases:--resume;Read;<task-notification>;Promptsis omitted when empty, and an older agentop decodes the timeline unchanged.6. PR split (small)
timeline.Prompts: the heuristic for Claude Code, think time, and the golden and rule tests. Docs insession-api.md(timeline section). No UI, no export.promptIndexon exported calls.Source: "telemetry") and human time inside a prompt.7. Open questions
Turnis one model call. We need a name for "everything from one Enter to the next". "Prompt", or "Interaction" (Claude Code's span name)?/timelineabove the turns (proposed), or a route of its own?session/fold.go) already skips the same scaffolding. Share one list withtimeline/agents.go, or keep two?Comments welcome, especially on the open questions in section 7.
Assisted-By: Claude (Anthropic AI) [email protected]
feat: Group a session's turns into prompts in the timeline