How to Exit Codex CLI
Press Ctrl + C to exit Codex CLI. You can also type /exit or /quit and press Enter — all three do the same thing and drop you back at your shell prompt.
The reason people end up searching for this is the key that doesn't work: Esc. In Codex CLI, Esc interrupts whatever the agent is doing but leaves you sitting in the session. That's the right key when you want Codex to stop editing your files — and the wrong one when you want your terminal back.
Every way out of Codex CLI
| What you press | What happens |
|---|---|
| Ctrl + C | Closes the session and returns you to the shell. The fastest way out. |
/exit | Exits the CLI. Same result, if you'd rather type it. |
/quit | An alias for /exit. Identical behaviour. |
| Esc | Does not exit. Interrupts the task Codex is running and keeps you in the session. |
If Codex is in the middle of something
Don't reach straight for Ctrl + C while the agent is mid-edit. Press Esc first to interrupt the turn cleanly, let it come to a stop, then Ctrl + C to leave. Quitting during an active turn is safe for your files — Codex isn't holding them open — but you lose the chance to see what it had already changed, and any queued follow-up prompts go with it.
If a shell command Codex launched is what's hanging, interrupting the Codex turn won't always kill the child process. Interrupt with Esc, and if the terminal still won't come back, close the session with Ctrl + C and check for a stray process afterwards.
Does exiting lose my conversation?
No. Codex saves your sessions, so quitting is not destructive. Start Codex again and run /resume to pick a saved conversation back up where you left it. This is worth knowing before you try to keep a session alive all day just to avoid losing context — you don't have to.
Two related commands people mix up with exiting:
/new— starts a fresh conversation without leaving Codex. Use this when you want a clean slate, not the shell./clear— clears the terminal display and starts a fresh chat. Also keeps you inside Codex.
Why Ctrl+C surprises people coming from other AI CLIs
Because it means something different in almost every terminal agent. In Claude Code and Aider, a single Ctrl + C interrupts and keeps you in the session — you need a second press to actually quit. In Codex CLI one press closes the session outright. So the habit you build in one tool will drop you out of another, which is exactly the wrong surprise when the agent is halfway through a refactor.
If you switch between tools regularly, Esc is the safer key to reach for when you mean "stop", because it interrupts rather than exits in most of them. The cross-tool comparison maps interrupt and exit for every agent side by side.
Exiting isn't a thing in headless mode
Everything above is about the interactive TUI you get from running codex. If you invoke Codex non-interactively for a single task, there's no session to leave — the process runs, prints, and returns to your shell on its own. Reach for that mode in scripts and CI, where an interactive prompt waiting for Ctrl + C would just hang the job.
The rest of the keymap
Ctrl + C and /exit are two entries in a much larger keymap — Codex CLI also has Ctrl + J for multi-line prompts, Ctrl + T for the transcript, Tab to queue a follow-up while it works, and a full slash-command catalog. The Codex CLI cheat sheet has all of it in one printable page.