No. 097 Lower the entropy

Refactor Assistant

Use when the code works but the structure is harder than the behavior

  • Claude Code
  • Codex
  • Cursor
  • Lower the entropy

Prompt

# Refactor Assistant

Please help me refactor code systematically using a structured approach:

## 1. Define the Refactoring
First, clearly identify:
- **What**: The specific code/pattern to refactor
- **Why**: The reason for refactoring (maintainability, performance, etc.)
- **Scope**: Which parts of the codebase are affected

## 2. Discovery Phase
Use search tools to find all occurrences:
```bash
# Find direct usage
chs find-code "ExactPatternName"

# Find imports/requires
chs search-imports "module-name"

# Find similar patterns
chs search-function "functionName"
chs search-class "ClassName"

# Find test files
chs find-file "*.test.*" | xargs grep -l "PatternName"
```

## 3. Impact Analysis
- List all files that need changes
- Identify potential breaking changes
- Check for external dependencies

## 4. Migration Plan
Create a step-by-step plan:
1. Update core implementation
2. Update imports/exports
3. Update all usages
4. Update tests
5. Update documentation

## 5. Execute Changes
For each file:
- Make the change
- Verify with your project's linter/type checker
- Run related tests
- Commit changes with meaningful messages

## 6. Verification
After all changes:
- Run full test suite
- Check for type/lint errors
- Verify no broken imports
- Review all changes

## 7. Documentation
Update any affected:
- README files
- API documentation
- Code comments
- Migration guides for breaking changes

Track progress and ensure nothing is missed!

When to use

“Refactor Assistant” fits when the code works but the structure is harder than the behavior, because it says “Refactor Assistant”, and its first written step is “Update core implementation”.

For “Refactor Assistant”, the extra line you type is the requirement those steps ask for, for example “make src/cart.js return 0 on an empty cart and skip a line with no price”, and the file then starts at “Update core implementation”.

When not to use

Leave “Refactor Assistant” unused when the change is a one-line typo or a red build you have not read, because “Refactor Assistant” points the other way

How to run it

Claude Code

Claude Code stores “Refactor Assistant” as a Claude command and runs it with that command, putting the requirement in the argument, and CLAUDE.md should not also carry “Refactor Assistant”.

Codex

Codex takes “Refactor Assistant” as a paste above the task. Leave AGENTS.md unchanged so the next thread does not inherit “Refactor Assistant”.

Cursor

Cursor should see “Refactor Assistant” only as a chat paste of “Refactor Assistant” for this turn. A file at .cursor/rules would keep applying after the turn ends.

Comparison

Without “Refactor Assistant”, the model only said to replace the file with one function. With “Refactor Assistant”, it followed that command's own headings: what, why, and scope, then a defect table, then the corrected file.

Related

来源:Darin Cassler · https://github.com/cassler/awesome-claude-code-setup/blob/main/commands/refactor-assistant.md · MIT · Copyright (c) 2025 Darin Cassler · 2026-12-01