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
fix(native-chat): show a terminal's unsent input in the chat composer and replace it on send - #36493
Before this change, if you typed something into Claude's input box in terminal view and then switched to chat view, the chat box was empty. The next message you sent from chat then deleted your terminal text, or mixed part of it into your message. Now the chat box shows the text that's waiting in the terminal. Sending replaces it cleanly.
What Changed
Before, on Claude Code 2.1.314 (the same result on main through a real PTY and in a hidden dev build):
Type please look at the flaky retry test in the terminal and switch to chat view: the composer is empty.
Send from chat: the single Ctrl+U clears that line, so the draft is deleted without a word.
Type a 3-line draft with the cursor on line 2 and send from chat: Claude receives alpha line\nReply with just the word OK.wo\ngamma three.
After:
The composer shows the terminal draft, multi-line drafts included.
A chat send clears every line of the draft before writing, so Claude receives exactly the composer text.
If you edit the draft in the terminal and come back, the composer picks up the edit.
If you sent or cleared it in the terminal, the composer copy goes away.
If the composer already holds your own text, the terminal draft is added on a line below it (product call), never twice.
Mechanism:
Reading the draft. A new shared readTerminalComposerTypedText reads only the undimmed text on the agent's input line. It returns '' when the prompt is empty, even with a dim placeholder or suggestion showing, and null when no composer is visible. It keeps the user's indentation on continuation lines and reads from the live screen, so a scrolled-back terminal is read whole.
Seeding the composer. On entering chat view, useNativeChatTerminalDraftPickup reads that line once. It seeds the text as the tab's NativeChatLaunchDraft with fromTerminal: true, so the existing adoption and replace-on-send paths take over. The seed is skipped in these cases:
while a launch draft Orca typed still owns the line;
Retiring the seed. A chat send or the next read retires a terminal seed. Transcript timestamps can't, because the draft follows earlier turns.
Confirming the clear. The send path's check that the clear landed now uses the same reader, so a dim placeholder no longer counts as leftover text.
Codex commands. A Codex slash command typed in chat now empties a seeded multi-line draft first, as mobile already does.
Burst size.AGENT_TUI_CLEAR_MAX_LINES drops from 40 to 15. Claude Code 2.1.314 drops any single input chunk of 64 bytes or more (I measured 63 bytes kept, 64 dropped). On main, the 79 + 79-byte widening burst left blank lines in the input and the Enter never submitted. A hidden dev build showed this on every fresh session, because the old check counted the placeholder as leftover text. The launch-draft mirror limit keeps main's 40 lines through its own constant.
Why
Reusing the launch-draft lifecycle brings composer adoption, the full-line clear with its confirmation, split-pane gating and mobile delivery (text and createdAt, no wire change) for free. The alternative was a second draft state machine.
Clearing the terminal line when switching views would edit the agent's input from a view toggle. A notice instead of the text would need new UI and still has to replace the line on send.
The burst cap and the typed-only confirmation fix the existing replace path. Without them, routing more sends through that path breaks fresh Claude sessions.
Known limits:
Claude soft-wraps long input with cursor moves, so a wrapped line reads as a line break.
Desktop sends clear up to 30 lines (a 15-line burst plus one confirmed burst).
A dialog covering the prompt when you return leaves the seed until the next read.
Hidden dev builds of origin/main (before) and this branch (after), real Claude Code 2.1.314, driven over CDP.
One-line draft left in the terminal, then switched to chat view
Terminal
Before: chat composer
After: chat composer
3-line draft with the cursor on line 2, then Reply with just the word OK. sent from chat
Terminal
Before: what Claude received
After: composer
After: what Claude received
Testing
Real Claude Code 2.1.314, macOS:
PTY harness: reproduced the drop, the glue and the 64-byte paste threshold.
Hidden dev builds over CDP, before and after: one-line and 3-line drafts (cursor moved up) on fresh sessions, plus re-entry after an edit. The send log shows a single 34- or 42-byte clear and no widening burst.
Focused tests: pickup plan and hook, adoption (append, swap, dedup, strip, no transcript resolution), the typed-only reader (suggestion rows, placeholder-like text, indentation, scrolled viewport), the send confirmation and the burst size. Each new regression test failed on the old code.
Changed-file code-quality and React Doctor gates pass. CI covers typecheck and the full suite.
Linux and Windows not tested by hand. Nothing here is platform-specific.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Risk
The riskiest part is the send path that clears the agent's input line before writing the chat message. If the clear misreads the terminal, a send could leave stale text in front of the message or wait for a clear that never shows. It only runs when the terminal holds unsent input; an empty line takes the old path. Renderer-only, so no saved data, paired phones or SSH servers are affected. A plain revert backs it out.
Level: Medium
AI Disclosure
Review
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
To try, in a dev build of /Users/kelvinamoaba/orca/workspaces/orca/sta-10855-terminal-draft-chat:
In a Claude terminal tab, type two lines (a backslash then Enter makes a new line) without sending. Pick "Switch to chat view" from the pane's right-click menu: the composer shows both lines.
Send Reply with just the word OK. from chat. Claude gets exactly that, and the terminal input is empty.
Type A in chat, switch to terminal, type B, switch back. The composer shows A with B on the line below.
SSH / paired runtimes: the renderer reads its own xterm mirror, so remote panes behave like local ones. Terminal seeds never resolve by a remote clock.
Mobile:
A desktop pickup reaches the phone over the existing launch-draft wire, and mobile's clear is now bounded under Claude's paste size too.
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
No actionable comments were generated in the recent review.
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: f5107d05-6160-4f49-be3a-bbe275391dbc
Commits
Reviewing files that changed from the base of the PR and between 4177419 and e40cea0.
Files selected for processing: 2
src/shared/terminal-composer-draft.test.ts
src/shared/terminal-composer-draft.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Walkthrough
The change reads typed text from an agent’s terminal composer and passes it into native chat. Native chat can seed and adopt that text as a draft, update it when the terminal text changes, and resolve terminal-origin drafts. Draft sends now check the terminal input line, and typed command sends can clear existing input before typing. Cursor context bounds and typed-text detection are updated, with tests covering extraction, draft handling, and sends.
Severity of issue fixed: Medium
Merge Risk: Moderate · up to e40ce
Long multiline terminal drafts may not be fully replaced when sent from chat, leaving stale input behind; this should be fixed before merging.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 38.89% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title names the main change: the chat composer now shows a terminal's unsent input and sending replaces it. The changeset matches this. It adds terminal draft pickup, a typed-only composer reader,…
Description check
The description follows the repository template closely. It has ELI5, What Changed (before and after plus mechanism), Why with alternatives, Linked Issue (Fixes #29775), Visual Proof with before/after…
Linked Issues check
Issue #29775 requires terminal input to appear in the chat composer and requires chat send to replace the full terminal draft. useNativeChatTerminalDraftPickup seeds readable TUI text as a terminal-…
Out of Scope Changes check
The production changes support issue #29775. They implement terminal draft pickup, multiline typed-text reading, composer adoption, stale-seed retirement, full-input clearing, send confirmation, and b…
Full details: Title check
Explanation
The title names the main change: the chat composer now shows a terminal's unsent input and sending replaces it. The changeset matches this. It adds terminal draft pickup, a typed-only composer reader, and replace-on-send clearing. The title uses the conventional fix(native-chat) prefix and stays under 100 characters, though it is somewhat long.
Full details: Description check
Explanation
The description follows the repository template closely. It has ELI5, What Changed (before and after plus mechanism), Why with alternatives, Linked Issue (Fixes #29775), Visual Proof with before/after media, Testing with platforms, Risk with level and revert path, Agent skill boundary, Notes, and a checklist. The Linked Issue section is complete. The AI Disclosure and Review headings are empty. Some checklist items are unchecked, including the lint/typecheck/test/build item, and the 'Review' heading has no content. The author's own content is detailed and specific.
Full details: Linked Issues check
Explanation
Issue #29775 requires terminal input to appear in the chat composer and requires chat send to replace the full terminal draft. useNativeChatTerminalDraftPickup seeds readable TUI text as a terminal-origin launch draft and resolves edits or terminal clears. resolveNativeChatLaunchDraftSend builds a full-line clear and confirms clearance with readTerminalComposerTypedText, which ignores dim suggestions and placeholders. Focused tests cover pickup, adoption, typed-only reads, send confirmation, and clear limits. The related mobile issue #22382 is not a requirement for this PR.
Full details: Out of Scope Changes check
Explanation
The production changes support issue #29775. They implement terminal draft pickup, multiline typed-text reading, composer adoption, stale-seed retirement, full-input clearing, send confirmation, and bounded clear bursts. The Codex command clearing change supports the same seeded-draft send path. The added exports and tests support these behaviors. No changed area has a demonstrated unrelated purpose.
Full details: Docstring Coverage
Explanation
Docstring coverage is 38.89% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 18 functions across 28 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
/** Mirror launch context only if TUI input can be cleared within the same budget. CR/LF fit the bound; Unicode separators/over-budget drafts stay terminal-only. */
/** Longest draft mirrored into chat; a send past the 15-line clear burst relies on the desktop's confirmed second burst. */
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Supported by static analysis
Script executed:
#!/bin/bash# Check which send paths clear a mirrored draft, and whether each has a confirmed second burst.
rg -nP --type=ts -C3 '\bcanMirrorLaunchDraftToNativeChat\s*\(' -g '!**/*.test.*'
rg -nP --type=ts -C3 '\b(buildAgentTuiClearInputForText|buildAgentTuiClearInput|AGENT_TUI_CLEAR_INPUT_MAX)\b' -g '!**/*.test.*'
rg -nP -C3 '\bconfirmCleared\b' mobile src -g '!**/*.test.*'
#!/bin/bashset -e
nl -ba mobile/src/session/native-chat/mobile-native-chat-send.ts | sed -n '108,160p'
Repository: stablyai/orca
Length of output: 1815
Limit mirrored drafts to one clear burst.
canMirrorLaunchDraftToNativeChat is shared by desktop and mobile. Each clear burst is capped at 15 logical lines. The desktop path can issue a confirmed second burst, but the mobile path sends only one burst. A 31–40-line draft can leave terminal residue before the new message is written.
Use AGENT_TUI_CLEAR_MAX_LINES and update the boundary test from 41 to 16 lines.
♻️ Suggested fix
-import { countAgentTuiInputLines } from '../../agent-tui-input-clear'+import {+ AGENT_TUI_CLEAR_MAX_LINES,+ countAgentTuiInputLines+} from '../../agent-tui-input-clear'-/** Longest draft mirrored into chat; a send past the 15-line clear burst relies on the desktop's confirmed second burst. */-const LAUNCH_DRAFT_MIRROR_MAX_LINES = 40+/** Longest draft mirrored into chat; every send path can clear one 15-line burst. */+const LAUNCH_DRAFT_MIRROR_MAX_LINES = AGENT_TUI_CLEAR_MAX_LINES
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
Major · Typed Codex slash commands clear only one line of… · use-native-chat-pty-composer-send.ts:102-119
src/renderer/src/components/native-chat/use-native-chat-pty-composer-send.ts:102-119 Major · Functional Correctness · Heavy lift
Typed Codex slash commands clear only one line of a seeded multi-line draft.
The Codex slash-command branch calls sendNativeChatTypedCommand(target.ptyId, text) without the launch-draft send options. That helper types the command through typeAgentTuiCommand, which starts with one Ctrl-U (AGENT_TUI_CLEAR_INPUT_LINE). Ctrl-U clears only one logical line. If the seeded terminal draft spans several lines, the earlier lines remain in the agent input. The command is then typed after them, and Enter can submit the leftover draft together with the command.
The other send branches clear with the seeded text (buildAgentTuiClearInputForText(seededText)). The mobile send path does the same for typed Codex commands. The desktop typed branch does not.
Correction: pass the seeded clear sequence (sendOptions.clearInput) into the typed-command path, and have it write that sequence before the command. Keep the single Ctrl-U when no seed is active.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 16d49d91-0ace-493c-8ae7-7226c1d5ff06
Commits
Reviewing files that changed from the base of the PR and between a20b8e8 and 4cfd736.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
… and replace it on send
Switching a pane to chat view now seeds the composer with the text left unsent in Claude Code's or Codex's input box, and a chat send clears every line of it instead of one Ctrl+U. The clear is confirmed with the same typed-only read and kept under the 64-byte chunk Claude Code reads as a paste.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Before this change, if you typed something into Claude's input box in terminal view and then switched to chat view, the chat box was empty. The next message you sent from chat then deleted your terminal text, or mixed part of it into your message. Now the chat box shows the text that's waiting in the terminal. Sending replaces it cleanly.
What Changed
Before, on Claude Code 2.1.314 (the same result on main through a real PTY and in a hidden dev build):
please look at the flaky retry testin the terminal and switch to chat view: the composer is empty.alpha line\nReply with just the word OK.wo\ngamma three.After:
Mechanism:
readTerminalComposerTypedTextreads only the undimmed text on the agent's input line. It returns''when the prompt is empty, even with a dim placeholder or suggestion showing, andnullwhen no composer is visible. It keeps the user's indentation on continuation lines and reads from the live screen, so a scrolled-back terminal is read whole.useNativeChatTerminalDraftPickupreads that line once. It seeds the text as the tab'sNativeChatLaunchDraftwithfromTerminal: true, so the existing adoption and replace-on-send paths take over. The seed is skipped in these cases:AGENT_TUI_CLEAR_MAX_LINESdrops from 40 to 15. Claude Code 2.1.314 drops any single input chunk of 64 bytes or more (I measured 63 bytes kept, 64 dropped). On main, the 79 + 79-byte widening burst left blank lines in the input and the Enter never submitted. A hidden dev build showed this on every fresh session, because the old check counted the placeholder as leftover text. The launch-draft mirror limit keeps main's 40 lines through its own constant.Why
Known limits:
Linked Issue
Fixes #29775
Linear: STA-10855
Visual Proof
Hidden dev builds of
origin/main(before) and this branch (after), real Claude Code 2.1.314, driven over CDP.One-line draft left in the terminal, then switched to chat view
3-line draft with the cursor on line 2, then
Reply with just the word OK.sent from chatTesting
Real Claude Code 2.1.314, macOS:
Focused tests: pickup plan and hook, adoption (append, swap, dedup, strip, no transcript resolution), the typed-only reader (suggestion rows, placeholder-like text, indentation, scrolled viewport), the send confirmation and the burst size. Each new regression test failed on the old code.
Changed-file code-quality and React Doctor gates pass. CI covers typecheck and the full suite.
Linux and Windows not tested by hand. Nothing here is platform-specific.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Risk
The riskiest part is the send path that clears the agent's input line before writing the chat message. If the clear misreads the terminal, a send could leave stale text in front of the message or wait for a clear that never shows. It only runs when the terminal holds unsent input; an empty line takes the old path. Renderer-only, so no saved data, paired phones or SSH servers are affected. A plain revert backs it out.
Level: Medium
AI Disclosure
Review
Agent skill upstream boundary
Notes
To try, in a dev build of
/Users/kelvinamoaba/orca/workspaces/orca/sta-10855-terminal-draft-chat:Reply with just the word OK.from chat. Claude gets exactly that, and the terminal input is empty.Ain chat, switch to terminal, typeB, switch back. The composer showsAwithBon the line below.SSH / paired runtimes: the renderer reads its own xterm mirror, so remote panes behave like local ones. Terminal seeds never resolve by a remote clock.
Mobile:
Folder workspaces: nothing here depends on git.
Cross-platform: nothing platform-specific.
Follow-ups:
orca terminal read.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)