- How you use it
- You ask for it
- What it can do
- writes files
- What's inside
The option
| Option | ASkill · v1.0.0refactor skill (GitHub awesome-copilot) |
|---|---|
| How you use it | You ask for it |
| What it can do | writes files |
| What's inside |
What this thread does
The problem
You ask an agent to "refactor this legacy module to be cleaner". It produces tidy, modular code that does not behave like the old code, and you spend days finding what changed. Legacy code has no spec, sparse tests and load-bearing oddities.
What the post says
A r/ClaudeCode post by u/thewritingwallah (27 January 2026) describes refactoring about 50k lines of a Django monolith untouched for about four years. The author's claim, not independently checked: about 3 weeks instead of an estimated 2 to 3 months. The workflow:
1. Characterization tests first. Before any refactor, ask for tests that capture what the code does now. The author's prompt: generate minimal pytest characterization tests for a module, capture current outputs for realistic inputs, no behaviour changes. They spent the first four days only on this, covering the parts they were most afraid to touch. 2. A CLAUDE.md with boundaries. Sections for build and test commands, an architecture overview (which modules are coupled), refactoring guidelines (always run relevant tests, prefer incremental change, keep original signatures as wrappers when extracting) and hard rules: modules, migration files and base classes the agent must not modify without approval. The author notes CLAUDE.md files in subdirectories load when Claude touches that code, so module-specific edge cases go next to the module. Run /init to draft the project instructions, then refine the boundaries it discovers. Check /context all under Memory files to confirm the instructions loaded. 3. Small prompted steps. One task per prompt ("extract the discount calculation from Invoice.process() into a method"), run the matching tests, commit if green, debug before moving on if red. 4. Extra review. The author runs an AI review tool on every PR; one commenter called the post a long sales pitch for that tool, so weigh that part accordingly.
Where it breaks down, per the author: context gets long (they restart with handoff documents), the agent still invents APIs, and architecture decisions remain human work.
What commenters added
- Several said the whole point is tests before refactoring; one said you would probably find a bug while writing them.
- One suggested snapshot (approval) testing, for example the Verify libraries, to prove byte-for-byte identical output before and after.
- One asked whether hooks that run tests and block edits to protected files beat CLAUDE.md rules; the author's answer is not in the part of the thread I read.
- Another stressed planning and a progress-tracking file, and small commits.
How to ask your agent
Do not change any code yet. For billing/invoice.py, write pytest characterization tests that record current outputs for realistic inputs, including the awkward ones. Run them and show me they pass on the unchanged code. Then I will give you refactor steps one at a time; after each, run these tests and stop if anything fails.
Mistakes to check
- Tests generated from the new code instead of the old: always run them on the untouched code first.
- Characterization tests that only assert "no exception". Ask for exact outputs.
- Letting the agent edit the tests to get green during a refactor.
- Rules that only live in CLAUDE.md: for must-not-touch files, a permission deny rule or hook is enforcement. Register the blocking script as a
PreToolUsehook in.claude/settings.jsonforEditandWritecalls.
Limits
Not run by me. A single self-reported result on one codebase.
Primary source
Primary source: Claude Code memory docs (Anthropic). Checked: CLAUDE.md and CLAUDE.local.md files in subdirectories load on demand once Claude reads, writes or edits a file in that subdirectory, which matches the post's point about module-specific notes; Claude treats CLAUDE.md as context rather than enforced configuration and the docs point to a PreToolUse hook to block an action, which supports the thread's advice to enforce must-not-touch files with a hook or deny rule. Not verified: everything specific to the r/ClaudeCode post (the 50k-line Django monolith, the 3 weeks versus 2 to 3 months, four days of tests, vote counts), the commenters' remarks, and the refactor skill package; no vendor or maintainer source exists for those.
Started from a post by @thewritingwallah, packaged by the editor. Original post
- 01 · YouPaste the line from Try it into your agent.
- 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
- 03 · YouApprove a one-line report. Nothing is posted without you.