[BUG] Terminal bracketed paste mode not cleaned up on forced exit (Control+C)

Resolved 💬 2 comments Opened Dec 17, 2025 by marcodicro-dp Closed Dec 17, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When exiting Claude Code using double Control+C, the terminal is left in bracketed paste mode, causing pasted content to show escape sequence characters (00~ prefix and ~ suffix).

Environment

  • OS: macOS 15.7.2 (Sequoia)
  • Build: 24G325
  • Claude Code Version: 2.0.72
  • Terminal: Default macOS Terminal.app
  • Shell: zsh (macOS default)

Expected Behavior

Pasted content should appear as-is:
pin-action-docker-setup-buildx-action-v301

Actual Behavior

Pasted content includes bracketed paste escape sequences:
00~pin-action-docker-setup-buildx-action-v301~

Root Cause

Claude Code enables bracketed paste mode (\e[?2004h) for better paste handling but doesn't properly disable it (\e[?2004l) when receiving SIGINT. The cleanup code only runs on graceful exits, not forced terminations.

Current Workaround

Users can manually fix the terminal state after each forced exit:
printf '\e[?2004l'

Or add a wrapper function to their shell config (~/.zshrc or ~/.bashrc):
claude() {
command claude "$@"
printf '\e[?2004l' # Always disable bracketed paste after exit
}

What Should Happen?

Proposed Fix

Claude Code should register signal handlers (SIGINT, SIGTERM) that ensure terminal state cleanup happens even on forced exits. This is standard practice for CLI
applications that modify terminal modes.

Example pattern:
process.on('SIGINT', () => {
// Disable bracketed paste mode
process.stdout.write('\x1b[?2004l');
// Other cleanup
process.exit(0);
});

Error Messages/Logs

Steps to Reproduce

Steps to Reproduce

  1. Start Claude Code: claude
  2. Force exit with double Control+C
  3. Paste any text into the terminal
  4. Observe extra characters around pasted content

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.72

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Additional Context

This affects user experience every time Claude Code is force-quit, which is a common workflow when users want to quickly exit. The issue persists across terminal
sessions until manually fixed or the terminal is restarted.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