refactor
Use Codex CLI to refactor a module, file, or code pattern. Use when you want an independent take on how to restructure complex or tangled code.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Codex Refactor
Use Codex CLI to analyze code and apply a refactor.
1) Build the prompt
From the user's request, construct a prompt for Codex that includes:
- The target (file, module, pattern, or concept to refactor)
- The goal (simplify, extract, decouple, rename, restructure, etc.)
- Any constraints (preserve API, maintain backwards compat, etc.)
2) Run Codex
Log output to a tmp directory:
CODEX_DIR="$(mktemp -d)/codex-refactor"
mkdir -p "$CODEX_DIR"
codex --sandbox danger-full-access -a never exec "$PROMPT" | tee "$CODEX_DIR/refactor.log"
3) Follow response contract
Structure the response as:
- Current state — what the code looks like now and why it's problematic
- Changes applied — what was changed, with file paths and line references
- Trade-offs — what improves, what gets more complex, what might break
After Codex finishes, review the changes and run tests to verify nothing broke.
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-03-11
- Index updated
- 2026-03-11
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!