Delegate to codex
Call the OpenAI Codex CLI (`codex exec`) non-interactively to get a second opinion, run a code review, or delegate read-only or edit-capable work to an independent Codex run. Use for Codex CLI subagent-style delegation, long-running worker runs, worktree-isolated edits, machine-readable JSONL output, resume flows, and harness gotchas around stdin and sandboxing.From its SKILL.md
npx -y skills add T0mSIlver/skills --skill delegate-to-codexAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
3 things to look at
- reads credentialsReads from 2 credential sources: `CODEX_API_KEY` and 1 more.
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
- runs commandsInstructs the agent to run 7 commands, including `slug="codex-$(date +%Y%m%d-%H%M%S)"; run_dir="/tmp/codex-$slug"; mkdir -p "$run_dir"` and 6 more.
SKILL.md
5.3 KB, ~1.3k tokens by cl100k_base, as published. Nobody here has run it
Delegate to Codex (CLI)
Run codex exec non-interactively for a second opinion, review, or a delegated
edit worker. Model default: gpt-5.6-sol at -c model_reasoning_effort='"high"'
(medium/low only for small or mechanical work).
Happy path
-
Isolate. Read-only work runs in the current checkout with
-s read-only:slug="codex-$(date +%Y%m%d-%H%M%S)" run_dir="/tmp/codex-$slug"; mkdir -p "$run_dir"Edit work gets its own worktree instead, so the diff is easy to inspect or discard:
slug="codex-$(date +%Y%m%d-%H%M%S)" worktree="../$(basename "$PWD")-$slug" git worktree add -b "agent/codex/$slug" "$worktree" HEAD run_dir="$worktree/.agent-runs/$slug"; mkdir -p "$run_dir" -
Write the brief to
$run_dir/prompt.md. Include context, exact task, constraints, verification commands, output contract — and a hard completion criterion: GPT-5.6 Sol is exploratory and keeps widening scope without an unambiguous definition of "done". -
Launch. Always feed the prompt from the file with
- < prompt.md; never pass it as a bare argument under a harness (see Gotchas: stdin wedge).Read-only reviewer / second opinion:
codex exec -C "$PWD" \ -m gpt-5.6-sol -c model_reasoning_effort='"high"' \ -s read-only --json -o "$run_dir/final.md" \ - < "$run_dir/prompt.md" > "$run_dir/events.jsonl"Edit worker — same command with
-C "$worktree"and--sandbox workspace-writeinstead of-s read-only.Research briefs that need current information: add
-c tools.web_search=true. -
Harvest. Final answer in
$run_dir/final.md; session id in thethread.startedevent in$run_dir/events.jsonl. For edit work also: diff viagit -C "$worktree" diff— harvest from the working tree, not branch history, since the worker's commits may be missing (see Gotchas) — and run a fresh read-only reviewer over the diff before merging.
Gotchas
- A missing
codexbinary or stale auth surfaces mid-run as an abort — or a hang indistinguishable from the stdin wedge. Preflightcodex --versionand auth (codex login, ChatGPT auth, or a scopedCODEX_API_KEY/OPENAI_API_KEY) before long runs. - Stdin wedge.
codex execreads piped stdin whenever you pass-, no prompt, or a prompt argument — and under a harness stdin never closes, so it wedges at startup (0% CPU, no output). Use- < prompt.md, or add< /dev/nullto any argument form. Nevercodex exec "$(cat prompt.md)"bare. - Workers cannot commit in a linked worktree. The sandbox can't write the
parent repo's
.git/worktrees/<name>, sogit commit/git mergefail even withworkspace-write. The orchestrator runs all git commands; workers only edit and resolve content. Commit-shaped deliverable: brief the worker "commit; if commit fails, produce agit bundle" and fetch from the bundle. codex exec review --base <ref>recurses on 0.144.1 — re-execs itself endlessly, emits no findings, leaves stray processes. Review with plaincodex exec -s read-onlyand a "review the diff between <sha> and HEAD" prompt instead.codex exec resumerejects the exec flags (-C -m -c -s --json -o, exit 2), so resumed turns run on config defaults. Prefer a fresh self-contained run that embeds the prior finding; if you must resume:codex exec resume --last "..." < /dev/null.- A crashing MCP server in
~/.codex/config.tomlaborts the whole run. Pass--ignore-user-config(auth still resolves viaCODEX_HOME) and re-specify-m/-con the CLI. - ChatGPT-plan usage limits abort runs mid-flight with a reset time. Fall back to another vendor until then.
-s read-onlyis a hard filesystem boundary — commands that write caches or build artifacts fail under it.-pselects a config profile, not an agent persona; custom subagents are TOML files under.codex/agents/or~/.codex/agents/.codex applyapplies the latest agent diff to the current tree — checkpwdand branch first.- Worktrees omit ignored files. Copy only explicit prerequisites (e.g.
.env.local), never secret directories. If the worker needs uncommitted local changes, apply an explicit patch in the worktree — never checkpoint unrelated user WIP withgit add -A.
Not possible
- No approval prompts in exec mode:
-a/--ask-for-approvalis rejected. - No
--searchflag oncodex exec— use-c tools.web_search=true. - No worktree creation or cleanup — manage them yourself.
- No resuming
--ephemeralruns. - The sandbox is not security isolation:
--dangerously-bypass-approvals-and-sandboxonly inside a bounded container/VM/CI runner — a worktree is not a security sandbox.
Evidence and full mechanics behind each gotcha: reference/gotchas.md.
What ships with it: 1 file
3.8 KB alongside SKILL.md
reference/
- gotchas.md3.8 KB