home / skills / phrazzld / claude-config / refactor
This skill helps you streamline Python code by guiding clarity first and architecture second, reducing nesting and improving module depth.
npx playbooks add skill phrazzld/claude-config --skill refactorReview the files below or copy the command above to add this skill to your agents.
---
name: refactor
description: |
REFACTOR
effort: high
---
---
description: Two-pass code refinement - clarity then architecture
---
# REFACTOR
> "Simplicity is the ultimate sophistication." — da Vinci
## Philosophy
Fight entropy. Leave the codebase better than you found it.
Every shortcut becomes someone else's burden. Every hack compounds into technical debt. You are not just refactoring code—you are shaping the future of this project.
## Role
You are the senior engineer. Codex does the refactoring; you review and ship.
**Codex writes first draft. You review and ship.**
## Objective
Post-implementation refinement: simplify code, improve module depth.
## Process
### Codex Does the Refactoring
Delegate the actual refactoring to Codex:
```bash
codex exec "REFACTOR: Simplify [file/module]. Focus on clarity, naming, reduced nesting. Follow CLAUDE.md standards. Run pnpm typecheck after." \
--output-last-message /tmp/codex-refactor.md 2>/dev/null
```
Review what Codex produces. Fix issues if needed, then commit.
## Mission
Two-pass refinement:
1. **Clarity** — Simplify code without changing behavior
2. **Architecture** — Improve module depth and information hiding
## Phase 1: Simplification
Launch `code-simplifier:code-simplifier` agent.
Goals: clarity, naming, reduced nesting, consolidated logic, project standards from CLAUDE.md.
Commit: `refactor: simplify implementation`
## Phase 2: Deep Module Review
Launch `ousterhout` agent to review for Ousterhout's design principles.
Looking for:
- Shallow modules or pass-through methods
- Leaky abstractions exposing implementation details
- Change amplification risk (small change → many edits)
- Cognitive load issues (too much to hold in head)
If high-impact issues found:
1. Implement suggested refactorings
2. Commit: `refactor: improve module depth`
## Completion
Report what was simplified and any architectural improvements made.
This skill performs two-pass code refinement aimed at leaving the codebase cleaner and more maintainable. It combines an initial clarity pass to simplify implementation with a deeper architecture pass to improve module boundaries and information hiding. The output is a set of concrete edits and commit-ready changes with a short report of improvements.
The skill delegates the first pass to a code-simplifier agent that focuses on naming, reduced nesting, consolidation of logic, and adherence to project standards. A second pass uses an ousterhout-style reviewer to detect shallow modules, leaky abstractions, and change-amplifying structures, then applies higher-impact refactorings. Each pass produces commits with clear messages and a completion report describing what changed and why.
Will the refactor change behavior?
The first pass explicitly avoids behavioral changes; the architecture pass may introduce changes but only after tests pass and with clear review.
What commit messages are used?
The skill creates focused commits: 'refactor: simplify implementation' for the clarity pass and 'refactor: improve module depth' for architecture changes.