fix(prompt): scale bracketed-paste delay by line count to prevent stuck initial prompts#107
Conversation
Root cause analysisWhen introduced: Commit The problem: Claude Code processes bracketed paste asynchronously. The CSI Result: the agent sits in The fix: Replace the fixed 50ms delay with The bracketed paste wrapping itself is preserved — Codex still needs it. Only the timing changes. |
|
Fresh code-review pass findings:
No additional actionable issues found in this fresh pass. |
…ck initial prompts When an agent enables bracketed paste mode (CSI ? 2004 h), synthetic prompt sends wrap the text in \x1b[200~...\x1b[201~ to avoid Codex's paste-burst guard. However, TUI agents like Claude Code process the paste asynchronously — if \r arrives while the paste is still being consumed, it is absorbed into the input buffer as a newline rather than submitting the prompt. The previous fixed 50ms delay was sufficient for short prompts but too short for large ones (e.g. a 31-line initial task prompt). The symptom is the agent sitting in INSERT mode with "[Pasted text #1 +N lines]" in its input, never sending. Fix: - Track bracketed paste mode (CSI ? 2004 h/l) in AgentTrackingState via updateBracketedPasteMode(), called on each PTY data chunk in markAgentOutput() - Export isAgentBracketedPasteEnabled() so sendPrompt can conditionally wrap - Scale the pre-Enter delay: max(50ms, lines * 15ms), capped at 500ms — a 31-line prompt now waits ~465ms instead of 50ms Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…cate constants Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
08426ee to
4572e29
Compare
Updates addressing review feedbackRebased onto current main — resolved two conflicts:
Added
All 437 tests pass, typecheck and lint clean. |
|
Thank you very much! <3 |
Summary
?2004h/l) per agent inAgentTrackingStateviaupdateBracketedPasteMode(), called on each PTY data chunkisAgentBracketedPasteEnabled()sosendPromptcan conditionally wrap text in\x1b[200~...\x1b[201~(matches what Codex expects to avoid its paste-burst guard)pasteDelayMs(text):max(50ms, lines × 15ms)capped at 500msProblem
When an agent enables bracketed paste mode, synthetic prompt sends wrap the text in
\x1b[200~...\x1b[201~. TUI agents like Claude Code process this paste asynchronously — if\rarrives while the paste is still being consumed (within the fixed 50ms window), it is absorbed into the input buffer as a newline rather than submitting the prompt.The symptom: the agent sits in
-- INSERT --mode showing[Pasted text #1 +N lines], waiting indefinitely for Enter. Reproduces reliably with initial task prompts of 30+ lines.Test plan
🤖 Generated with Claude Code