disable-ctrl-d-exit
Problem Statement
When using Claude Code CLI, pressing Ctrl+D sends an EOF (End-Of-File) signal that exits the session. Users who want to use Ctrl+D for text deletion (common in editors like Emacs) may accidentally trigger exits multiple times.
Current Behavior:
- Single Ctrl+D on empty line → Claude Code attempts to exit
- Multiple consecutive Ctrl+D presses → Claude Code exits completely
Key Finding: No Built-in Claude Code Option
Claude Code CLI does not have a built-in configuration option to disable or remap Ctrl+D. The behavior is inherited from:
- Node.js readline module (which Claude Code uses)
- Your shell’s terminal settings
Solution 1: Shell-Level IGNOREEOF (Recommended)
Configure your shell to ignore Ctrl+D, requiring multiple consecutive presses before exit.
For Bash
Add to ~/.bashrc or ~/.bash_profile:
# Require 10 Ctrl+D presses to exit (default if just set to any value)export IGNOREEOF=10
# Or require 3 Ctrl+D pressesexport IGNOREEOF=3Alternative bash syntax:
set -o ignoreeofHow it works:
- When set, bash ignores the first N consecutive Ctrl+D characters
- Displays warning: “Use ‘exit’ to exit.” after each ignored Ctrl+D
- After N+1 presses, the shell exits
For Zsh
Add to ~/.zshrc:
# Ignore Ctrl+D on empty linessetopt ignoreeofBehavior:
- When you press Ctrl+D, you get: “zsh: use ‘exit’ to exit.”
- Prevents accidental exits completely (no numeric limit like bash)
- Must type
exitexplicitly to quit
For Ksh
set -o ignoreeofBehavior:
- Ignores Ctrl+D for 20 times (ksh93)
- Ignores Ctrl+D for 11 times (older ksh)
- No user-configurable limit (unlike bash IGNOREEOF)
Shell-Agnostic Approach
Put in ~/.profile for any Bourne-compatible login shell:
export IGNOREEOF=10This works across bash, dash, and other POSIX shells.
Solution 2: Alternative Text Deletion Shortcuts
Since Ctrl+D is reserved for EOF, use these alternatives for deleting text:
| Shortcut | Function | Works In |
|---|---|---|
| Delete or Fn+Backspace | Delete character forward | All terminals |
| Ctrl+K | Delete from cursor to end of line | Claude Code, most shells |
| Ctrl+U | Delete entire line (before cursor) | Most shells, bash/zsh |
| Ctrl+W | Delete word backward | Most shells |
| Ctrl+H | Backspace (delete backward) | Most terminals |
Note: Claude Code updated Ctrl+U behavior and moved undo to Ctrl+_ to match zsh conventions.
Solution 3: Vim Mode (If You Prefer Vi/Vim Keybindings)
Enable Vim mode in Claude Code for modal editing:
/vimOr configure permanently via /config.
In NORMAL mode:
x- Delete character under cursordw- Delete worddd- Delete lineD- Delete to end of line
This avoids Ctrl+D entirely by using vi-style deletion.
Understanding the Technical Details
Why Ctrl+D Exits
Ctrl+D sends an EOT (End-Of-Transmission) character:
- ASCII: 004 (decimal), 0x04 (hex)
- When shells/CLIs see EOF on an empty line, they interpret it as “no more input coming”
- This is standard Unix/Linux terminal behavior, not specific to Claude Code
Node.js Readline Behavior
Claude Code CLI is built with Node.js and uses the readline module:
// Node.js readline emits 'close' event on Ctrl+Drl.on('close', () => { // readline interface is finished, app exits});Key facts:
- Node.js readline has no built-in option to ignore EOF/Ctrl+D
- The
'close'event fires when input stream receives EOF - Once the interface receives EOF, it’s considered “finished”
Why shell IGNOREEOF helps:
- Shell-level IGNOREEOF prevents EOF from reaching the readline interface
- The shell intercepts Ctrl+D before Node.js sees it
- Only works if shell properly wraps the EOF signal
Potential Workarounds (Advanced)
If shell-level IGNOREEOF doesn’t work for your setup:
- Terminal-level remapping - Use terminal emulator settings to remap Ctrl+D to a different key
- Custom wrapper script - Launch Claude Code through a script that handles raw terminal input
- Feature request - Request Claude Code to add a
--ignore-eofflag or config option
Known Limitations
IGNOREEOF May Not Always Work
Shell IGNOREEOF settings may not prevent Ctrl+D from exiting Claude Code because:
- Node.js readline reads directly from
process.stdin - If the shell doesn’t intercept EOF before passing it to child processes, readline still receives it
- Behavior varies by shell, terminal emulator, and OS
Testing required:
- Try IGNOREEOF settings in your specific shell + terminal combination
- Test whether Claude Code still exits on Ctrl+D after configuration
- If it doesn’t work, consider using alternative shortcuts or filing a feature request
Claude Code Keyboard Shortcuts (Built-in)
Current Claude Code shortcuts that cannot be remapped:
| Shortcut | Function |
|---|---|
| Ctrl+C | Cancel current operation |
| Ctrl+D | Exit Claude Code |
| Ctrl+L | Clear terminal screen |
| Esc + Esc | Edit previous message |
| Ctrl+Y | Paste deleted text (readline-style) |
| Ctrl+_ | Undo (matches zsh convention) |
| Tab | Auto-complete |
| Up/Down | Navigate command history |
Feature Request Option
If IGNOREEOF doesn’t solve your problem, consider filing a GitHub issue requesting:
Proposed Feature:
- Add
--ignore-eofCLI flag or config option - Add
ignoreEOFsetting to~/.claude/settings.json - Allow Ctrl+D to delete forward character instead of exit
Example config proposal:
{ "terminal": { "ignoreEOF": true, "eofExitCount": 3 }}Related Issues:
- Issue #8292 - Allow configurable mode cycling (keyboard shortcuts)
- Issue #5196 - Terminal input handling breaks keyboard shortcuts on macOS
No specific issue exists yet for Ctrl+D configuration.
Recommended Approach
- Try shell IGNOREEOF first - Add to
~/.bashrcor~/.zshrc - Test if it works - Launch Claude Code and try Ctrl+D
- If ineffective - Use alternative deletion shortcuts (Delete key, Ctrl+K)
- Consider Vim mode - If you’re comfortable with modal editing
- File feature request - If this is a dealbreaker, request built-in support
Sources
Claude Code Documentation
- Optimize your terminal setup - Claude Code Docs
- Interactive mode - Claude Code Docs
- The Ultimate Claude Code Cheat Sheet | Medium
- Claude Code Developer Cheatsheet
Shell IGNOREEOF Configuration
- The UNIX School: $IGNOREEOF vs ignoreeof
- Stop Accidental C Shell Logouts
- Zsh IGNORE_EOF mailing list