[Bug] Fork on completed /btw response re-submits original prompt instead of continuing session
Bug Description
Pressing "f" (fork) on a completed /btw response re-submits the original prompt instead of just continuing the session.
Repro: submit /btw <message>, wait for the response, then in the response viewer (escape: close, c: copy, f: fork) press f.
Actual: a new forked session is created with the parent transcript, and the original /btw message is re-submitted as a directive — so the fork starts re-answering an already-answered question (duplicate agent run, wasted tokens; from the user's side it looks like the message was double-sent).
Expected: forking a completed exchange should seed the new session with the transcript as history and leave the user to type their next message. Re-submitting the prompt only makes sense if the agent hasn't already answered the /btw <message> prompt.
Environment Info
- Platform: darwin
- Terminal: Apple_Terminal
- Version: 2.1.233
- Feedback ID: 953950f0-3ddb-443d-a581-0ccb7a9f1064
Errors
[]
3 Comments
Authorship note: Claude wrote the below comment under my guidance. I did actually perform the described repro myself, it's not just a Claude hypothetical.
Edit: I changed "I / my" to the "the user / the" so it's more clear that Claude wrote it.
---
Additional context: root cause from session logs, plus a clean-room repro (Claude Code v2.1.233, macOS).
The user's (Daniel's) original report said pressing
f"re-submits the original message." After examining the session logs (the main session's JSONL and the fork's transcript undersubagents/) and reproducing in a fresh session, the picture is more specific. There are two bugs that chain into an automatic failure, plus two UX problems.Summary: pressing
fon a completed/btwresponse (1) spawns the fork as a one-shot worker that re-executes the already-answered question and exits, and (2) writes the/btwquestion into the main session's history, where the main assistant picks it up and responds. The two combine: the worker's completion notification triggers the main session seconds after thefpress, so the leak happens with no further user action.Minimal repro
/btw <any question>. The overlay answers normally (isolation is still intact at this point).fto fork.Observed: the fork runs on its own and terminates (Bug 1). Its completion notification reaches the main session, which now has the
/btwquestion and the fork's answer in context and responds to them (Bug 2).To verify directly, ask the main assistant "do you see the /btw message in your context?". In the main session's JSONL, the
/btwcommand turn appears as"subtype":"local_command"records timestamped at thefpress, not at the/btwsubmission.Bug 1:
fcreates the fork as a one-shot worker, not a continuable sessionThe fork's transcript shows the documented part working first: the
/btwquestion and the overlay answer are copied in as real transcript turns (their timestamps are identical, milliseconds after fork creation, so this is a copy rather than a live generation). Immediately after, a<fork-boilerplate>turn is appended:…with the already-answered question as its directive. The fork obeys: it re-answers the question on its own (in the repro it ran
git logvia Bash to re-answer what the overlay had already answered) and then stops, per the boilerplate's "report once and stop." Total lifetime in the repro: about 8 seconds. The continuable session the docs describe never exists, and by the time the user navigates to the agent, it has finished.(In the user's original session, they did get a conversation with the fork, but only because they happened to interrupt its self-run with Escape and then message it, which resumed it.)
The docs (interactive-mode.md, response-viewer keybindings) describe
fas forking into a new session that inherits the Q&A "so you can continue with full tool access."Bug 2:
fleaks the/btwquestion into the main session's historyThe
/btwsubmission itself writes nothing about the question to the main session's log, so the documented isolation holds at that point. Thefpress is what breaks it: it appends the/btwcommand turn and the fork stdout to the main session's log as"subtype":"local_command"records withisMeta: false. That is the ordinary, model-visible record type used for slash-command turns.Those records sit pending until the next model invocation in the main session, whatever triggers it:
fpress, with no further user action.fpress.At that invocation, the main assistant receives the question as a normal command turn and responds. (Notably, the records arrive without the
<local-command-caveat>wrapper that accompanies local-command records delivered alongside a regular user message, so nothing tells the assistant to ignore them.) In the original session it produced a full second answer, different from the overlay's and generated with tool access (it wrote files). In the repro it relayed the fork's answer. Either way, the question and the fork's answer (carried in the task notification) both end up in the main session's history.The documented contract (interactive-mode.md, "Side questions with /btw"): "The question and answer never enter the conversation history."
UX problems
freturned the user to the main session instead of switching into the fork, which was only reachable through the background-agents UI (down arrow). By then, it had already finished per Bug 1. The forked session wasn't usable at all.Suggested fixes
ffrom a completed exchange, seed the fork with the Q&A as history and give the user the prompt. No worker directive, no self-started run./btwcommand turn to the main session onf(or flag it so context assembly excludes it), and suppress the fork's lifecycle notifications in the main session, or at least strip the/btwcontent from them.Evidence available on request: record-type and timestamp skeletons from both sessions' JSONLs showing the
local_commandrecords written at thefpress, the copied Q&A pair, the<fork-boilerplate>directive, and the fork's self-started run.btw, I'll be watching this thread myself, so if further details or info would be useful, let me know. I hope the above breakdown is helpful and clear.
Edit: One more note. I don't fully understand what happened in the original session which caused the forked agent to receive the <message> from
/btw <message>as a second message, right at fork time. That was why I hit "escape" on the forked agent, which then caused it to not be auto-finished, and thus I could continue interacting with it. This issue was, in fact, produced by the/feedback-> github issue flow in that original forked agent.Confirmed / reproduced on 2.1.234 (Linux): after a
/btwquestion has been answered in the overlay, pressingfdoes not open a continuable forked session. It spawns a one-shot background fork (⑂ forked … (xxxx)) whose context is the parent transcript + the/btwquestion and answer, followed by the same question again as its directive, so it immediately re-answers it (an extra model request) and finishes within seconds. You stay in the original session, and on its next model call that session's context now contains the/btwcommand turn, the fork's output line and the fork's completion notification, and the assistant responds to them without any user action — matching both parts of the follow-up analysis above.This differs from the documented behaviour of
f("Fork into a new session… so you can continue with full tool access") and of/btw("The question and answer never enter the conversation history"): https://code.claude.com/docs/en/interactive-mode🤖 Generated with Claude Code
---
_Generated by Claude Code_