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:

  1. Node.js readline module (which Claude Code uses)
  2. Your shell’s terminal settings

Configure your shell to ignore Ctrl+D, requiring multiple consecutive presses before exit.

For Bash

Add to ~/.bashrc or ~/.bash_profile:

Terminal window
# Require 10 Ctrl+D presses to exit (default if just set to any value)
export IGNOREEOF=10
# Or require 3 Ctrl+D presses
export IGNOREEOF=3

Alternative bash syntax:

Terminal window
set -o ignoreeof

How 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:

Terminal window
# Ignore Ctrl+D on empty lines
setopt ignoreeof

Behavior:

  • When you press Ctrl+D, you get: “zsh: use ‘exit’ to exit.”
  • Prevents accidental exits completely (no numeric limit like bash)
  • Must type exit explicitly to quit

For Ksh

Terminal window
set -o ignoreeof

Behavior:

  • 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:

Terminal window
export IGNOREEOF=10

This 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:

ShortcutFunctionWorks In
Delete or Fn+BackspaceDelete character forwardAll terminals
Ctrl+KDelete from cursor to end of lineClaude Code, most shells
Ctrl+UDelete entire line (before cursor)Most shells, bash/zsh
Ctrl+WDelete word backwardMost shells
Ctrl+HBackspace (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:

Terminal window
/vim

Or configure permanently via /config.

In NORMAL mode:

  • x - Delete character under cursor
  • dw - Delete word
  • dd - Delete line
  • D - 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+D
rl.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:

  1. Terminal-level remapping - Use terminal emulator settings to remap Ctrl+D to a different key
  2. Custom wrapper script - Launch Claude Code through a script that handles raw terminal input
  3. Feature request - Request Claude Code to add a --ignore-eof flag 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:

ShortcutFunction
Ctrl+CCancel current operation
Ctrl+DExit Claude Code
Ctrl+LClear terminal screen
Esc + EscEdit previous message
Ctrl+YPaste deleted text (readline-style)
Ctrl+_Undo (matches zsh convention)
TabAuto-complete
Up/DownNavigate command history

Feature Request Option

If IGNOREEOF doesn’t solve your problem, consider filing a GitHub issue requesting:

Proposed Feature:

  • Add --ignore-eof CLI flag or config option
  • Add ignoreEOF setting 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 - Allow configurable mode cycling (keyboard shortcuts)
  • Issue - Terminal input handling breaks keyboard shortcuts on macOS

No specific issue exists yet for Ctrl+D configuration.

  1. Try shell IGNOREEOF first - Add to ~/.bashrc or ~/.zshrc
  2. Test if it works - Launch Claude Code and try Ctrl+D
  3. If ineffective - Use alternative deletion shortcuts (Delete key, Ctrl+K)
  4. Consider Vim mode - If you’re comfortable with modal editing
  5. File feature request - If this is a dealbreaker, request built-in support

Sources

Claude Code Documentation

Shell IGNOREEOF Configuration

Node.js Readline Technical Details