ai-skills-code-refactoring
Refactor code while preserving behavior through scoped coverage, duplication, complexity, CRAP-score, and convention gates.
Skill by fabian-barney
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/fabian-barney-ai-skills-code-refactoring
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.
About
Use cases: testing
Reviews
Write a reviewNo 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/ai-skills-code-refactoring
What's inside
- Skill name
ai-skills-code-refactoring- Description
- Refactor code while preserving behavior through scoped coverage, duplication, complexity, CRAP-score, and convention gates.
- License
- Apache-2.0
- Instructions
- 97 lines in SKILL.md · view on GitHub
Files (4)
- SKILL.md
- refactoring-status.md · examples/
- coverage-before-refactor.md · references/
- refactoring-order.md · references/
SKILL.md (first lines)
<!-- markdownlint-disable MD025 -->
# Purpose
Refactor code only after the affected behavior is protected, then improve the
bounded implementation without changing externally observable behavior.
# When to Use
- use when a user asks to refactor, simplify, clean up, or restructure existing
code while preserving current behavior
- use when a change primarily improves internal code quality rather than adding
new product behavior
- use `references/refactoring-order.md` for the mandatory refactoring sequence
and evidence expectations
- use `references/coverage-before-refactor.md` for the coverage-first rule and
acceptable justification when `100%` coverage is impossible
- use `examples/refactoring-status.md` when reporting scope, evidence, and
residual risks
- coordinate with skill `ai-skills-quality-cognitive-complexity`
when measuring or reducing cognitive complexity
- coordinate with skill `ai-skills-quality-crap` when
CRAP evidence exists
# Inputs
- the exact files, functions, methods, or modules requested for refactoring
- current behavior expectations, tests, fixtures, snapshots, or production
compatibility constraints
- strongest available coverage evidence for the scoped functions
- strongest available duplication, cognitive-complexity, CRAP, and convention
evidence for the scoped functions
- project-specific conventions, linters, formatters, and quality gates
- `references/refactoring-order.md`
- `references/coverage-before-refactor.md`
# Workflow
1. Identify the exact functions or methods being refactored and keep all rules
scoped to that bounded set.
2. Characterize current behavior from tests, fixtures, callers, contracts,
observed outputs, or user-provided examples before editing implementation.
3. Raise coverage for the scoped functions to `100%` using the strongest
available coverage metric before refactoring behavior-preserving code.
4. If `100%` scoped coverage is impossible, document the objective blocker and
the strongest substitute evidence before changing implementation.
5. Remove or reduce duplication in the scoped implementation without extracting
helpers that obscure domain intent.
6. Reduce cognitive complexity for each scoped function to `<= 15`, using
skill `ai-skills-quality-cognitive-complexity`
for evidence order and reduction tactics.
7. Reduce CRAP score for each scoped function to `<= 8` when CRAP evidence is
available, using skill `ai-skills-quality-crap`.
8. Apply the repository's code conventions, formatter, linter, and local helper
patterns after the structural refactor is complete.
9. Re-run the relevant tests and quality gates, then compare behavior evidence
before and after the refactor.
10. Use `examples/refactoring-status.md` when summarizing what changed, which
gates passed, and which objective constraints remain.
# Outputs
- behavior-preserving refactor changes scoped to the identified functions
- focused tests or documented equivalent evidence protecting current behavior
- reduced duplication, cognitive complexity `<= 15`, and CRAP score `<= 8`
where the relevant evidence is available
- final status that names the scoped functions, validation commands, metric
evidence, and any justified coverage or metric gaps
# Guardrails
- do not refactor unscoped functions as opportunistic cleanup
- do not change externally observable behavior unless the user explicitly
expands the task beyond refactoring
- do not reduce coverage, remove behavior assertions, or weaken tests to make a
refactor pass
- do not claim `100%` coverage, cognitive complexity, or CRAP results without
tool evidence or an explicit estimate label
- do not hide complexity in vague helpers, broad boolean flags, or duplicated
orchestration spread across new methods
- do not let formatting churn or unrelated convention cleanup dominate the diff
# Exit Checks
- the refactored functions are explicitly scoped and no unrelated behavior was
changed
- scoped behavior is protected by `100%` coverage or a documented objective
exception with strongest available substitute evidence
- duplication in the scoped implementation was removed or an objective reason
for retaining it is documented
- every scoped function is at cognitive complexity `<= 15` or has a failing
result with evidence
- every scoped function with CRAP evidence is at CRAP score `<= 8` or has a
failing result with evidence
- project conventions and quality gates have been applied after the structural
refactorFrom fabian-barney/ai-skills, Apache-2.0.
More from fabian-barney/ai-skills
- 0.502score
ai-skills-compliance-dependency
fabian-barney
Evaluate dependency additions and upgrades for compliance and governance risk.
SkillCFreshness: C★ 1Claude Code +9 - 0.499score
ai-skills-conventions-java
fabian-barney
Apply the default Java conventions by orchestrating the Java-specific leaf skills and the remaining Java baseline rules.
SkillCFreshness: C★ 1Claude Code +9 - 0.499score
ai-skills-bootstrap-ai-instructions
fabian-barney
Bootstrap the downstream ai-instructions layer for a repository by following the authoritative upstream setup source instead of copying or reinventing it…
SkillCFreshness: C★ 1Claude Code +9 - 0.499score
ai-skills-bootstrap-ci-pipeline
fabian-barney
Establish the initial CI pipeline for a project so build, lint, test, and policy checks run consistently from the start.
SkillCFreshness: C★ 1Claude Code +9 - 0.499score
ai-skills-bootstrap-project
fabian-barney
Orchestrate the initial project bootstrap by sequencing repository, instruction-layer, framework, CI, and documentation setup in dependency order.
SkillCFreshness: C★ 1Claude Code +9 - 0.499score
ai-skills-conventions-prompt-caching
fabian-barney
Structure prompts and skill bundles so the static prefix stays stable across invocations and Anthropic prompt-prefix caching can hit instead of rebuild.
SkillCFreshness: C★ 1Claude Code +9 - 0.499score
ai-skills-conventions-ternary
fabian-barney
Prefer simple ternary expressions over verbose if-else blocks when the choice is expression-shaped and side-effect-free.
SkillCFreshness: C★ 1Claude Code +9 - 0.496score
ai-skills-correctness-equals-hashcode
fabian-barney
Verify the equals/hashCode contract for touched Java equality code and check Comparable consistency when applicable.
SkillCFreshness: C★ 1Claude Code +9 - 0.496score
ai-skills-conventions-early-return
fabian-barney
Prefer early returns and guard clauses to keep exceptional paths explicit and the happy path linear.
SkillCFreshness: C★ 1Claude Code +9 - 0.496score
ai-skills-conventions-lombok
fabian-barney
Prefer Lombok for applicable Java boilerplate while keeping risky annotations and config choices explicit.
SkillCFreshness: C★ 1Claude Code +9 - 0.496score
ai-skills-conventions-null
fabian-barney
Enforce explicit null contracts, non-null collections by default, and fail-fast handling for illegal nulls.
SkillCFreshness: C★ 1Claude Code +9 - 0.496score
ai-skills-correctness-jpa
fabian-barney
Verify JPA entity equality and hashCode behavior, especially for unsaved entities with null primary keys.
SkillCFreshness: C★ 1Claude Code +9
Signals
- Stars
- 1
- Forks
- 0
- Open issues
- 2
- Last commit (this folder)
- May 2, 2026 (6 months ago)
- Last release
- Jun 2, 2026 (4 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- Apache-2.0
- Repository
- github.com/fabian-barney/ai-skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from fabian-barney
- 0.502score
ai-skills-compliance-dependency
fabian-barney
Evaluate dependency additions and upgrades for compliance and governance risk.
SkillCFreshness: C★ 1Claude Code +9 - 0.499score
ai-skills-bootstrap-ai-instructions
fabian-barney
Bootstrap the downstream ai-instructions layer for a repository by following the authoritative upstream setup source instead of copying or reinventing it…
SkillCFreshness: C★ 1Claude Code +9 - 0.499score
ai-skills-bootstrap-ci-pipeline
fabian-barney
Establish the initial CI pipeline for a project so build, lint, test, and policy checks run consistently from the start.
SkillCFreshness: C★ 1Claude Code +9 - 0.499score
ai-skills-bootstrap-project
fabian-barney
Orchestrate the initial project bootstrap by sequencing repository, instruction-layer, framework, CI, and documentation setup in dependency order.
SkillCFreshness: C★ 1Claude Code +9 - 0.499score
ai-skills-conventions-java
fabian-barney
Apply the default Java conventions by orchestrating the Java-specific leaf skills and the remaining Java baseline rules.
SkillCFreshness: C★ 1Claude Code +9 - 0.499score
ai-skills-conventions-prompt-caching
fabian-barney
Structure prompts and skill bundles so the static prefix stays stable across invocations and Anthropic prompt-prefix caching can hit instead of rebuild.
SkillCFreshness: C★ 1Claude Code +9
Cite this page
ai-skills-code-refactoring. Agent Mart. https://agentmart.dev/skills/fabian-barney-ai-skills-code-refactoring (last updated 2026-10-24)