Skip to content

fix(native-chat): unwrap Claude's pasted_content so a multi-line prompt's echo retires - #23469

Closed
Harshul1484 wants to merge 2 commits into
stablyai:mainfrom
Harshul1484:fix/native-chat-pasted-prompt-echo
Closed

Harshul1484 wants to merge 2 commits into
stablyai:mainfrom
Harshul1484:fix/native-chat-pasted-prompt-echo

Conversation

@Harshul1484

@Harshul1484 Harshul1484 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you send a multi-line message in the chat view, Orca shows it straight away as a "pending" bubble and removes that copy once Claude Code saves the real message. Claude Code now saves pasted multi-line text wrapped in <pasted_content> tags, so Orca never recognised the saved message as the same one, and the pending bubble stayed stuck at the bottom of the chat for the rest of the session. This PR removes that wrapper when Orca reads Claude's transcript, so the two copies match again.

What Changed

  • Before: every multi-line prompt stayed pinned below all later replies, because the optimistic echo was never retired. Once it did match, the saved user bubble would also have shown the raw <pasted_content id="…"> tags.
  • After: the echo retires as soon as Claude records the turn, and the user bubble shows only the prompt.
  • Mechanism: Claude Code 2.1.283 records a pasted prompt as \n\n<pasted_content id="7e64">\n<prompt>\n</pasted_content id="7e64">\n. decodeClaudeTranscriptLine now unwraps that for user turns (claude-pasted-content.ts). It only unwraps when the whole text block is exactly one paste with matching opening and closing ids, so text typed around a paste, mismatched tags and assistant text are left untouched.

Why

The issue suggests two places for the fix: the pending-echo comparison key (normalizeNativeChatUserText), or the Claude transcript decoder. I went with the decoder. Fixing only the key would retire the echo, but the transcript row that replaces it would then render the literal tags in the user bubble. Unwrapping in the decoder fixes both, and keeps the Claude-specific format inside the Claude decoder instead of the provider-neutral normalizer.

Linked Issue

Fixes #23450

Visual Proof

Not captured. I couldn't run the desktop app on this machine, so the behavior is covered by decoder tests instead (below). The expected visual change: a multi-line prompt no longer stays pinned at the bottom of the chat, and its bubble shows no <pasted_content> tags.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

transcript-line-decoders-claude-pasted-content.test.ts (6 tests):

  • the pasted prompt decodes without the wrapper;
  • its normalized text equals the composer text, so the optimistic echo can retire;
  • a text block in array content and CRLF line endings are handled;
  • text around a paste, a wrapper with a mismatched closing id, and assistant text are left unchanged.

Without the decoder change, the first three fail and the three guards pass.

