Skip to content

fix(claude-cli): send inbound context privately instead of in the user's message - #186439

Merged
obviyus merged 2 commits into
mainfrom
fix/claude-cli-private-inbound-context
Oct 28, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/claude-cli-private-inbound-context

Conversation

@obviyus

@obviyus obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

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 UserPromptSubmit hook's additionalContext, which #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 (fix(claude-cli): keep each steered input's own origin and context #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 #185945):

main this PR
main: OpenClaw context shown as the user's message this PR: only the typed message
  • 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 fix(claude-cli): keep each steered input's own origin and context #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 #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.

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.
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 28, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The user bubble includes Git co-author guidance and queued System events above the request.
  • After: The bubble contains only the typed request, while Claude receives host context through UserPromptSubmit.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused producer repair with inspected live UI proof, existing transport ownership, meaningful boundary coverage, and green exact-head gates.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): Inspected before/after Control UI screenshots from real Claude CLI runs show generated context disappearing from the user bubble; the accompanying live report records clean chat.history rows, private hook attachments, and preserved busy-parent completion behavior.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Claude CLI history presents OpenClaw-generated context as text the user typed, sometimes creating an extra user bubble.
Reason: The collaborator-authored direction restores accurate message authorship through an existing transport capability and explicitly accepts the historical beta-display consequence.

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
Reviewed head: e9cc24e98411dcde4c3fa35ea3658843fa94197b

Before merge

None.

Findings

None.

Agent review details

How this fits together

CLI 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]
Loading

Technical review

Best 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

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source -208, Tests -240. Total -448 across 18 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 10 122 330 -208
Tests 8 128 368 -240
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 250 698 -448

Labels

Label changes:

  • add P2: Incorrect duplicate or decorated user bubbles affect Claude CLI history, with a limited runtime-specific blast radius.
  • add merge-risk: 🚨 compatibility: Removing decoration matching changes display of existing beta-native transcript rows; the maintainer-authored PR explicitly accepts that tradeoff and preserves stored bytes.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Incorrect duplicate or decorated user bubbles affect Claude CLI history, with a limited runtime-specific blast radius.
  • merge-risk: 🚨 compatibility: Removing decoration matching changes display of existing beta-native transcript rows; the maintainer-authored PR explicitly accepts that tradeoff and preserves stored bytes.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 27, 2026, 10:09 PM ET / October 28, 2026, 02:09 UTC.

@obviyus
obviyus merged commit f76e79b into main Oct 28, 2026
149 checks passed
@obviyus
obviyus deleted the fix/claude-cli-private-inbound-context branch October 28, 2026 02:11
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in f76e79b.

  • Bug: OpenClaw's context (co-author note, queued System: events, drift and gap notes) was sent inside the user's Claude CLI message, so chat history showed it as a second user bubble.
  • Fix: that context goes to Claude through the prompt hook; the native prompt holds only what the person typed. The importer's decoration matching is removed (+250/−698).
  • Proof: live Control UI run with real Claude CLI, before/after screenshots above; Claude still receives the context as hook_additional_context.

Thanks @Marvinthebored for finding this and for the original change in #185915.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…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: OpenClaw context shown as the user's message](https://github.com/user-attachments/assets/40df4e35-a1a4-46d4-96f5-5812d5de426f) | ![this PR: only the typed message](https://github.com/user-attachments/assets/929d9f9d-a3fd-44dd-868e-ab2fdcb1dda9) |

- `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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant