codex-agent
Invoke OpenAI Codex CLI for coding and complex tasks. ALWAYS use the codex_agent_direct TOOL — NEVER exec codex directly. Direct codex exec opens an interactive TUI that hangs and gets killed. The tool handles non-interactive execution correctly.
Best use case
codex-agent is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Invoke OpenAI Codex CLI for coding and complex tasks. ALWAYS use the codex_agent_direct TOOL — NEVER exec codex directly. Direct codex exec opens an interactive TUI that hangs and gets killed. The tool handles non-interactive execution correctly.
Teams using codex-agent should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/codex-agent/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How codex-agent Compares
| Feature / Agent | codex-agent | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Invoke OpenAI Codex CLI for coding and complex tasks. ALWAYS use the codex_agent_direct TOOL — NEVER exec codex directly. Direct codex exec opens an interactive TUI that hangs and gets killed. The tool handles non-interactive execution correctly.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
Cursor vs Codex for AI Workflows
Compare Cursor and Codex for AI coding workflows, repository assistance, debugging, refactoring, and reusable developer skills.
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
SKILL.md Source
# Codex Agent — Direct Tool
**CRITICAL: NEVER run `exec codex ...` directly.** Running codex without the tool opens an interactive TUI that hangs and gets killed with signal 9. Always use the `codex_agent_direct` tool below.
**Use your own model first.** Only delegate to Codex when the user explicitly asks, or the task is large/multi-file.
## Primary Method: `codex_agent_direct` Tool
The **`codex_agent_direct`** tool invokes Codex CLI non-interactively (`codex exec`) with structured JSON output. This is the preferred method for all Codex interactions.
```
codex_agent_direct(
prompt: "Your detailed task description",
workspace: "/path/to/project", // optional, passed as --cd
model: "gpt-4.1-mini", // optional, default "gpt-4.1-mini"
mode: "agent" | "plan" | "ask" // optional, default "agent"
)
```
### Modes
- **agent** (default): Execute code changes and commands. Codex runs with `auto` approval — it reads, edits, and runs commands in the workspace. Use for "implement", "refactor", "fix" tasks.
- **plan**: Plan before executing. Passes `--plan` to `codex exec`. Codex proposes a plan before making changes. Use when the user says "plan first", "design approach", or for large/ambiguous tasks.
- **ask**: Read-only / suggest-only. Codex is set to `suggest` approval mode — it explains and proposes but does not auto-run. Use for "explain", "where is", "why does" — no edits.
### When to Use
- User explicitly asks for "Codex", "openai codex", or "use Codex"
- **Coding tasks**: write, edit, refactor, review code
- **Complex multi-file operations**: Codex understands full codebase context
- **Analysis**: deep code analysis, dependency checking, architecture review
- Task is large, multi-file, or benefits from GPT-5 Codex reasoning
### Model Selection
| Model | Use when |
|---|---|
| `gpt-4.1-mini` | Default — fast, capable, cost-effective |
| `gpt-4.1` | Complex reasoning, large codebases |
| `gpt-5.3-codex` | Maximum capability (requires ChatGPT Pro/Plus auth) |
### Output
The tool returns structured JSON:
- `output`: Codex's text response (may include JSON transcript from `--json` flag)
- `exit_code`: 0 for success
- `duration_ms`: execution time
- `files_created`: list of new file paths detected after the run
- `truncated`: true if output was capped at 100KB
## There Is No Fallback — Handle Errors Directly
**DO NOT exec codex under any circumstances.** Running `codex` or `exec codex ...` opens an interactive TUI that hangs forever and gets killed with signal 9. There is no safe direct exec fallback.
### When the tool returns `ok: false` or an error:
1. **Read the `error` or `output` field** — it contains the failure reason (e.g. "not a trusted directory", "model not found")
2. **Report it to the user directly** — e.g. "Codex failed: [reason]. You may need to run `codex` interactively first to trust this directory."
3. **Do NOT** retry with exec, sessions_spawn, process polling, or any other approach
4. **Do NOT** start a background process and poll it
### When the tool returns empty output:
Report to the user: "Codex returned no output. The workspace may not be a trusted git repo, or Codex may need re-authentication."
### When output is raw JSONL:
The tool parses JSONL and returns clean text. If you still see raw `{"type":...}` JSON in the output, just summarize what you can see and tell the user the response format was unexpected.
### Common errors and what to tell the user:
| Error | Tell user |
|---|---|
| `Not inside a trusted directory` | Run `codex` interactively in the workspace first to trust it, or pass `--skip-git-repo-check` |
| `model not supported` | Your ChatGPT account uses `gpt-5.3-codex` — omit `--model` to use config default |
| `stream disconnected` | Codex authentication may have expired — run `codex` interactively to re-login |
| `signal 9` / process killed | The codex TUI was opened instead of non-interactive exec — this means exec was called directly, which is forbidden |
## Prerequisites
- Codex CLI installed: `npm i -g @openai/codex`
- Authenticated: run `codex` once interactively to sign in with your ChatGPT account or API key
- Verify: `python3 plugin/scripts/codex_agent_direct.py --check`
## Project Config
The project includes `.codex/config.toml` with sensible defaults:
- Model: `gpt-4.1-mini`
- Approval: `on-request` (Codex asks before running commands)
- Web search: `cached`
Override per-run with `--model` or `--approval` flags.
## Do NOT
- Do NOT run `codex` interactively from exec — it opens a TUI and hangs
- Do NOT use `codex` without the `exec` subcommand for automation
- Do NOT expose API keys in prompts or command argumentsRelated Skills
julien-workflow-advice-codex
Get OpenAI Codex CLI's opinion on code, bugs, or implementation. Use when you want a second AI perspective during coding sessions.
consult-codex
Compare OpenAI Codex GPT-5.2 and code-searcher responses for comprehensive dual-AI code analysis. Use when you need multiple AI perspectives on code questions.
codex-team
Use when you have 2+ tasks that Codex agents should execute. Runtime-native: Codex sub-agents when available, Codex CLI fallback otherwise. Handles file conflicts via merge/wave strategies. Triggers: "codex team", "spawn codex", "codex agents", "use codex for", "codex fix".
codex
Run OpenAI's Codex CLI agent in non-interactive mode using `codex exec`. Use when delegating coding tasks to Codex, running Codex in scripts/automation, or when needing a second agent to work on a task in parallel.
codex-sessions-skill-scan
Daily skill health scan: analyze ~/.codex/sessions plus per-repo session logs under ~/dev (default last 1 day) and summarize skill invocations + likely failures for personal skills in ~/dev/agent-skills (missing paths, tool failures, complex-task word triggers). Optional: include best-effort local OTel signals.
codex-reviewer
Use OpenAI's Codex CLI as an independent code reviewer to provide second opinions on code implementations, architectural decisions, code specifications, and pull requests. Trigger when users request code review, second opinion, independent review, architecture validation, or mention Codex review. Provides unbiased analysis using GPT-5-Codex model through the codex exec command for non-interactive reviews.
codex-review
Two-pass adversarial review of design documents and implementation plans using OpenAI Codex CLI. Invokes Codex to review plans section-by-section (pass 1), then holistically (pass 2), feeding critique back for revision. Use when you have a design doc, architecture plan, or implementation plan that should be stress-tested before execution.
codex-cli-bridge
Bridge between Claude Code and OpenAI Codex CLI - generates AGENTS.md from CLAUDE.md, provides Codex CLI execution helpers, and enables seamless interoperability between both tools
codex-advisor
Get a second opinion from OpenAI Codex CLI for plan reviews, code reviews, architecture decisions, and hard problems. Use when you need external validation, want to compare approaches, or are stuck on a difficult problem.
plan-refine-codex
Refine a Claude Code plan using OpenAI Codex. Use when you have a plan file and want a second opinion or to improve robustness.
codex-headless
Delegiere Aufgaben an OpenAI Codex CLI im Headless-Mode. Nutzt ChatGPT Subscription (KEIN API Key). Nur Workspace-Zugriff, KEIN System-Zugriff. Auto-Accept mit --full-auto. Web-Recherche mit --search.
codex-auth
Setup and manage OpenAI Codex CLI authentication including ChatGPT Plus/Pro OAuth, API keys, and multi-account management. Use when configuring Codex access, switching accounts, or troubleshooting authentication.