Master OpenAI’s Codex CLI from zero to advanced: installation, commands, skills, subagents, and real-world projects.
CLI, App, and Web in perspective
Node.js, npm, device auth login
/ @ agents.md context
flags, config.toml, sandbox
SKILL.md, invoke, reuse
10 types, threads, workers
Parallel, prompt formula
Parallel Git, automatic PRs
Scheduling, CI/CD, routines
Full app with multitasking
O Codex is OpenAI's coding agent — a rival to Claude Code. Its differentiator: it runs agents in the cloud, delegates tasks remotely (even from your phone) and returns ready-to-use pull requests. 274K tokens of context.
More context than Claude Code, native worktree support, direct GitHub Actions integration. A natural complement to Claude for long-running cloud tasks.
| Version | Best for | Detail |
|---|---|---|
| CLI (terminal) | Speed + local control | macOS, Windows, Linux. Direct integration with repositories |
| App (Windows) | Complete visual interface | Skills, plugins, built-in browser, multiple parallel threads |
| Web (ChatGPT) | Delegate to the cloud | GitHub connected, agents run without your PC on, access from your phone |
Installation via npm. Prerequisite: Node.js v18+. Sign-in uses device auth — you open a link in the browser without exposing an API key.
An outdated version of Node.js causes silent failures. Device auth is more secure than an API key — it works in Docker containers without exposing environment variables.
winget install --id Git.Git -e --source winget # depois instale Node.js em nodejs.org
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt-get install -y nodejs
npm install -g @openai/codex
codex login --device-auth # Abre link no browser → digita código → ✓ logado
After installing, codex opens interactive mode. / accesses internal commands, @ references project files.
O agents.md is equivalent to CLAUDE.md — it defines permanent context. Without it, Codex starts from scratch in every session.
codex # modo interativo codex "crie uma API" # prompt direto codex chat # modo conversa codex --full-auto "..." # sem confirmação
/plan mode— planning/model— switch models/browser use— activate browser/skill creator— create a skillApproval policies control when Codex asks for confirmation. Set it to always ask or never ask, depending on the environment (local development vs. production).
In an isolated container or VM, disabling confirmations eliminates friction and greatly speeds things up. In production, always keep confirmations enabled.
| Flag | Behavior | Risk |
|---|---|---|
| --full-auto | on-request + sandbox write | Medium |
| -a never | Never asks for approval | Medium |
| --dangerously-bypass... | Zero confirmations, zero sandbox | High ⚠️ |
Skills are reusable instructions for recurring tasks. Create it once, use it with $nome-da-skill or let Codex invoke it automatically.
They eliminate repetition. A "PR review" skill can run 3 subagents in parallel without rewriting the prompt each time.
--- name: pr-review-agent description: Use quando pedir revisão de PR, diff ou código alterado. --- Ao revisar um PR: 1. Leia o diff completo 2. Identifique riscos de segurança 3. Verifique cobertura de testes 4. Classifique achados por severidade
Codex has several “names” for agents — thread, task agent, worker, subagent, background agent, automation, skill. They’re all variations on how you structure the work.
Understanding the hierarchy avoids confusion. Start with threads + skills + automations. Subagents and workers come in when you need real parallelism.
| Type | Usage |
|---|---|
| Main agent | Regular chat/thread |
| Subagent | "Use subagents in parallel" |
| Background agent | Background thread |
| Automation | Automations tab (scheduled) |
| Skill | $name or natural language |
Specialized subagents launched in parallel. Codex doesn't create them automatically — you explicitly ask for it with "use subagents in parallel".
Parallelizing audits, feature planning, and refactoring drastically reduces the total time.
Use subagentes em paralelo para [objetivo]. Divida: 1. Subagente A: [papel específico] 2. Subagente B: [papel específico] 3. Subagente C: [papel específico] Regras: trabalho independente, não edite ainda, consolide no final.
Worktrees let multiple agents work in parallel without mixing changes. Each agent has its own directory + branch. OpenAI highlights worktrees as a central part of the multiagent workflow.
Without worktrees, two agents editing the same file create conflicts. With worktrees, each works in isolation, and you merge afterward.
Parallel agents, their own branches, no conflicts
Branch + commit + push + PR with summary
Codex as CI, automatic patches
Delegates through the ChatGPT app, receives PRs remotely
Automations configure routines that Codex runs at a set time without you being present. Available in the Automations from the Codex App (Windows).
Turns Codex into a team member who works while you sleep — reviewing code, running tests, and generating reports.
Toda segunda-feira às 9h: 1. Atualizar dependências (se seguro) 2. Rodar testes 3. Rodar build 4. Gerar reports/weekly-review.md 5. Se houver mudanças, criar commit
Building a stock portfolio app complete — with a UI, database, real market data, and marketing materials — using Codex 5.5, with no prior programming experience.
Pushes Codex to its limits: real multitasking with 3 simultaneous agents (dev + video + research), image generation, and reverse prompting.
Design with image generation — Codex generates visual options, user chooses
Frontend + database — Next.js + Convex to persist the portfolio
Real data — free Alpha Vantage API for live prices
Multitasking — 3 agents: dev + video (Remotion) + research (browser)
Reverse prompting — ask Codex “what should be done next?”