Mastering Codex CLI: Essential Commands & Workflows for AI-Assisted Terminal Coding
This guide covers Codex CLI installation, key slash commands (/init, /status, /permissions, /model, /review), automation flags (-C, -m, --add-dir, codex exec), and best practices for iterative AI-assisted coding with clear boundaries and verification loops.
Installation and Login
On macOS or Linux, run the official standalone install script:
curl -fsSL https://chatgpt.com/codex/install.sh | shAfter installation, navigate to your project directory and run codex. On first launch, follow the prompts to log in with your ChatGPT account. Codex is available across multiple ChatGPT plans; the exact usage quota varies by plan, task complexity, and execution location.
Initial Verification
Before asking Codex to make changes, run /status to inspect the current model, working directory, and permissions. Then confirm Codex understands the codebase with a read-only task, for example:
Explain this repository's entry points, core modules, and test commands. Do not modify any files.High-Frequency Slash Commands
/init — Creates an
AGENTS.md</strong> file that records project conventions, test commands, and directory boundaries. This acts as a persistent briefing for every subsequent session, more reliable than repeated verbal reminders.</li><li><strong>/status</strong> — Displays the current session configuration. Check it after switching directories, models, or permissions to avoid misjudgments.</li><li><strong>/permissions</strong> — Adjusts what Codex is allowed to do. When external network access, sensitive directories, or high-impact commands are involved, explicit permissions make collaboration safer.</li><li><strong>/model</strong> — Selects the active model and reasoning intensity. Routine edits may not need the highest intensity; complex architectural decisions or cross-module refactors benefit from increased reasoning.</li><li><strong>/review</strong> — Runs a post-change defect scan. It does not replace tests but re-examines boundary conditions, regression risks, and code consistency.</li></ul><h2>Command-Line Arguments for Automation</h2><p>When launching from the shell:</p><ul><li><code>-Csets the working directory. -m specifies the model. -i attaches an image. --add-dir grants access to additional directories that need collaboration.
For non-interactive, repeatable tasks, use codex exec to hand well-defined work to scripts or CI pipelines.
Recommended Workflow: Small Iterative Loops
Prefer a tight cycle: ask Codex to outline a plan, apply changes to a limited scope, then run tests and inspect diffs. Prompts should explicitly state which files may be modified, what success looks like, and what must not be touched. This yields better results than stacking a long list of commands.
Three Common Pitfalls
Treating Codex as an omnipotent shell. It can invoke local tools but still respects the current permissions and environment; missing dependencies will not magically appear.
Opening the entire directory at once. Larger codebases should start with the minimum writable scope; expand only after confirming results.
Prioritizing generation speed over verification evidence. Reliable delivery must include test results, change diffs, and uncovered risks.
Codex CLI's barrier is not memorizing every parameter but stringing "requirement → modification → verification" into a short loop. The terminal moves fast, yet engineering quality still depends on boundaries and evidence.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
