[BUG] Terminal Paste Corruption from Bracketed Paste Mode
Open 💬 23 comments Opened Jul 8, 2025 by jason-riddle
Summary
Launching and exiting Claude Code corrupts terminal paste functionality. All subsequent paste operations are prefixed with 00~ and suffixed with 01~.
Environment
- OS: macOS - Sequoia 15.5
- Terminal: Terminal.app 2.14
- Claude Code Version: 1.0.44
- Shell: bash 5.2.37
Reproduction
- Open fresh terminal
- Verify paste works normally
- Run
claude - Exit immediately (no commands)
- Copy/paste any text
Expected vs Actual
Expected: adding-mcp-to-your-python-project
Actual: 00~adding-mcp-to-your-python-project01~
Workarounds
resetprintf '\e[?2004l'- Restart terminal
Technical Details
Claude Code leaves terminal in corrupted bracketed paste mode. The 00~/01~ characters are escape sequences (\e[200~/\e[201~) being displayed instead of processed.
Impact
- Frequency: 100% reproducible
- Trigger: Every Claude Code launch/exit
- Effect: Breaks all terminal paste until manual reset
Root Cause
Claude Code likely enables bracketed paste mode (\e[?2004h) but fails to disable it (\e[?2004l) on exit.
Related
Related:
- https://gitlab.com/gnachman/iterm2/-/issues/7908
- https://jdhao.github.io/2021/02/01/bracketed_paste_mode/
Environment Info
- Platform: darwin
- Terminal: Apple_Terminal
- Version: 1.0.44
- Feedback ID: b21fac8e-2c0a-4d59-b6a5-9ef693b97ece
Errors
[{"error":"Error: Command failed: security find-generic-password -a $USER -w -s \"Claude Code\"\nsecurity: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.\n\n at genericNodeError (node:internal/errors:983:15)\n at wrappedFn (node:internal/errors:537:14)\n at checkExecSyncError (node:child_process:892:11)\n at execSync (node:child_process:964:15)\n at wD (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:702:3921)\n at file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:623:9350\n at Q (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:526:13327)\n at uC (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:623:8496)\n at hC (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:623:7361)\n at wB (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:623:11970)","timestamp":"2025-07-08T05:52:40.983Z"},{"error":"SyntaxError: Unexpected token '/', \"/usr/local\"... is not valid JSON\n at JSON.parse (<anonymous>)\n at file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:618:9971\n at Q (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:526:13327)\n at gQA.<anonymous> (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:2586:111)\n at gQA.B [as _actionHandler] (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:516:528)\n at file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:520:3127\n at gQA._chainOrCall (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:520:1694)\n at gQA._parseCommand (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:520:3103)\n at gQA.parseAsync (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:517:4195)\n at Cv6 (file:///Users/jason/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:2598:1217)","timestamp":"2025-07-08T05:52:41.063Z"}]
23 Comments
Same here
Dup of #3007 ? FWIW you can temporarily fix this by typing this into the shell
Might want to add that as an alias...
Same here!
Here's how to use @jscalo's workaround automatically.
In your
.bashrcput:@thomasnormal This little function is awesome, thanks! Totally fixed it on my end.
I'm experiencing similar bracketed paste mode issues in v2.0.59 when using voice-to-text accessibility software (Handy).
The terminal scrollback clearly shows
[201~(the paste END marker) appearing raw in the input prompt, indicating the bracketed paste sequence isn't being properly consumed. After several paste attempts, the CLI hangs permanently and requireskill -9.Documented with timestamps and process diagnostics in #13183.
This also affects PowerShell Core in Ghostty. It has a slightly different effect than the original report above. It prefixes the pasted text with
200~(instead of00~) and suffixes it with201~(instead of01~).i.e. pasting in the URL to this issue after exiting Claude Code:
Version info:
Issues in iTerm too. This is extremely annoying. The alias fixes it, but sheesh this needs to be fixed.
After modifying .bashrc didn't work, I turned on cursor's settings: Integrated: Ignore Bracketed Paste Mode,successfully solved the problem!
This issue is still happening with Claude Code v2.0.76.
The fix should be straightforward:
@archer-eric I was able to resolve the issue by using the suggested alias here. You might as well save yourself the headache of waiting for this issue to get resolved.
I had my own bash function that did something similar, but it keeps getting in the way of Claude Code itself believing that it should be an alias instead of a function. I think it sometimes interferes with automatic upgrades (which seems to keep changing in approach).
It would be fantastic if Anthropic could simply restore the setting that Claude Code is currently changing while it runs.
Heads up for anyone else finding this before it’s fixed: this hook will clear bracketed paste mode on exit:
As far as I can tell, this appears to have been fixed in or before Claude Code 2.1.4 (running Ubuntu 24.04.3 LTS).
Can anybody else confirm?
I don't see anything related in recent
/release-notes.version 2.1.14 - has no issues (using till the fix rollout), 2.1.16 introduced this issue (could be 2.1.15 - didn't had 2.1.15, can't confirm).
@benjaminjackson fix didn't seem to work on my setup: WSL 2 Linux Debian.
For me, the problem exists only in the terminal in the Cursor code editor. For the native Mac terminal, pasting even long texts works fine.
Cross-posting: Paste truncation is STILL broken — 24 issues, 8 months, zero staff responses
This bracketed paste bug is part of a family of 5 distinct paste-handling failures in the Ink TUI, all unfixed after 8 months. I've documented the full scope on #5017 including:
The bracketed paste mode corruption you reported in July 2025 — 8 months ago — is still happening. The
\e[?2004h/\e[?2004llifecycle management in the Ink TUI has never been fixed.Every user's terminal is left in a corrupted state after Claude Code exits, and every paste operation silently loses content. This is a data integrity crisis that Anthropic has completely ignored.
See #5017 for the full analysis.
Cursor 2.6.19 integrated terminal: paste freeze persists despite all known workarounds
Adding data from extensive debugging on Cursor's integrated terminal.
Environment
What I tried (all failed to fix the freeze)
ignoreBracketedPasteMode: false(confirmed)printf '\e[?2004l'wrapper in.zshrc+ SessionEnd hookterminal.integrated.enablePersistentSessions: false+persistentSessionScrollback: 0terminal.integrated.scrollback: 500ENABLE_IDE_INTEGRATION=false, unsettingCLAUDE_CODE_SSE_PORTandVSCODE_INJECTIONterminalProgressBarEnabled: false,prefersReducedMotion: true,spinnerTipsEnabled: falseKey finding: Claude Code process is NOT frozen
Stack sampling (
sample <pid> 3) during freeze shows:kevent64— the Claude Code Node.js process is idle, waiting for eventsStreamBase::Write— occasional write attemptsstty -aon the frozen terminal's tty shows raw mode is active (-icanon -isig -iexten -echo), which is expected for an Ink TUI app.ptyhost.log before persistent sessions were disabled
After disabling persistent sessions, this log entry disappeared but the freeze remained.
Conclusion
This is not a bracketed paste mode restoration issue in the Cursor case. The freeze happens during paste, not after exit. The Claude Code process itself stays responsive — the bottleneck is Cursor's PTY/xterm.js layer choking on the paste input volume.
Cursor's repo has issues disabled, so this can only be tracked here. Likely related to their bundled node-pty 1.1.0-beta42 and xterm 5.6.0-beta.99.
Same terminal, same paste content works fine in VS Code, iTerm2, and Terminal.app.
If you're still hitting this, VoiceInput-Patch can help as a workaround. It's a macOS menu bar app that intercepts Cmd+V in terminals and re-types clipboard content char-by-char via CGEvent Unicode key events — the terminal receives keyboard input instead of a paste, so bracket paste mode is never triggered.
Reproducing on SSH + tmux + voice-to-text (OpenWhispr)
Environment:
extended-keys on(CSI u protocol)Symptoms:
201~residue (bracketed paste end-marker)lnextresets parser state)[?2004lleaks into prompt text when disable-code is sent externallyAnalysis:
The TUI enables bracketed paste (
ESC[?2004h) but the parser gets stuck waiting for the end-marker, especially when:extended-keys onis active (CSI u sequences compete with bracketed paste CSI sequences in the same buffer)set-titles on)Disabling
xterm-keys on(which conflicts withextended-keys on) reduced frequency but did not eliminate the issue. Externalprintf '\e[?2004l'is ineffective because the TUI re-enables bracketed paste mode.Workaround: ESC ESC to break the stuck parser. The previously entered/dictated text is preserved in the prompt — it does not need to be re-entered. The only cleanup needed is removing the trailing
201~residue (bracketed paste end-marker) before submitting.Related: #13183 (voice-to-text accessibility tools), #43169 (tmux extended-keys + paste)
New data point: OSC 10 foreground color query response leaking into input buffer
Observing a related symptom: the string
10;rgb:cccc/cccc/ccccoccasionally appears as literal text in the Claude Code input buffer.This is an OSC 10 response — the terminal reporting its current foreground color in reply to a
\e]10;?\aquery. The TUI parser does not consume this escape sequence response, so it leaks into the text input as visible characters.This appears to be the same root cause family as the Bracketed Paste Mode
201~residue previously reported in this issue — terminal escape sequence responses that arrive asynchronously and are not recognized/consumed by the TUI input parser.Environment:
Frequency: Occasional. Reduced after adding
automatic-rename offandxterm-keys offto tmux.conf (which reduces the number of terminal queries tmux issues), but not eliminated. The underlying issue is that the TUI parser doesn't handle OSC responses arriving in the input stream.01~ and more hex characters appear
upvote
Environment:
Symptom: pasting multi-line text into Claude Code inside tmux (
extended-keys on) doesn't just drop newlines, each one is replaced with a literalj. Pasting in Claude Code outside of tmux, there is no issue.For example when pasting some python code:
Isolating it:
wl-pasteshows the clipboard itself has correct\nbytes.tmux paste-buffer -pstraight into a freshclaudeinstance comes through clean, so the corruption happens in Claude Code's own paste handling, not the terminal/clipboard.extended-keys off(+tmux kill-server, since a liveset-optiondoesn't clear tmux's cached capability negotiation) fixes it.csi-u-specific:extended-keys onwithextended-keys-format xtermreproduces the same corruption. So the trigger isextended-keysbeing on at all, not the wire format.The catch:
extended-keys onis also required for tmux to relay the CSI-u sequence my terminal sends for Shift+Enter. This means I either setextended-keys onto make Shift+Enter work, or I remove it to make user text is pasted properly.