Chapter 7. Using It in the Terminal — Checking Your Organizer with One Line of codex exec
Optional Read this when you need it. You can skip it and still follow the later chapters.One-line summary: Codex CLI is Codex for the terminal. It reads
AGENTS.mdand skills from the folder where you run it.codex exec "task"runs once and exits, and it is read-only by default. It is similar to Claude Code'sclaude -p, except for this difference.
This chapter is based on the official Codex docs checked on November 1, 2026, and the results of running Codex CLI in the macOS terminal.[1] If you are new to the terminal, you can skip this chapter. We explained what the terminal is in Claude Code Chapter 10.
Installing and Getting Started
Here are the install commands from the official docs.[2]
# macOS, Linux
curl -fsSL https://chatgpt.com/codex/install.sh | sh# Windows PowerShell
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"Here is the command broken into pieces.
curl -fsSL URL: Downloads the install script (a file that lists the installation steps) at that address.-fsSLis four options written together: "stop if there is an error, hide the progress display, still show errors, and follow the address if it has moved."|(pipe): Passes the result of the command before it to the command after it.sh: Runs the script it received.- Windows works the same way.
irmdownloads it, andiexruns it.-ExecutionPolicy ByPasslifts the script-running restriction just this once.
Before running the install command, make sure it matches the official docs (learn.chatgpt.com) character for character. That is because this command downloads a script from the internet and runs it right away.
Once the installation finishes, move to your organizer folder and type codex. On your first run, choose Sign in with ChatGPT.[3]
cd ~/hello-ai-practice/organizer
codexIn the terminal, Codex treats the folder where you started it as the project for that chat.[4] cd replaces what you did with Choose project in the app.
Quick check
What must you check before running the Codex CLI install command in the terminal?
codex exec — Ask Once and Finish
codex exec runs once and finishes without opening the chat screen.[5] We asked it the same question from Claude Code Chapter 10.
cd ~/hello-ai-practice/organizer
codex exec "Show me the list of files in the notes folder, and tell me in one line per file which template (from templates) each file used. Do not edit any files. Reply briefly as a table only."Only the answer came out cleanly (full output: Chapter 7 codex exec output.txt).
| notes file | Template used |
|---|---|
| study-2026-10-28-prompt-lecture.md | templates/study-notes.md |
| weekly-review-2026-10-26.md | templates/weekly-review.md |
| minutes-2026-10-27-weekly.md | templates/minutes.md |
Source: Hands-on results from this guide (2026-11-01). Progress logs were discarded separately, leaving only the final answer.
codex exec sends progress updates and the final answer down different paths.[6]
- Progress: Goes to the side channel on screen (stderr, standard error).
- Final answer: Goes only to standard output (stdout, standard out).
This difference is useful when you want the result in a file. For example, try typing codex exec "…" > result.md. > is a symbol that means "put the standard output in this file instead of on the screen." Then only the progress passes by on the screen, and only the final answer is saved in result.md. If a file with the same name already exists, > erases its contents and writes it anew. So pick a new name you have not used before.
codex exec is read-only by default. To let it edit files, add --sandbox workspace-write.[7] We also ran the exercises in Chapters 2, 3, and 5 of this guide with this option.
codex exec --sandbox workspace-write '$weekly-review'codex exec works by setting permissions in advance before running.[8] In the Chapter 5 exercise of this guide, when writing to the .agents folder was blocked, Codex could not ask for permission and simply stopped. For tasks that need permission prompts, it is easier to use the app or interactive codex.
There are also risky options that turn off both the sandbox and approvals, but do not use them for organizing notes.
Options from older posts and risky options (click to expand)
The --full-auto option you might see in older posts is no longer supported.[9] There is also an option like --dangerously-bypass-approvals-and-sandbox that turns off both the sandbox and approvals[10], but you do not need it for organizing notes.
Quick check
You tried to have codex exec edit a file, but nothing changed. What is the most likely reason?
Commands Inside Interactive codex
When you open interactive mode with codex, you use commands that start with /.
| Command | What it does |
|---|---|
/permissions | Change permissions (the permissions menu in the app) |
/import | Import settings from Claude Code or Cursor |
/resume | Continue a saved chat |
/status | View chat details and remaining limits |
/skills | View the list of skills |
Source: Codex official docs[11][12][13][14][15]
To continue a chat from outside after closing interactive mode, type codex resume.[13:1]
/permissions and /import are terminal commands. In the app, use the permissions menu below the input box (Chapter 4) and the Import menu in Settings (Chapter 3).
Quick check
On the interactive Codex CLI screen, which command shows your session details and remaining usage limit?
Try It Yourself
- Check that the install command above matches the official docs, then install it (if you already have it, run
codex --version). - Move to your organizer folder and run the read-only
codex execquestion above. - Open interactive mode with
codexand type/status. - Type
$or run/skillsto check that the skill name from Chapter 5 appears.[15:1]
Up next: In Chapter 8, we will cover cost, data, and safety, and see how Codex handles a note with hidden instructions inside.
Summary
- In the terminal, Codex treats the folder where you run it as the project and reads
AGENTS.mdand skills from that folder. - Check that the install command matches the official docs before running it.
codex execruns once and finishes, and it is read-only by default. To allow edits, add--sandbox workspace-write.codex execruns with permissions set in advance. Use the app or interactive mode for tasks that need approval prompts.
Glossary
| Term | One-line meaning |
|---|---|
| Codex CLI | Codex used in the terminal |
codex exec | A mode that runs once and finishes |
| stdout / stderr | Standard output / the side channel where progress and errors go |
Finished this chapter?
Progress is saved only in this browser. See your progress on the full table of contents.
Next chapter: Chapter 8. Cost, Data, Safety, and Choosing Your Tool
References (15)
The version this guide ran was Codex CLI 0.166.0. ↩︎
Codex official docs, "Codex CLI". "curl -fsSL chatgpt.com | sh" / "powershell -ExecutionPolicy ByPass -c "irm chatgpt.com | iex"" learn.chatgpt.com (checked on 2026-11-01) ↩︎
Codex official docs, "Codex CLI". "Open a project directory and run
codex. The first time you run Codex, choose Sign in with ChatGPT or another available sign-in method." learn.chatgpt.com (checked on 2026-11-01) ↩︎Codex official docs, "Projects and chats". "Codex CLI treats the directory where you start it as the project for the chat." learn.chatgpt.com (checked on 2026-11-01) ↩︎
Codex official docs, "Non-interactive mode". "Non-interactive mode lets you run Codex from scripts (for example, continuous integration (CI) jobs) without opening the interactive TUI." learn.chatgpt.com (checked on 2026-11-01) ↩︎
Codex official docs, "Non-interactive mode". "While
codex execruns, Codex streams progress tostderrand prints only the final agent message tostdout." learn.chatgpt.com (checked on 2026-11-01) ↩︎Codex official docs, "Non-interactive mode". "By default,
codex execruns in a read-only sandbox." / "Allow edits:codex exec --sandbox workspace-write "<task>"" learn.chatgpt.com (checked on 2026-11-01) ↩︎Codex official docs, "Non-interactive mode". "Run with explicit, pre-set sandbox and approval settings." learn.chatgpt.com (checked on 2026-11-01) ↩︎
Codex official docs, "Non-interactive mode". "
--full-autois no longer supported." learn.chatgpt.com (checked on 2026-11-01) ↩︎Codex official docs, "Agent approvals & security". "
--dangerously-bypass-approvals-and-sandbox(alias:--yolo)" learn.chatgpt.com (checked on 2026-11-01) ↩︎Codex official docs, "Permissions". "In the CLI, enter
/permissions." learn.chatgpt.com (checked on 2026-11-01) ↩︎Codex official docs, "Import from another agent". "Start a local Codex CLI session and type
/import." learn.chatgpt.com (checked on 2026-11-01) ↩︎Codex official docs, "Projects and chats". "Use
/resumewhile Codex is open, or runcodex resume, to continue a saved chat." learn.chatgpt.com (checked on 2026-11-01) ↩︎Codex official docs, "Pricing". "If you want to see your remaining limits during an active Codex CLI session, you can use
/status." learn.chatgpt.com (checked on 2026-11-01) ↩︎Codex official docs, "Build skills". "In Codex CLI or the IDE extension, run
/skillsor type$to mention a skill." learn.chatgpt.com (checked on 2026-11-01) ↩︎