codex-invocation
Skill9 starsChanged 30 days agoMITView on GitHub
How to invoke Codex CLI from Claude Code on this machine. Use when any workflow needs to dispatch a Codex task — codex-dispatch wrapper + --background + Monitor polling. Contains the exact wrapper, flags, polling loop, and stale-lock workaround. Read this before the first Codex call in a session, including from dev-orchestrator.
- Installs packages
In this repository16 other files it gives its agents.
- agent-invocationSkill
- architecture-memorySkill
- brainstormingSkill
- dev-orchestratorSkill
- dispatching-parallel-agentsSkill
- executing-plansSkill
- finishing-a-development-branchSkill
- receiving-code-reviewSkill
- requesting-code-reviewSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- using-git-worktreesSkill
- verification-before-completionSkill
- writing-plansSkill
- writing-skillsSkill
- zcode-invocationSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 49
Before the first task in a session, verify the wrapper and the companion are alive:
- Very specific: line 69
Role table (GPT-6 routing): Every dev-orchestrator dispatch passes --model + --effort explicitly:
- Very specific: line 136
Run this via the Monitor tool.
- Distinctive: line 175
When in doubt, dispatch fresh with a full prompt: a fresh task merely costs Codex a context re-read.
- Distinctive: line 215
Always include a draft position when you have one — a consultation without a position to attack degenerates into a generic essay.
- Distinctive: line 222
Write tasks: NEVER two in the same working tree — they stomp each other's files and their diffs become inseparable.
- Distinctive: line 236
After the Monitor loop reports a terminal status:
- Very specific: line 244
If a prior task was interrupted (Esc) or the broker restarted, the broker may hold in-memory state of status=running even after the OS …
- Very specific: line 264
Call the old hardcoded path ~/.claude/plugins/cache/openai-codex/codex/.../codex-companion.mjs — we no longer depend on that plugin being …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Codex invocation (codex-dispatch wrapper, background-only)
Manual-only pipeline skill (superpowers-strigov-ver). It starts only from the user (
/dev,/superpowers-strigov-ver:<skill>), from another skill of this plugin, or when resuming an in-progress plan — never on your own initiative. The Skill tool refuses it by design, so this plugin's pipeline skills are loaded withRead, never through the Skill tool. This file:${CLAUDE_SKILL_DIR}/SKILL.md(if the variable shows unexpanded, it is the path you just read). Another skill named below (writing-plans,codex-invocation,zcode-invocation,dev-orchestrator, …) is../<name>/SKILL.mdrelative to this skill's directory —Readit there. After a context compaction, re-Readthis file before your next step.
GLM-5.3-Flash through Z.ai's ZCode CLI — the dev-orchestrator default implementer — has its own wrapper and skill:
Read../zcode-invocation/SKILL.md(manual-only; never through the Skill tool). This skill covers Codex only.
Role routing (
"$AD" route <role>) and the other headless harnesses (claude -p, OpenCode, pi,dsh) live in../agent-invocation/SKILL.md(manual-only). The built-in Codex profilesluna,sol,astraandastra-highkeep exactly the commands below.
The plugin vendors the Codex companion runtime under vendor/codex-companion/ and exposes it through the codex-dispatch shell wrapper in bin/. Do not call the upstream OpenAI codex plugin — we do not depend on it being installed.
The wrapper handles three things on every call:
- Resolves the bundled
codex-companion.mjsfrom the marketplace cache or the local dev tree. - Pins
CLAUDE_PLUGIN_DATAto~/.claude/plugins/data/superpowers-strigov-ver-codexso jobs/broker state stays isolated from any other codex install on the machine. - For
task/review/adversarial-review, injects--model gpt-6.1-sol(overridable viaCODEX_DEFAULT_MODELenv or by passing an explicit--modelflag). This blocks the backend from auto-downgrading to spark on small or low-effort tasks. Protocol dispatches always pass an explicit--modelper role (see the role table below); the pin only backs up ad-hoc calls (see "Ad-hoc consultation" below).
On this Mac in Claude Code terminal mode, the standard Codex invocation paths silently auto-reject. Use this wrapper with background tasks and Monitor polling.
Working path
1. Resolve the wrapper once per session
DISPATCH="$(command -v codex-dispatch || true)"
[ -z "$DISPATCH" ] && DISPATCH="$(ls -1d ~/.claude/plugins/cache/strigov-cc-plugins/superpowers-strigov-ver/*/bin/codex-dispatch 2>/dev/null | sort -rV | head -1)"
[ -z "$DISPATCH" ] && DISPATCH="$(pwd)/bin/codex-dispatch"
echo "DISPATCH=$DISPATCH"command -v codex-dispatch works when the marketplace install put bin/ in PATH; the glob fallback covers a fresh session before PATH refreshes; the $(pwd)/bin/... fallback is for local dev runs from the repo root.
2. One-time login (user action)
User runs in their shell prompt:
!codex loginThe !-prefix in Claude Code makes it a user-shell command, not a tool call. Browser OAuth flow, then "Successfully logged in". Required once per machine. This logs in the standalone codex CLI (npm i -g @openai/codex), which is the only external dependency of the wrapper.
3. Sanity-check the runtime
Before the first task in a session, verify the wrapper and the companion are alive:
"$DISPATCH" status --jsonA JSON snapshot (workspaceRoot, sessionRuntime, running, recent) means the wrapper resolved the companion and the broker is reachable.
4. Submit task (ALWAYS --background)
"$DISPATCH" task \
--background \
[--write] \
[--model <gpt-6-astra|gpt-6-luna|gpt-6.1-sol>] \
[--effort <low|medium|high|xhigh|max|ultra>] \
[--resume-task task-XXXX | --resume-last | --fresh] \
"<prompt>"Role table (GPT-6 routing). Every dev-orchestrator dispatch passes --model + --effort explicitly:
| Role | Flags |
| Plan review (dev-orchestrator Step 2, writing-plans) | --model gpt-6-astra --effort xhigh (no --write; fresh task every round) |
| Spec review (brainstorming) | --model gpt-6-astra --effort xhigh |
| Control review (Step 4.2, requesting-code-review) | --model gpt-6-astra --effort high |
| Implementability check (systematic-debugging, 3+ failed fixes) | --model gpt-6-astra --effort high (no --write, single shot) |
| Final-review fallback (Step 5, only when Opus is unavailable) | --model gpt-6-astra --effort xhigh (no --write) |
| Availability-fallback implementation (Luna max) — GLM channel down or kill switch; implementation + fix rounds (dev-orchestrator Step 3 / 3.5 / 4 / 5, integration repair) | --model gpt-6-luna --effort max --write |
| Risk-marked phases (SECURITY / DATA_LOSS) and reasoning escalation (Sol xhigh) | --model gpt-6.1-sol --effort xhigh --write (GLM phase: FRESH; Luna phase: resume the Luna thread) |
| Ad-hoc consultation / one-off calls | no --model — wrapper default (gpt-6.1-sol); --effort xhigh (high for quick checks) |
Astra is the reviewer model, Luna the availability-fallback implementer (GLM via ZCode is the default — zcode-invocation), Sol 6.1 the risk-phase implementer, the escalation and the ad-hoc default. gpt-6-luna always runs at max (it has no ultra); a Luna dispatch at any lower level is a wrong dispatch. max on any other role only when the user asks for it by name.
--effort ultra is user-initiated ONLY. Ultra is the parallel-subagent mode of Astra / Sol (~4× tokens). Never offer it, suggest it, or fall back to it on your own — use it exclusively when the user explicitly said "ultra" in their own words. Note: ultra may be rejected on some Codex plans/transport paths; if the dispatch errors on effort, report that to the user rather than silently downgrading.
Expected output: Codex Task started in the background as task-XXXX.
Multi-line prompts go through a file, not inline. Anything longer than one sentence: write the prompt to a scratch file with the Write tool first and pass it via the native --prompt-file flag — inline quoting of multi-line text with backticks / $ / quotes breaks silently:
"$DISPATCH" task --background --effort xhigh --prompt-file /path/to/scratch/codex-prompt.mdFlag sanity before submitting (re-check every dispatch):
--background— always;--write— ONLY when the task must modify files (implementation); never on reviews, and no plan-stage Codex role writes files any more;--model+--effortmatch the role table above (plan + spec review = astra/xhigh; control review = astra/high; final-review fallback = astra/xhigh; fallback implementation = luna/max; risk-phase implementation and escalation = sol 6.1/xhigh; implementability check = astra/high); ad-hoc consultations omit--modeland take the wrapper default; noultraunless the user explicitly asked;--resume-task task-XXXX— the standard way to continue a prior Codex conversation: resumes the thread of exactly that task id, regardless of what ran in between (see "Resume semantics" below). Track the task id of each role's last dispatch and resume by it;--resume-last— legacy positional resume ("newest thread in this repo"); only safe when no other Codex task ran in between. Prefer--resume-taskeverywhere; first round of a new loop goes without either.
Ultra smoke test (run ONCE per machine and model family, on the user's first ultra request)
Ultra requires a Plus-or-higher Codex plan AND a transport that supports it — Codex Desktop does; third-party /responses relays were observed capped at xhigh/max, and the app-server path this wrapper uses is unverified. Before the first real ultra dispatch on a machine, offer the user this cheap probe (seconds of tokens):
"$DISPATCH" task --background --model <the role's model, e.g. gpt-6-astra> --effort ultra "Reply with one word: PONG"
# after the Monitor loop reports terminal:
"$DISPATCH" status task-XXXX --json # failed → read the log below
"$DISPATCH" result task-XXXX
cat ~/.claude/plugins/data/superpowers-strigov-ver-codex/state/<workspace-slug>/jobs/task-XXXX.logInterpretation:
failedwith an effort/entitlement error → ultra does not pass through this path; tell the user, and for ultra runs suggest Codex Desktop. Real dispatches proceed only after the user picks a fallback (max) explicitly.completed→ check the job log / events for the effective reasoning effort and for parallel-subagent activity; a genuine ultra run shows markedly higher token use even on a trivial prompt. If effort was silently coerced to xhigh/max, treat this path as "no ultra" — silent coercion means the user pays Sol prices without getting ultra.
Remember the outcome for the rest of the session; do not re-probe before every ultra dispatch.
5. Poll with terminal-only filter (via Monitor)
TASK=task-XXXX
until
st=$("$DISPATCH" status "$TASK" --json 2>/dev/null \
| python3 -c "import json,sys; print(json.load(sys.stdin)['job']['status'])")
case "$st" in
completed|failed|cancelled) echo "codex task terminal: $st"; true ;;
*) false ;;
esac
do
sleep 25
doneRun this via the Monitor tool. The case guard is non-negotiable — a monitor that prints every poll ("elapsed=40s status=running") floods the chat and auto-stops.
6. Fetch result
"$DISPATCH" result task-XXXXRelay Codex's report to the next step verbatim (or summarize into the next prompt, preserving verdict lines and blocking items exactly).
Flag reference
--background— return immediately with task id. Mandatory.--write— Codex may modify files (implementer). Omit for review-only runs (default is read-only).--effort <low|medium|high|xhigh|max|ultra>— reasoning effort (max/ultra are a local companion patch; upstream stops at xhigh). In dev-orchestrator: implementation =max; plan review, spec review, escalation and the final-review fallback =xhigh; control review =high. Nothing lower.ultraonly on explicit user request.--model <name>— the role's model (see role table above). The wrapper auto-pinsgpt-6.1-solif you don't pass this. Override the wrapper default globally withCODEX_DEFAULT_MODEL=...in the env.--resume-task <task-id>— continue the Codex conversation of exactly that prior task. Thread-addressed: immune to whatever ran in between. Preferred resume mechanism.--resume-last— continue the newest task thread in this repo. Legacy; safe only when no other Codex task ran in between. Prefer--resume-task.--fresh— force new session. Use when a stale job record prevents resume (see below).
Related commands: status [job-id] [--all] [--json], result [job-id] [--json], cancel [job-id].
Resume semantics — read before resuming anything
--resume-task task-XXXX (vendored-companion extension, idea borrowed from TRIP-workflow's per-target thread files) resolves the stored job record of task-XXXX and resumes that job's own thread. Because the reference is explicit, it stays correct no matter how many other Codex tasks (other roles, other loops, parallel reviews) ran in between. Rules:
- Track the task id of each ROLE's latest dispatch (spec reviewer, implementer, control reviewer are separate roles — never cross them).
- Any task id of the same role/thread works: resuming
task-0007after the thread already continued intask-0012lands in the same thread — the id is resolved to its thread, not replayed. - The referenced task must be terminal (
completed); a still-running reference errors out cleanly. - Worktree isolation unchanged: pass the same
--cwdas the original dispatch, ids are per-workspace.
--resume-last resumes the NEWEST completed task thread in this repo — regardless of what role that task played. It remains ONLY as a fallback when a task id got lost; if you use it, first confirm via status --json that the newest thread really is the one you intend to continue. Prefer --resume-task in every loop:
- Spec review loop (brainstorming: Codex review → Opus revision → Codex re-review):
--resume-task <spec-review-task-id>. - dev-orchestrator Step 2 plan review: FRESH task every round, never resumed — same bias decision as Step 4.2 below. Use the follow-up template plus the ledger, not thread memory.
- Implementer
NEEDS_CONTEXT/ Sol reasoning-escalation re-dispatch:--resume-task <implementer-task-id>. - dev-orchestrator Step 4 fix rounds:
--resume-task <implementer-task-id>— the fixer continues its own implementation thread with full context even though the control reviewer ran in between. (Before--resume-taskexisted this loop was forced to use fresh fully re-briefed dispatches.) - Step 4 control review rounds 2+: still dispatched FRESH by design — an independent second opinion must not anchor on its own prior rounds. This is a bias decision, not a resume limitation.
When in doubt, dispatch fresh with a full prompt: a fresh task merely costs Codex a context re-read; a wrong resume poisons the thread with another role's instructions.
Ad-hoc consultation (second opinion)
A free-form, read-only second opinion from Codex — an architecture call before it hardens, a debugging hypothesis, a conclusion to red-team. Advisory only: no verdict tokens, nothing gated on the answer. Agreement is weak evidence; disagreement is a strong signal — relay any disagreement to the user verbatim, attributed to Codex. Not from the dev-orchestrator main thread while its protocol is active (its channels are fixed), and not for questions that need the user's own judgment.
Dispatch without --model — the wrapper default applies — and never with --write:
"$DISPATCH" task --background --effort xhigh --prompt-file <scratch>/ask-<topic>.mdDrop to --effort high for a quick sanity check. Follow-ups on the same topic resume its thread: same command plus --resume-task <task id of the previous round>. Prompt template:
ADVISORY CONSULTATION — read-only. Do not modify any files. You are being asked for a grounded second opinion, not a review verdict and not an implementation.
## Question
<the question — one paragraph, specific>
## My draft position (red-team this)
<your current recommendation / hypothesis and the reasoning; omit the section header only if you genuinely have no position yet>
## Context
- Repository root: <path>
- Relevant files / evidence so far: <paths, error messages, measurements>
## What I want back
1. Your independent answer, grounded in the actual code you inspected (cite file:line for every claim about the repo).
2. Where you AGREE with my position — one line each, no elaboration.
3. Where you DISAGREE or see a risk I missed — elaborate ONLY here.
4. What evidence would settle each disagreement.
Be direct. "Your position holds, no material objections" is a complete, valid answer.Always include a draft position when you have one — a consultation without a position to attack degenerates into a generic essay.
Parallel tasks and worktrees
Each --background task is its own detached OS process — there is no serial queue, so several Codex tasks CAN run at once. The rules:
- Read-only tasks (reviews, no
--write): safe to run in parallel in the same working tree. - Write tasks: NEVER two in the same working tree — they stomp each other's files and their diffs become inseparable. Each parallel write task gets its own git worktree.
Dispatching into a worktree: pass
--cwd <worktree-path>(nocdneeded):"$DISPATCH" task --background --write --model gpt-6-luna --effort max --cwd <worktree-path> --prompt-file <scratch>/prompt.mdThe companion resolves the workspace from
--cwd(git rev-parse --show-toplevel), so each worktree gets its OWN state directory, broker, job list, and thread history — fully isolated tracks.status/result/cancelfor a worktree task must pass the same--cwd <worktree-path>— without it the wrapper looks in the main repo's workspace and won't find the job.- Resume isolation: thread history is per-worktree, so parallel tracks never collide on
--resume-last; the within-track rules from "Resume semantics" still apply unchanged. - Width cap: max 2 concurrent write tasks, counted across both dispatchers — ZCode jobs (
"$ZDISPATCH" status) count too. Subscription rate limits and orchestrator attention both degrade beyond that. Do not launch other Codex tasks while 2 write tasks are live.
Terminal status handling
After the Monitor loop reports a terminal status:
completed→ fetch withresult; machine-read the FIRST line for the verdict / status token.failed→ read the tail of the job log (~/.claude/plugins/data/superpowers-strigov-ver-codex/state/<workspace-slug>/jobs/task-XXXX.log). Retry ONCE with--freshand the same full prompt. A secondfailed→ stop and escalate to the user with the log tail.cancelled→ someone interrupted the task. Do NOT silently re-dispatch — report to the user and wait for instruction.
Stale-lock gotcha
If a prior task was interrupted (Esc) or the broker restarted, the broker may hold in-memory state of status=running even after the OS process is gone. A subsequent --resume-last fails with:
Task task-XXXX is still running. Use /codex:status before continuing it.(--resume-task hits the same class of problem when the referenced job's on-disk record is stuck at running/queued: it refuses with Job task-XXXX is still running; wait for it to finish.... Same workaround below applies.)
Patching the on-disk JSON at ~/.claude/plugins/data/superpowers-strigov-ver-codex/state/<workspace-slug>/jobs/<task>.json does not help — the broker holds state in memory via broker.sock, not on disk.
Workaround: submit a fresh task with --fresh instead of --resume-last. Codex re-reads project context; new jobs start fine.
When you fall back to --fresh inside a review loop, the new thread has NO memory of prior rounds. Do NOT send the short follow-up prompt — send the full first-round prompt PLUS a digest of prior rounds (ledger path, open ACCEPTED items, what was already fixed/rejected).
Note: orphan broker processes from prior crashed Claude Code sessions are now cleaned up automatically - the broker self-terminates within ~6 s of its parent dying (heartbeat in app-server-broker.mjs), and ensureBrokerSession reaps any leftover orphans (including legacy state files without parentPid) on startup. The --fresh workaround above addresses a different symptom: stale in-memory job state inside a still-alive broker after an interrupted task.
Never do
Agent(subagent_type="codex:codex-rescue", ...)— that subagent belongs to OpenAI's separately-installed codex plugin and silently auto-rejects in this terminal mode anyway. We do not require nor use it.Bash("codex exec ...")— silent auto-reject.- Call the old hardcoded path
~/.claude/plugins/cache/openai-codex/codex/.../codex-companion.mjs— we no longer depend on that plugin being installed. - Omit
--backgroundfor non-trivial prompts — appears to hang, user Esc's, counts as interrupt. - Print per-poll status from the Monitor loop — floods output, loop auto-stops.
Session paths (for debugging)
- Wrapper:
<plugin-root>/bin/codex-dispatch - Vendored companion:
<plugin-root>/vendor/codex-companion/scripts/codex-companion.mjs - Vendored companion version:
<plugin-root>/vendor/codex-companion/VERSIONand.claude-plugin/plugin.json - State + jobs + broker.sock:
~/.claude/plugins/data/superpowers-strigov-ver-codex/state/<workspace-slug>/ - Job log:
~/.claude/plugins/data/superpowers-strigov-ver-codex/state/<workspace-slug>/jobs/task-XXXX.log
ECONNREFUSED on the socket = broker not yet started; resolves on the first real task invocation.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

