$npx -y skills add tobihagemann/turbo --skill codex-execRun autonomous task execution using the codex CLI. Use when the user asks to \"codex exec\", \"run codex exec\", \"execute a task with codex\", or \"delegate to codex\".
| 1 | # Codex Exec |
| 2 | |
| 3 | Autonomous task execution via the codex CLI. Runs non-interactively. Progress streams to stderr; final result on stdout. |
| 4 | |
| 5 | ```bash |
| 6 | codex exec "task description" < /dev/null |
| 7 | ``` |
| 8 | |
| 9 | For large context, pipe it via stdin. The prompt stays as the argument, context is passed as `<stdin>` automatically: |
| 10 | |
| 11 | ```bash |
| 12 | cat context.txt | codex exec "question about the context" |
| 13 | ``` |
| 14 | |
| 15 | ## Sandbox |
| 16 | |
| 17 | **All `codex` Bash calls require `dangerouslyDisableSandbox: true`** (network access to OpenAI API). Without it, codex crashes with an `Operation not permitted` panic from the `system-configuration` crate before the model runs. |
| 18 | |
| 19 | ## Stdin Gotcha |
| 20 | |
| 21 | Codex reads from stdin whenever stdin is non-TTY (per `codex exec --help`: "If stdin is piped and a prompt is also provided, stdin is appended as a `<stdin>` block"). In subagent and subprocess contexts the harness leaves stdin connected to a pipe that never EOFs, so a bare `codex exec "..."` hangs forever, printing only `Reading additional input from stdin...`. |
| 22 | |
| 23 | Always redirect stdin on non-piped invocations: |
| 24 | |
| 25 | ```bash |
| 26 | codex exec "task description" < /dev/null |
| 27 | ``` |
| 28 | |
| 29 | The piped form (`cat context.txt | codex exec "..."`) is safe — `cat` closes the pipe after the file, sending EOF. |
| 30 | |
| 31 | ## Synchronous Execution |
| 32 | |
| 33 | Run codex via the Bash tool as a foreground call (do not set `run_in_background`). Set `timeout: 600000`, the Bash maximum. A larger value is not honored: the harness backgrounds the call immediately and hard-kills codex at 600s, truncating its output. Within a valid timeout, codex runs foreground and returns its result synchronously when it finishes in time. |
| 34 | |
| 35 | If codex outlives the timeout, the harness force-backgrounds it (returning a task ID and an output file path) and the run continues to completion uninterrupted. Recover it by reading the output file: `Read` the path, then `Read` it again once the `<task-notification>` reports completion. Never wait with `Monitor` (it returns immediately, and events that arrive after your final text are dropped), and never return the task ID, an interim file snapshot, or `"Waiting for codex to finish"` as the result — each is a false-empty return. |
| 36 | |
| 37 | ## Transient Crash Retry |
| 38 | |
| 39 | Re-run the command once when the Bash call returned an error exit with no stdout and no task ID. Recover a force-backgrounded run per Synchronous Execution rather than retrying it. Keep the same prompt; when the run writes to an `-o` file, point the retry at a fresh path. Treat a second failure as final. |
| 40 | |
| 41 | Treat models-manager and cache-TTL errors as non-fatal warnings. Read the error text for usage-limit and authentication signatures and report those without retrying. |
| 42 | |
| 43 | ## Permission Levels |
| 44 | |
| 45 | | Level | Flag | When to Use | |
| 46 | |-------|------|-------------| |
| 47 | | Read-only | `--sandbox read-only` | Analysis, code reading, generating reports | |
| 48 | | Workspace write | `--sandbox workspace-write` | Editing files within the project | |
| 49 | | Full access | `--sandbox danger-full-access` | Installing packages, running tests, system operations | |
| 50 | | Full auto | `--full-auto` | Combined with a sandbox level for unattended execution | |
| 51 | |
| 52 | Omitting `--sandbox` falls back to the codex config and project trust level (trusted projects run workspace-write), so always pass the flag explicitly. |
| 53 | |
| 54 | For fix or implementation tasks, default to `--sandbox workspace-write --full-auto` so Codex can edit files without confirmation prompts. Use `--sandbox read-only` for analysis or research tasks. |
| 55 | |
| 56 | ## Options |
| 57 | |
| 58 | | Option | Description | |
| 59 | |--------|-------------| |
| 60 | | `--full-auto` | Allow file edits without confirmation prompts | |
| 61 | | `--sandbox <level>` | Permission level: `read-only`, `workspace-write`, `danger-full-access` | |
| 62 | | `--json` | JSON Lines output (progress + final message) | |
| 63 | | `-o <path>` | Write final message to a file | |
| 64 | | `--output-schema <path>` | Enforce JSON Schema on the output | |
| 65 | | `--ephemeral` | No persisted session files | |
| 66 | | `--skip-git-repo-check` | Bypass git repository requirement | |
| 67 | |
| 68 | ## Prompt Shaping |
| 69 | |
| 70 | Codex uses XML tags in its own context scaffolding, so the model parses them natively. Structure prompts with XML tags for clearer responses: |
| 71 | |
| 72 | - `<task>`: The concrete job and relevant context. |
| 73 | - `<structured_output_contract>`: Required output shape, ordering, and format. |
| 74 | - `<compact_output_contract>`: Same purpose but for concise prose responses. |
| 75 | - `<grounding_rules>`: When claims must be evidence-based. |
| 76 | - `<dig_deeper_nudge>`: Push past surface-level findings to check for second-order failures. |
| 77 | - `<verification_loop>`: When correctness matters — ask Codex to verify before finalizing. |
| 78 | |
| 79 | Keep prompts compact, with tight output contracts. One clear task per exec call. |
| 80 | |
| 81 | ## Parallel Execution |
| 82 | |
| 83 | Codex supports parallel sub-agents via `spawn_agent` / `wait_agent`. The model will not fan out unless the prompt e |