Repository navigation
fix(claude-cli): send inbound context privately instead of in the user's message - #186439
Conversation
Native Claude prompts now hold only the sender's text: inbound context reaches Claude through the prompt hook and forwarded inputs are synthetic meta rows. History import matches on text plus the drift-note copy, as v2026.10.7 did.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR sends inbound context and session notices through Claude’s existing private prompt hook and removes superseded history-decoration matching. Example: The user sends “Reply with exactly the word DONE.” after a session-creation event.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a current Claude CLI history defect at the prompt producer, has visible before/after proof and green exact-head CI, and introduces no actionable defect found in this review. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCLI preparation combines the current request with host context; the Anthropic plugin submits them to Claude, whose native transcript is merged with canonical OpenClaw history for display. flowchart LR
A[User request] --> B[CLI prompt preparation]
B --> C[Private prompt hook]
B --> D[Claude CLI]
C --> D
D --> E[Native transcript]
F[Canonical transcript] --> G[History merge]
E --> G
G --> H[Control UI]
Technical reviewBest possible solution: Use the existing private-context owner for initial prompts and resume handoffs, retaining canonical transcript ownership and the documented historical-display tradeoff. Do we have a high-confidence way to reproduce the issue? Current main still inserts inbound context into native prompt text, and the supplied baseline screenshot demonstrates the resulting decorated bubble; this review ran no target code. Is this the best way to solve the issue? The change fixes context placement at the producer using the existing hook rather than expanding text-cleanup heuristics, and the retained tests cover private versus inline delivery and resume isolation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 738a5e06729f. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -208, Tests -240. Total -448 across 18 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 27, 2026, 10:09 PM ET / October 28, 2026, 02:09 UTC. |
|
Landed in f76e79b.
Thanks @Marvinthebored for finding this and for the original change in #185915. |
…r's message (openclaw#186439) Related: openclaw#185915, openclaw#185945 ## What Problem This Solves Fixes: on Claude CLI sessions, OpenClaw put its own context into the text of the user's message: inbound conversation context, the Git co-author note, queued `System:` events, and the session drift and gap notes. Claude saved that text as the user's prompt. Chat history then imported it as a second user bubble, because the importer's text stripping did not recognize every fragment (the co-author note, for example). ## Why This Change Was Made The plugin transport already has a private channel for host context: the `UserPromptSubmit` hook's `additionalContext`, which openclaw#185945 also uses for steered inputs. - `buildCliCurrentPrompt` returns the inbound context fragments and the drift/gap notes as `prependContext` when the session runs on the plugin transport. The rendered prompt holds only the sender's text. Other transports keep the old inline rendering. - Native Claude prompts now hold only what the person typed, and forwarded inputs are synthetic meta rows (openclaw#185945). So the importer's prompt-decoration matching has no new input to clean. This PR removes it: - `cli-session-history.prompt-text.ts` (system-event, gap-note, requester-hint and routed-envelope stripping) - the `routed_key` / `undecorated_text` views and the matchers that used them - the display cleanup for unmatched imported rows - History import goes back to the two keys that v2026.10.7 shipped: the text, plus a copy without the drift note. The removed views shipped only on `main` and beta. The history index is an in-memory SQLite table rebuilt on each read, so no stored schema changes. ## User Impact A Claude CLI message shows once in chat history, as the person wrote it. Claude still gets the same context, through the prompt hook. On sessions that ran before this change, rows written by beta builds can show their old context prefix again, as they did on v2026.10.7. ## Evidence **Live, real Claude CLI, Control UI.** Same turns on `main` and on this branch (stacked on openclaw#185945): | `main` | this PR | | --- | --- | |  |  | - `main`: the user bubble holds the Git co-author note and the queued `System:` session-creation events above "Reply with exactly the word DONE." - This PR: `chat.history` has one user row per turn, holding only the typed text. Claude's transcript records the same context as `hook_additional_context` on `UserPromptSubmit`. - The busy-parent scenario from openclaw#185945 still passes on this branch: the subagent result steered into the running turn reaches the parent, and history shows no extra user rows. **Tests and checks** - `prompt-context.test.ts`, `prepare.durable-context.test.ts`, `prepare.existing-session.test.ts` and `execute.native-history-owner.test.ts` cover the plugin-transport split and the unchanged inline rendering. - All `cli-session-history*`, `session-history*`, `chat-history*cli*`, `strip-inbound-meta` and `cli-runner` suites pass (93 files). - `check:changed` lanes: typecheck, lint and boundaries pass. The dead-export scan flags three exports in files this PR does not touch; `main` has the same failures. Size: +250/−698. Test lines: −240. Credit: @Marvinthebored found this and wrote the private-context change in openclaw#185915. This PR is its second part. **Merge danger:** two-way door. A revert restores inline context and the old matchers; nothing persisted changes. Blast radius: Claude CLI prompt rendering on the plugin transport and imported Claude CLI history display. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #185915, #185945
What Problem This Solves
Fixes: on Claude CLI sessions, OpenClaw put its own context into the text of the user's message: inbound conversation context, the Git co-author note, queued
System:events, and the session drift and gap notes. Claude saved that text as the user's prompt. Chat history then imported it as a second user bubble, because the importer's text stripping did not recognize every fragment (the co-author note, for example).Why This Change Was Made
The plugin transport already has a private channel for host context: the
UserPromptSubmithook'sadditionalContext, which #185945 also uses for steered inputs.buildCliCurrentPromptreturns the inbound context fragments and the drift/gap notes asprependContextwhen the session runs on the plugin transport. The rendered prompt holds only the sender's text. Other transports keep the old inline rendering.cli-session-history.prompt-text.ts(system-event, gap-note, requester-hint and routed-envelope stripping)routed_key/undecorated_textviews and the matchers that used themmainand beta. The history index is an in-memory SQLite table rebuilt on each read, so no stored schema changes.User Impact
A Claude CLI message shows once in chat history, as the person wrote it. Claude still gets the same context, through the prompt hook. On sessions that ran before this change, rows written by beta builds can show their old context prefix again, as they did on v2026.10.7.
Evidence
Live, real Claude CLI, Control UI. Same turns on
mainand on this branch (stacked on #185945):mainmain: the user bubble holds the Git co-author note and the queuedSystem:session-creation events above "Reply with exactly the word DONE."chat.historyhas one user row per turn, holding only the typed text. Claude's transcript records the same context ashook_additional_contextonUserPromptSubmit.Tests and checks
prompt-context.test.ts,prepare.durable-context.test.ts,prepare.existing-session.test.tsandexecute.native-history-owner.test.tscover the plugin-transport split and the unchanged inline rendering.cli-session-history*,session-history*,chat-history*cli*,strip-inbound-metaandcli-runnersuites pass (93 files).check:changedlanes: typecheck, lint and boundaries pass. The dead-export scan flags three exports in files this PR does not touch;mainhas the same failures.Size: +250/−698. Test lines: −240.
Credit: @Marvinthebored found this and wrote the private-context change in #185915. This PR is its second part.
Merge danger: two-way door. A revert restores inline context and the old matchers; nothing persisted changes. Blast radius: Claude CLI prompt rendering on the plugin transport and imported Claude CLI history display.