I also ran every native-chat suite (src/main/native-chat, src/shared/native-chat*, src/renderer/src/components/native-chat): the same 51 tests fail with and without this change. They fail only in my local environment (dependencies installed with --ignore-scripts, so native modules weren't built), and no suite fails only with the change. oxlint and oxfmt --check pass on the changed files, and a targeted tsc over them (using config/tsconfig.node.json settings) reports no errors in them. I didn't run the full pnpm typecheck and pnpm build: this machine doesn't have the memory for the 7 GB node typecheck, so CI will cover them.

AI Disclosure

I used Claude (Anthropic's Claude Opus 5.5, through Claude Code) to investigate the issue, write the fix and tests, and run the checks above. I reviewed the change and the test results.

Review

AI code review summary:

  • Cross-platform: pure string handling, with no paths or processes involved. CRLF line endings are handled and tested.
  • SSH/remote/local: the decoder runs wherever transcripts are read, and the change doesn't depend on where the transcript lives.
  • Agents and integrations: scoped to the Claude transcript decoder and to user turns. Codex and other providers are untouched. Orca dispatch prompts that type a lead line before a paste aren't a whole-block paste, so they're left as they are.
  • Performance: one anchored regex per user text block when a transcript line is decoded, with the tag id bounded to 64 characters.
  • UI: no new UI. The user bubble shows the prompt instead of the tags.
  • Security: transcript text is untrusted. The unwrap only removes a matching outer wrapper and never evaluates or interprets its contents.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Older transcripts without the wrapper decode exactly as before.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This PR fixes #23450 by unwrapping Claude Code's <pasted_content> wrapper in the Claude transcript decoder, so a multi-line prompt's optimistic echo matches the saved transcript row and retires, and the user bubble no longer renders the literal tags.

  • New claude-pasted-content.ts — adds unwrapClaudePastedContent, one anchored regex that returns the inner text only when the whole block is exactly one paste (optional id on both tags, opening id backreferenced on the closing tag), else returns the input unchanged.
  • transcript-line-decoders-claude.ts — decodeClaudeTranscriptLine maps role === 'user' blocks through withoutPastedContentWrapper; it only rewrites text blocks whose unwrap actually changed the text, leaving non-text blocks and assistant turns untouched.
  • New test file — 6 tests covering the unwrap, the normalization equality that drives echo retirement, array content with CRLF, text around a paste, a mismatched closing id, and assistant text quoting the wrapper. The first three fail without the decoder change.

I re-ran the touched suite (13 passed across the Claude decoder tests), oxlint, oxfmt --check, check:code-quality:changed (0 new findings), and typecheck:node — all clean. The decoder approach is the stronger of the two the issue suggested, since it also removes the tags from the rendered bubble instead of only fixing the comparison key, and it keeps the Claude-specific format inside the Claude decoder rather than the provider-neutral normalizer.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Delta since the prior review: the only new commit (f4f7a3d) shortens the file-level Why: comment in claude-pasted-content.ts and drops the function JSDoc. No behavior, signatures, regex, or test changes — the decoder and its 6 tests are byte-identical to the reviewed b93e6c0. Re-ran the Claude decoder suite (13 passed), oxlint, and check:code-quality:changed (0 new findings) at the new head; all clean. My prior review's assessment — mergeable as-is — stands.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 5206137e-711e-4818-b1b3-e9f8f2b5de52

📥 Commits

Reviewing files that changed from the base of the PR and between 838769d and f4f7a3d.

📒 Files selected for processing (3)
  • src/main/native-chat/claude-pasted-content.ts
  • src/main/native-chat/transcript-line-decoders-claude-pasted-content.test.ts
  • src/main/native-chat/transcript-line-decoders-claude.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change adds unwrapClaudePastedContent to remove matching pasted-content wrappers, including wrappers with LF or CRLF line breaks. The Claude transcript decoder applies it to text blocks in user messages and leaves assistant messages and non-text blocks unchanged. Tests cover matching and mismatched IDs, surrounding text, string and array content, and assistant messages.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to f4f7a

The change is mergeable after normal checks. A rare prompt that literally contains a complete pasted-content wrapper may not match its pending echo.

Security Architecture Review

Security architecture risk: 🔵 Low · up to f4f7a

Saved pasted prompts should now replace their temporary copies correctly. No new permissions or external services are involved. A prompt that literally resembles Claude’s paste markers could, in some circumstances, be shown differently; whether that occurs in normal use remains unconfirmed.

Retained concerns

  • Low · security · inferred: A wrapper-shaped Claude user record is unwrapped without distinguishing provider formatting from literal user text. If literal text reaches the decoder without an additional outer wrapper, the displayed turn loses content and its pending copy may not match for retirement. Live submission reachability is unverified.
Security review details

Security Blast Radius

  • inferred — The demonstrated effect is confined to decoded Claude user text and its downstream presentation and matching. The inspected change grants no tool, credential, or service authority; broader exposure from specially shaped submitted text is not established.

Security Findings and Attack Paths

  • inferred — A user record whose entire text literally matches the wrapper grammar is decoded as its body. This establishes a content-integrity edge case, not a verified live exploit: the available evidence does not show whether submission would add an outer provider wrapper first.

Trust Boundaries and Controls

  • observed — The decoder accepts transcript JSON as input, restricts unwrapping to Claude user text blocks, and requires a complete wrapper with matching IDs. These controls constrain the transform but do not identify whether the wrapper originated with Claude or the user.

Hardening Proposals

  • proposed — Verify the submitted-literal-wrapper case against an actual Claude transcript, including repeated sends and recovery, before relying on wrapper shape alone as evidence of provider formatting.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements issue #23450. unwrapClaudePastedContent removes a complete Claude <pasted_content> wrapper with matching IDs and LF or CRLF line endings. The Claude decoder applies it only to us…
Out of Scope Changes check ✅ Passed The changed files contain only the wrapper helper, its Claude user-message decoder integration, and focused automated tests. Each change supports issue #23450. No unrelated product behavior or unrelat…
Title check ✅ Passed The title clearly identifies the Claude native-chat fix and its purpose: unwrapping pasted content so multi-line prompt echoes retire.
Description check ✅ Passed The description covers all required sections, explains the user impact and implementation, links issue #23450, documents testing and limitations, and addresses compatibility and security. Visual proof…
  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Chat view never retires the echo of a multi-line prompt because Claude Code records pastes inside <pasted_content> tags

1 participant