Codex Delegate
Claude Code skill for using Codex CLI as an execution specialist for implementation-heavy coding work, multi-file refactors, and wrapper-based execution flows.
WenyuChiou · 已有 AI 审核记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add WenyuChiou/codex-delegate技能说明
name: codex-delegate description: Delegates implementation-heavy or repetitive coding work (batch edits, boilerplate, multi-file refactors with clear patterns, test scaffolding) from Claude to OpenAI Codex CLI. Use when token cost outweighs judgment cost. Trigger phrases include "delegate to codex", "let codex do this", "batch refactor across files", "scaffold tests for". Avoid for architecture, security review, or root-cause debugging. license: MIT compatibility: Designed for Claude Code. Portable across agentskills.io-compliant hosts; the wrapper script lives at /scripts/run_codex.sh — adapt the example path to your host's skills directory (e.g. ~/.claude/skills/codex-delegate/ on Claude Code, ~/.hermes/skills//codex-delegate/ on Hermes).
Codex Delegate Skill
Claude is the supervisor. Codex CLI runs the mechanical work. Claude plans, constrains scope, reviews the diff, and verifies outcomes.
Why use this instead of raw codex exec
This wrapper is not cosmetic. It exists because every shipping task that bypasses it loses one of three things that have caused real incidents:
| What the wrapper handles | What raw codex exec costs you |
|---|---|
stdin closure (</dev/null) | Codex hangs indefinitely (issue #20919). One session hit a 25-minute zero-byte hang on 2026-05-14 because the supervising agent forgot the redirect. |
.result.json structured contract (status / risks / files_changed / tests_run) | You parse raw stdout. On a 10 MB log this is multi-thousand tokens of grep + interpretation per run. |
Brief template (references/task-template.md) | Codex drifts. F11 (over-applied a sweep rule to the meta-doc documenting the rule) and F12 (injected unrequested "Attributions: Karpathy, Simon Willison, ..." lines) both shipped from no-brief raw invocations. |
Token-saving ratios (directional dogfood data — measured treatment, ESTIMATED control)
From a 6-round mixed-workload session (awesome-agentic-ai-zh 2026-05-14, see agent-collab-skills/docs/measured-benefits.md). Honest methodology note (per that doc's own words): the delegated arm was measured (bytes/3 proxy), the Claude-inline control arm was "estimated, not measured, because we didn't run the control condition" — treat every ratio below as directional, not a precise multiplier. The 17-22× row was additionally produced on the since-retired gemini lane (R4 of that session) and has not been re-measured on Codex.
| Workload | Saving vs Claude-inline | When it applies to you |
|---|---|---|
| Mechanical sweep × 2 parallel (e.g., term replacement, § strip, doc renumber) | ~7× token reduction + caught 4 drift files | Repo with > 20 files needing the same edit |
| Mirror sync (zh-TW → zh-Hans + en, 8 files) | 17-22× token reduction | Multi-locale docs / curricula |
| Multi-file rename / typed-API migration | ~3× (extrapolated from Phase D title-sweep) | > 10 files following one pattern |
| Single-file < 50 line fix | ~1× (don't bother) | Use Claude direct Edit |
| Architecture / debugging / security review | 1× (skill cannot help) | Claude direct |
The wrapper helps for token-heavy mechanical work. It does not help for judgment-heavy work — be honest about which one your task is.
Anti-patterns this skill prevents
- F11: Codex over-applies a sweep rule to documentation describing that rule. Prevented by
agent-task-splitterbrief that explicitly lists in-scope files. - F14: Operator (Claude) defaults to
Bash("codex exec ...")despite the rule saying useSkill("codex-delegate"). Prevented by aPreToolUsehook on the operator side (template below). - Codex hang: 25-minute zero-byte run on 2026-05-14 because raw
codex execwas invoked without</dev/null. Prevented by wrapper's mandatory stdin closure.
CLAUDE.md snippet to enforce routing
Drop this into your ~/.claude/CLAUDE.md (or repo-level CLAUDE.md) to make the rule operational rather than aspirational:
## Codex routing rule (enforced)
For any task that is mechanical, multi-file, has a clear pattern, or
batch-edits ≥ 3 files (canonical tripwire: fable-style-project-harness/docs/codex-delegation-policy.md — single source; older ≥5 statements are superseded): invoke `Skill("codex-delegate", args="brief=...")`.
Do NOT use `Bash("codex exec ...")` for shipping tasks — it loses stdin
closure (codex hangs), the `.result.json` contract (no structured status),
and the brief template (Codex drifts F11/F12).
Optional mechanical enforcement: a PreToolUse hook on Bash that nudges raw
`codex exec` toward `Skill("codex-delegate")`. Reference implementation:
https://github.com/WenyuChiou/dotfiles-claude/blob/main/hooks/check_codex_skill_routing.py
→ The hook is non-blocking (warns only) so you can still run codex --version /
codex exec resume / codex exec review without friction. Replace return 0
with return 2 in the hook to make it block instead of warn.
Hard rules
- Before invoking the wrapper, run
codex --versionvia Bash. If it fails, stop and tell the user tonpm install -g @openai/codex. - When calling
codex execdirectly (not through the wrapper), close stdin explicitly (</dev/null); the wrapper handles this internally. - Wrapper run leaves machine-readable status at
<log-file>.result.json. Acceptance is Claude's job, not the wrapper's. - Do not wrap the wrapper in
Start-Process. Call it inline so file writes persist.
Brief discipline
The wrapper now enforces on-disk brief traceability (added 2026-05-15 after the research-hub v0.89.1 post-release audit caught 2 orphan results from inline --prompt dispatches with no brief on disk).
- Brief MUST be on disk before invoking the wrapper. Filename pattern:
.ai/codex_task_<NN_chronological_or_version>_<short_slug>.md(e.g.,.ai/codex_task_v090_paginated_hub.md). The brief is the audit record — if it's not on disk, post-hoc reconstructi