New Line, Interrupt, and Exit in AI Coding CLIs

Terminal AI coding agents — Claude Code, Codex CLI, Gemini CLI, and the rest — share most of their keyboard layout. But three everyday actions are stubbornly inconsistent across them, and they're the ones you reach for constantly: writing a multi-line prompt without firing it off early, interrupting the agent mid-task, and exiting the tool. Guess wrong and you either send a half-finished message, can't stop a runaway edit, or accidentally quit the whole session.

This guide puts all three side by side, tool by tool. Every key here is drawn from each tool's own reference page — links to the full cheat sheets are at the bottom.

The Ctrl+C trap (read this first)

Ctrl + C does not mean the same thing everywhere, and that's the single biggest source of confusion. In Codex CLI a single Ctrl + C exits the whole session immediately. In Claude Code, Aider, and Qwen Code it interrupts the current task and you stay in the session — you need a second press (or an empty input line) to actually quit. So the muscle memory you build in one tool can drop you out of another. When you just want to stop what the agent is doing, Esc is the safer universal choice in most of these tools.

Add a new line without sending

By default Enter submits your prompt in every one of these tools. To write a multi-line message you need the newline key — and here's the catch: many terminals can't tell Shift + Enter apart from plain Enter. That's why several tools bind Ctrl + J (a real, distinct control character) as the reliable fallback. If Shift + Enter seems to do nothing, reach for Ctrl + J.

ToolNew line without sendingNotes
Codex CLICtrl + JThe terminal-safe default. Shift + Enter is also bound but unreliable.
Claude CodeShift + EnterOr \ then Enter, which works in any terminal.
Gemini CLICtrl + JInserts a newline without submitting.
opencodeShift + EnterOr Ctrl + J as the fallback.
Cursor CLIShift + EnterOr Ctrl + J (useful under tmux).
Qwen CodeShift + EnterOr Ctrl + J.
AiderAlt + EnterOr wrap the message in { … }, or flip default behavior with /multiline-mode.
Grok Build/multilinexAI documents a multiline toggle rather than a single newline key.

Interrupt a running task (stay in the session)

When the agent is off doing the wrong thing, you want to stop it without quitting. Esc is the cleanest way to do this in most of the tools; Ctrl + C works too but — per the trap above — can exit outright in some.

ToolInterrupt the taskNotes
Codex CLIEscInterrupts the active task. (Ctrl + C here exits instead.)
Claude CodeEscCancels the current request or input. Ctrl + C also interrupts.
Gemini CLIEscCancels the operation / dismisses a dialog.
opencodeEscInterrupts the running model.
Qwen CodeCtrl + CCancels the request / clears input; press again (or on an empty line) to exit.
AiderCtrl + CInterrupts Aider — the partial response is kept.

Grok Build and Cursor CLI don't publish a distinct interrupt key in their official references, so they're left off this table rather than guessed at.

Exit / quit the tool

Two reliable patterns show up everywhere: a slash command (/quit or /exit) and a control key. The control key is where they diverge — Ctrl + D is the common "exit on empty line" convention, while Codex uses Ctrl + C.

ToolExit keySlash command
Codex CLICtrl + C/quit or /exit
Claude CodeCtrl + D/exit
Gemini CLICtrl + D (empty input)/quit
opencodeCtrl + C · Ctrl + X then Q
Cursor CLICtrl + D (twice)
Qwen CodeCtrl + C or Ctrl + D (twice)/quit
AiderCtrl + C/exit
Grok Build/quit

When in doubt, type /quit or /exit — a slash command never accidentally interrupts a task, so it's the safest way to leave any of these tools cleanly.

What about the browser chat apps?

If you searched for how to go to the next line in Gemini, Perplexity, Claude, or ChatGPT, the answer is simpler: in the browser and desktop chat apps, Enter sends and Shift + Enter makes a new line — uniformly. The terminal-distinguishability problem that forces Ctrl + J in the CLIs doesn't exist in a web page, so Shift + Enter just works. To start a fresh conversation, most use Cmd/Ctrl + Shift + O (ChatGPT, Gemini, Grok), while Claude uses Cmd/Ctrl + O. See the AI chat shortcuts comparison for the full set.

The quick answer

  • New line without sending: Ctrl + J is the universal fallback; Shift + Enter works in many tools if your terminal supports it.
  • Interrupt a task: Esc in most tools (Claude Code, Codex, Gemini CLI, opencode); Ctrl + C in Aider and Qwen Code.
  • Exit: type /quit or /exit — or Ctrl + D (most) / Ctrl + C (Codex, Aider, opencode).
  • Remember the trap: Ctrl + C quits Codex but only interrupts Claude Code, Aider, and Qwen Code.