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.
| Tool | New line without sending | Notes |
|---|---|---|
| Codex CLI | Ctrl + J | The terminal-safe default. Shift + Enter is also bound but unreliable. |
| Claude Code | Shift + Enter | Or \ then Enter, which works in any terminal. |
| Gemini CLI | Ctrl + J | Inserts a newline without submitting. |
| opencode | Shift + Enter | Or Ctrl + J as the fallback. |
| Cursor CLI | Shift + Enter | Or Ctrl + J (useful under tmux). |
| Qwen Code | Shift + Enter | Or Ctrl + J. |
| Aider | Alt + Enter | Or wrap the message in { … }, or flip default behavior with /multiline-mode. |
| Grok Build | /multiline | xAI 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.
| Tool | Interrupt the task | Notes |
|---|---|---|
| Codex CLI | Esc | Interrupts the active task. (Ctrl + C here exits instead.) |
| Claude Code | Esc | Cancels the current request or input. Ctrl + C also interrupts. |
| Gemini CLI | Esc | Cancels the operation / dismisses a dialog. |
| opencode | Esc | Interrupts the running model. |
| Qwen Code | Ctrl + C | Cancels the request / clears input; press again (or on an empty line) to exit. |
| Aider | Ctrl + C | Interrupts 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.
| Tool | Exit key | Slash command |
|---|---|---|
| Codex CLI | Ctrl + C | /quit or /exit |
| Claude Code | Ctrl + D | /exit |
| Gemini CLI | Ctrl + D (empty input) | /quit |
| opencode | Ctrl + C · Ctrl + X then Q | — |
| Cursor CLI | Ctrl + D (twice) | — |
| Qwen Code | Ctrl + C or Ctrl + D (twice) | /quit |
| Aider | Ctrl + 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
/quitor/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.