Skip to content

codex

codex - execute non-interactive OpenAI Codex prompts

state-name:
tool: codex
arguments:
prompt: <prompt-text>
model: <model-name> # optional
timeout: <duration> # optional

The codex tool invokes OpenAI’s Codex CLI (codex exec) for code-focused AI tasks. It sends a prompt and captures the response, suitable for code generation, analysis, and transformation tasks.

The tool runs in the project root directory for full codebase context.

ArgumentRequiredDefaultDescription
promptYes-The prompt to send to Codex
modelNoDefault modelModel to use
timeoutNo5mMaximum execution time
  • 30s - 30 seconds
  • 5m - 5 minutes
  • 1h - 1 hour
CodeMeaning
0Success
1Codex error
2Codex CLI not found
124Timeout exceeded

Both stdout and stderr are merged for capture:

generate-code:
tool: codex
arguments:
prompt: "Write a function to parse CSV files"
output: var(generated_code)
explain-code:
tool: codex
arguments:
prompt: "Explain what this function does: {{ file(./src/parser.js) }}"
generate-tests:
tool: codex
arguments:
prompt: |
Generate unit tests for this class:
{{ file(./src/UserService.ts) }}
output: file(./tests/UserService.test.ts)
complex-task:
tool: codex
arguments:
prompt: "Refactor this code to use async/await"
model: gpt-4
codex-task:
tool: codex
arguments:
prompt: "Analyze this codebase for security issues"
timeout: 10m
on-error:
2: codex-not-installed
124: handle-timeout
_: general-error
next: process-results
codex-not-installed:
tool: bash
arguments:
command: |
echo "Codex CLI not found. Install with: npm install -g @openai/codex"
exit 1

The Codex CLI must be installed separately:

Terminal window
npm install -g @openai/codex

Configure authentication according to OpenAI’s documentation.

The tool runs in the project root directory, giving Codex access to the full project context.

  • claude - Claude AI integration
  • gemini - Google Gemini integration