Skip to content
Agentmart
Submit a tool

refactor

Safe, systematic refactoring workflow — same behavior, better structure

Skill by Hbin77

IndexedMIT
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/hbin77-refactor

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Safe, systematic refactoring workflow — same behavior, better structure

Use cases: productivity

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/refactor

What's inside

Skill name
refactor
Description
Safe, systematic refactoring workflow — same behavior, better structure
License
MIT
Instructions
67 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

Execute a safe, systematic refactoring workflow on the target scope.

Task: the task/scope the user described when invoking this skill (if none given, ask or infer from context)

## Phase 1: Analysis
Do the analysis yourself:
- **Code smells** (see `~/.codex/skills/code-smells`): long functions, deep nesting, duplication, large classes, long parameter lists, feature envy, primitive obsession, dead code.
- **Dependencies & coupling**: map module dependency direction, identify tight coupling and leaf vs core modules.
Synthesize into a unified findings list.

## Phase 2: Refactoring Plan
Present findings with severity ratings. Create a **safe refactoring order** based on:
1. Dependency direction (leaf modules first, core last)
2. Test coverage (well-tested first; untested code needs characterization tests first)
3. Risk level (pure functions → utilities → business logic → public API)

Each step specifies: target file(s), smell addressed, refactoring pattern (Extract Method, Move Function, Replace Conditional with Polymorphism, etc.), and that behavior MUST remain identical.

**Wait for user approval before proceeding.**

## Phase 3: Test Baseline
1. Run the full test suite → record baseline pass count.
2. If no tests exist for target code, write characterization tests first.
3. Store baseline: `build PASS | lint PASS | test X/Y PASS`.

## Phase 4: Execution
For each approved step:
1. Apply ONE refactoring pattern at a time.
2. Run build + lint + test immediately after.
3. Tests fail → revert that step and report. Never fix forward.
4. Tests pass → commit atomically (`refactor(scope): pattern applied`) → next step.
Execute sequentially in leaf → root order (dependent modules strictly sequential).

## Phase 5: Verification
Run full build + lint + full test suite. Compare test count: baseline vs current (must be equal or greater).
Distinguish failure cause:
- **Breakage caused by a refactoring step** (green before, now fails) → revert that step immediately.
- **Pre-existing failures or environment/build issues unrelated to the refactor** → fix separately (root-cause, minimal diffs), don't revert refactoring.

## Phase 6: Review
Review the refactoring yourself: verify (1) no behavior changes, (2) improved structure, (3) no regressions.

## Phase 7: Report
```
## Refactoring Report
### Before → After
| Metric | Before | After |
| Files changed / Lines removed / Lines added / Avg function length / Max nesting / Test count |
### Applied Refactorings
| # | Pattern | Target | Result |
### Smells Resolved
- [x] ...
### Remaining (deferred)
- [ ] ... — reason
### Verification
Build: PASS | Lint: PASS | Tests: X/Y PASS
```

## Rules
- NEVER change behavior. Refactoring = same behavior, better structure.
- ONE pattern per commit — easy to revert.
- TEST FIRST. No refactoring without a green baseline.
- If a step breaks a previously-green test, revert that step immediately — don't fix forward.
- Don't refactor code you don't understand. Read it first.
- Preserve public API unless the user explicitly approves breaking changes.

From Hbin77/codex-kit, MIT.

More from Hbin77/codex-kit

Signals

Stars
0
Forks
0
Open issues
0
Last commit (this folder)
Aug 7, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Hbin77

Cite this page

refactor skill. Agent Mart. https://agentmart.dev/skills/hbin77-refactor (last updated 2026-10-24)