Sord

Untitled

Mar 3rd, 2026
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | Software | 0 0
  1. ---
  2. name: codex
  3. description: >
  4. Delegate code generation to Codex CLI so Claude writes zero code itself.
  5. ALWAYS use this skill when the user asks to create, modify, fix, refactor,
  6. or test code — even if they don't mention Codex. Trigger on: implementing
  7. features, adding endpoints, writing services or classes, creating tests,
  8. fixing bugs, refactoring, migrating code, adding models or entities,
  9. writing fakers/fixtures, adding DI registrations, creating middleware.
  10. Trigger if the task would require Claude to write more than 5 lines of code.
  11. Do NOT trigger for: read-only exploration, explaining code, architecture
  12. discussions, git/commit/push/PR operations, running tests, checking config,
  13. listing files, Jira/ticket management, CI/CD debugging, or trivial one-liner edits.
  14. ---
  15.  
  16. # Codex Delegate — Claude Orchestrates, Codex Implements
  17.  
  18. Claude's output tokens are expensive. Every line of code Claude generates
  19. costs ~5x more than it costs to read. The entire point of this skill is to
  20. shift code generation to Codex (which runs on its own token budget) so Claude
  21. spends its tokens only on thinking: planning, spotting gotchas, reviewing.
  22.  
  23. **Golden rule: Claude never writes code. Claude writes prompts for Codex.**
  24.  
  25. ## When to Delegate vs. Handle Directly
  26.  
  27. **Delegate to Codex** when the task involves generating or editing code —
  28. new files, classes, methods, tests, refactors, bug fixes, boilerplate.
  29.  
  30. **Handle directly** when no code generation is needed — reading files,
  31. planning, discussing architecture, git operations, running commands,
  32. trivial one-liner edits (a typo, a flag toggle, adding an import).
  33.  
  34. The threshold is low: if you'd write more than ~5 lines of code, delegate it.
  35.  
  36. ## The Orchestration Loop
  37.  
  38. ### 1. Minimal Context Gathering
  39.  
  40. Read just enough to write a good Codex prompt. Codex has full filesystem
  41. access via `-C` and its own skills, so it can discover patterns on its own.
  42.  
  43. Only read files to:
  44. - Identify the correct file paths to reference in the prompt
  45. - Spot gotchas (e.g., a method name that differs from what the user assumed)
  46.  
  47. Don't read the codebase "just in case." If there's a CLAUDE.md, skim it.
  48. If the user references a pattern file, glance at it to confirm the file
  49. path exists and the key method names are what the user thinks.
  50.  
  51. ### 2. Craft a Short Prompt
  52.  
  53. **Never include code in the prompt.** Point Codex to files and let it read
  54. them. Codex has the project open — it will explore.
  55.  
  56. Good prompt (~50 tokens):
  57. > Create src/Services/OrderService with a cancelOrder method.
  58. > Follow src/Services/UserService patterns. Read the Order model for
  59. > entity methods. Write tests first in tests/OrderServiceTests following
  60. > tests/UserServiceTests structure.
  61.  
  62. Bad prompt (~300 tokens):
  63. > Create OrderService. It must be a class with constructor taking
  64. > a DatabaseClient and a Logger. Store them as private fields.
  65. > The namespace is com.example.services. Add import for Entity
  66. > from models. Add import for DatabaseClient from db...
  67. > [50 more lines duplicating what's already in the reference file]
  68.  
  69. The short prompt works because Codex reads the existing service itself
  70. and copies the patterns. Claude saves ~250 output tokens per prompt.
  71.  
  72. ### 3. Execute via Codex CLI
  73.  
  74. **Always run codex exec in the foreground** — never in the background.
  75. Set a generous timeout so the Bash call blocks until Codex finishes.
  76.  
  77. **Command template:**
  78.  
  79. ```bash
  80. codex exec \
  81. -m gpt-5.3-codex \
  82. --config model_reasoning_effort="high" \
  83. --full-auto \
  84. --skip-git-repo-check \
  85. -C "<project-directory>" \
  86. "<prompt>" \
  87. 2>/dev/null
  88. ```
  89.  
  90. Use a Bash timeout of 120000ms (2 minutes) for simple tasks, 300000ms
  91. (5 minutes) for complex multi-file tasks.
  92.  
  93. **Sandbox modes:**
  94.  
  95. | Task type | Flags |
  96. |---|---|
  97. | Write or edit files (default) | `--full-auto` |
  98. | Analyze / review only | `-s read-only` |
  99. | Need network or system access | `-s danger-full-access` (ask user first) |
  100.  
  101. **Rules:**
  102. - Always `--config model_reasoning_effort="high"`.
  103. - Always `--skip-git-repo-check` (WSL paths may confuse git detection).
  104. - Always `2>/dev/null` to suppress thinking tokens from stderr.
  105. - Always `-C` to point at the project root.
  106. - Never `danger-full-access` without asking the user first.
  107. - Use `--full-auto` for implementation tasks (the normal case).
  108.  
  109. ### 4. Quick Review
  110.  
  111. After Codex finishes, verify the files were created/modified. Don't reread
  112. and analyze the code Codex wrote — just check:
  113.  
  114. - The expected files exist (quick `ls` or `glob`)
  115. - If tests were written, run them (the project's test command)
  116.  
  117. Keep the review to 1-2 sentences of output. If tests pass, the code is fine.
  118. If they don't, send a follow-up to Codex.
  119.  
  120. ### 5. Resume or Continue
  121.  
  122. To continue in the same Codex session:
  123.  
  124. ```bash
  125. echo "follow-up instructions" | codex exec --skip-git-repo-check resume --last 2>/dev/null
  126. ```
  127.  
  128. When resuming, don't repeat model/sandbox flags — the session inherits them.
  129.  
  130. ### 6. Brief Report
  131.  
  132. Tell the user what was done in one sentence. Example:
  133. "Codex created OrderService with cancelOrder + 5 tests, all passing."
  134.  
  135. Don't list what files were created, don't summarize the code, don't explain
  136. the implementation. The user can read the diff.
  137.  
  138. ## Iterative Development Pattern
  139.  
  140. For multi-step features, each Codex call is one focused task:
  141.  
  142. 1. **Claude** skims context, plans approach (minimal output)
  143. 2. **Codex** writes tests first (TDD)
  144. 3. **Claude** runs tests (should fail — red)
  145. 4. **Codex** implements the code
  146. 5. **Claude** runs tests (should pass — green)
  147. 6. **Claude** reports one-liner to user
  148.  
  149. ## Handling Codex Errors
  150.  
  151. If `codex exec` exits non-zero:
  152. 1. Remove `2>/dev/null` temporarily to see the error
  153. 2. Transient issue (network, timeout) → retry once
  154. 3. Config issue (wrong model, missing credentials) → tell the user
  155. 4. Bad code → send a corrective prompt to Codex
  156.  
  157. ## What Codex Already Knows
  158.  
  159. Codex has its own skills and instructions configured. Don't repeat
  160. language conventions or project patterns in the prompt — Codex will
  161. apply them automatically. Just reference the relevant files by path.
  162.  
Advertisement
Add Comment
Please, Sign In to add comment