TL;DR
The Codex CLI runs almost entirely from the keyboard. The keys you actually reach for every day: Esc interrupts a running turn, Ctrl+J inserts a newline that survives any terminal, Ctrl+G opens your $EDITOR for a long prompt, Ctrl+R searches your prompt history, Esc Esc rewinds to edit an earlier message, and Shift+Tab cycles approval modes (Read-only, Auto, Full Access). When in doubt inside a live session, type /keymap to print the bindings your installed build actually ships.
Version note (as of June 2026): this guide is written against Codex CLI v0.135.x, the line OpenAI shipped through May 2026. Codex iterates fast and a few bindings are version-gated (noted below), so
/keymapin your session is always the final word.
Who this is for
- Developers who run
codexdaily and want to stop editing long prompts one character at a time. - People who write multi-paragraph specs and keep accidentally submitting them half-finished.
- Anyone running long agent tasks who needs to interrupt, redirect, or rewind without losing context.
- Teams writing an internal Codex onboarding doc.
- Users whose keys behave differently in iTerm2, Apple Terminal, the VS Code terminal, Warp, or tmux.
The shortcuts worth memorizing first
If you learn nothing else, learn these. They cover roughly 90% of real Codex CLI sessions.
| Shortcut | What it does | Notes |
|---|---|---|
Esc | Interrupt the current model turn or tool call | Stops the run; does not undo file edits |
Ctrl+J | Insert a newline in the composer | Most reliable newline across terminals |
Ctrl+G | Open the prompt in your $EDITOR / $VISUAL | Best way to draft a long spec |
Ctrl+R | Reverse-search your prompt history | v0.121.0+; Enter accepts, Esc cancels |
Esc Esc | Edit your previous message (composer empty) | Keep pressing to walk back; Enter forks |
Shift+Tab | Cycle approval modes in-session | Read-only → Auto → Full Access |
Tab | Queue a follow-up for the next turn | Does not interrupt the current turn |
Enter (while running) | Inject new instructions mid-turn | Codex reads it without losing context |
Ctrl+L | Redraw the screen | Keeps your context intact |
? / /keymap | Show the active bindings | The source of truth for your build |
Session control: interrupt, exit, rewind
| Shortcut | Detail |
|---|---|
Esc | Interrupts the current turn or tool call. Use it the moment a run drifts. |
Ctrl+C | Cancels input; press twice to quit the session. You can also type /exit or /quit. |
Ctrl+D | Exits when the composer is empty; press twice to force-quit. |
Esc Esc | With an empty composer, edits your previous user message. Keep pressing Esc to walk further back through the transcript, then press Enter to fork the conversation from that point. |
Ctrl+L | Redraws the terminal when long output garbles the screen. It does not clear Codex context. |
Ctrl+O | Copies Codex’s most recent completed output to the clipboard. |
The most important distinction: Esc stops the current turn, but neither Esc nor Ctrl+C rolls back files Codex already wrote. To undo edits, tell Codex explicitly (“revert your changes to src/auth.ts”) or inspect git diff and discard yourself. If you fork with Esc Esc, you change the conversation, not the files on disk.
Approval and automation modes
Codex CLI ships three approval modes. Cycle them mid-session with Shift+Tab, or set one explicitly with the /approvals command (some builds expose it as /permissions).
| Mode | What Codex may do | When to use it |
|---|---|---|
| Read-only | Browse and read files, propose a plan; no edits, no commands | First look at an unfamiliar repo; planning |
| Auto (default) | Read, edit, and run commands inside the working directory; asks before touching anything outside it or using the network | Day-to-day work in a repo you trust |
| Full Access | Work across the machine, including network access, without asking | Isolated containers or throwaway VMs only |
Rule of thumb: read-only to plan, Auto for normal work, Full Access only inside a sandbox you can throw away. Auto is the safe default precisely because it confines writes to the working directory and still gates network and out-of-tree actions behind a prompt.
Composing prompts: newlines, editor, files, shell
This is where Codex saves the most time, and where terminals cause the most friction.
| Shortcut / token | What it does |
|---|---|
Ctrl+J | Insert a newline without sending. The most reliable multiline key across terminals. |
Shift+Enter | Also inserts a newline, but only if your terminal forwards the combo. If it submits instead, use Ctrl+J. |
Ctrl+G | Opens the current draft in your $EDITOR / $VISUAL. Best for anything longer than a couple of lines. |
@ | Fuzzy file search; pick a file to attach its path/content to the message. |
! | Run a local shell command and feed the output into the conversation. |
-i / --image | Attach an image (e.g. a screenshot of an error). |
For a real spec, don’t fight terminal keymaps. Either press Ctrl+G to draft in your editor, or write the spec in a file and tell Codex to read it:
Read TASK.md and implement it. Stop and ask before changing the database schema.
Input editing (readline / Emacs style)
The composer follows readline conventions, so most shell editing habits transfer directly.
| Shortcut | Meaning |
|---|---|
Ctrl+A | Move to start of line |
Ctrl+E | Move to end of line |
Ctrl+B / Ctrl+F | Move back / forward one character |
Option+B / Alt+B | Move back one word (Option must send Meta on macOS) |
Option+F / Alt+F | Move forward one word |
Ctrl+U | Delete everything before the cursor |
Ctrl+K | Delete everything after the cursor |
Ctrl+W | Delete the previous word |
Ctrl+Y | Yank (paste back) the last killed text |
Ctrl+H / Backspace | Delete the previous character |
Since v0.135.0, the TUI also supports Vim-style text-object editing when Vim mode is enabled in your config, which adds word/line motions on top of these readline defaults.
Reasoning depth, history, menus
| Shortcut | Meaning |
|---|---|
Alt+, / Alt+. | Lower / raise reasoning depth for the next turn (v0.124.0+) |
Ctrl+R | Reverse-search prompt history; Enter accepts, Esc cancels (v0.121.0+) |
Up / Down | Navigate draft history in the composer |
Tab | Complete a slash command or path; queues a follow-up turn while Codex works |
Enter | Submit, or inject instructions into the running turn |
Esc | Close a menu, or interrupt the active task |
Raising reasoning depth (Alt+.) before a hard refactor gives Codex more thinking budget; lowering it (Alt+,) speeds up trivial edits.
Slash commands you’ll use often
Shortcuts handle editing; slash commands handle the session. The ones worth knowing:
| Command | What it does |
|---|---|
/keymap | Print the active keymap for your build (settles every “which key?” question) |
/approvals | Switch approval mode (also /permissions in some builds) |
/model | Switch the underlying model |
/init | Generate an AGENTS.md project context file |
/diff | Show the working-tree diff Codex has produced |
/compact | Summarize and shrink the context to free up window |
/review | Ask Codex to review the current changes |
/exit, /quit | End the session |
When shortcuts fail
| Symptom | Cause | Fix |
|---|---|---|
Option+B/F prints odd characters | Option isn’t sending Meta | Enable “Use Option as Meta key” (Apple Terminal) or “Esc+” (iTerm2) |
Shift+Enter submits instead of newline | Terminal doesn’t forward the combo | Use Ctrl+J instead, or draft with Ctrl+G |
Ctrl+S freezes output | Terminal flow control paused the stream | Press Ctrl+Q; to disable permanently, stty -ixon |
Esc Esc does nothing | Composer isn’t empty, or build predates it | Clear the input first; check /keymap |
Alt+, / Alt+. ignored | Build older than v0.124.0 | Update Codex CLI |
Cmd shortcuts do nothing | You’re in a pure terminal, not an app surface | Use the terminal Ctrl / Alt equivalents |
iTerm2 and Apple Terminal both work cleanly once Option is mapped to Meta. tmux, screen, and some VS Code integrated-terminal builds remap meta/alt keys. When a key misbehaves, test it in plain Terminal.app to isolate whether it’s Codex or your terminal.
Codex CLI vs Claude Code
The two tools share readline editing keys (Ctrl+A, Ctrl+E, Ctrl+R) and the “press Esc to interrupt” reflex, and both ship an Esc Esc rewind. But the slash commands and product-level bindings differ: Codex uses /approvals and /keymap; Claude Code has its own set such as /terminal-setup. Don’t assume a binding from one carries to the other. In Codex, /keymap is the authoritative list for your installed version. For a deeper comparison, see Codex vs Claude Code.
FAQ
Q: What’s the difference between Esc and Ctrl+C in Codex?
A: Esc interrupts the current model turn or tool call while keeping the session alive, ideal when a run heads the wrong way. Ctrl+C cancels the current input; pressed twice on an empty composer it quits the session entirely. Neither rolls back files Codex already edited, so use git diff or ask Codex to revert.
Q: How do I enter a newline without sending the prompt?
A: Press Ctrl+J. It’s the most reliable newline across terminals. Shift+Enter also works if your terminal forwards the combo, but many don’t. For anything longer than a few lines, press Ctrl+G to draft in your $EDITOR instead.
Q: Can I edit a message I already sent?
A: Yes. With an empty composer, press Esc Esc to edit your previous user message. Keep pressing Esc to walk further back through the transcript, then press Enter to fork the conversation from that point. This rewinds the conversation, not the files on disk.
Q: How do I switch approval modes without restarting?
A: Press Shift+Tab to cycle Read-only, Auto, and Full Access mid-session, or run /approvals (or /permissions on some builds) to set one explicitly. Auto is the default and confines writes to the working directory.
Q: Which terminals are most likely to break Codex shortcuts?
A: tmux, screen, and some VS Code integrated-terminal builds remap meta/alt keys, breaking Option+B/F and Shift+Enter. iTerm2 and Apple Terminal work cleanly once you enable “Use Option as Meta key”. When in doubt, test in plain Terminal.app first, and fall back to Ctrl+J for newlines.
Related
- Codex Beginner Guide
- Codex Skills and /skills Guide
- Codex vs Claude Code
- AI Coding Context Management
Tags: #AI coding #Codex #Tutorial