Improves code quality across duplication, efficiency, and architectural fit. Use when code passes tests but quality is poor or before a major release.
npx skills add https://github.com/athola/claude-night-market --skill code-refinement
Analyze and improve living code quality across six dimensions.
/refine-code
/refine-code --level 2 --focus duplication
/refine-code --level 3 --report refinement-plan.md
dead/unused code (use conserve:bloat-detector)
| # | Dimension | Module | What It Catches |
|---|-----------|--------|----------------|
| 1 | Duplication & Redundancy | duplication-analysis | Near-identical blocks, similar functions, copy-paste |
| 2 | Algorithmic Efficiency | algorithm-efficiency | O(n^2) where O(n) works, unnecessary iterations |
| 3 | Clean Code Violations | clean-code-checks | Long methods, deep nesting, poor naming, magic values |
| 4 | Architectural Fit | architectural-fit | Paradigm mismatches, coupling violations, leaky abstractions |
| 5 | Anti-Slop Patterns | clean-code-checks | Premature abstraction, enterprise cosplay, hollow patterns |
| 6 | Error Handling | clean-code-checks | Bare excepts, swallowed errors, happy-path-only |
| 7 | Additive Bias | imbue:justify | Workarounds over root fixes, test tampering, unnecessary additions |
Detection patterns for plugin and skill codebases where
standard code quality heuristics miss structural issues.
A skill that declares "delegates to X" but still carries the
full template body is doing double duty. The delegating skill
should be a thin wrapper (under 30 lines) that routes to the
target. Flag any delegating skill whose body exceeds 50 lines.
Flag skills with 10+ module files where 40% or more of content
overlaps. Signal: two modules covering the same API surface
from different angles (e.g., both describing the same config
options or the same CLI flags).
Flag individual module files exceeding 500 lines as candidates
for splitting or trimming. Large modules defeat progressive
loading by forcing full-file reads for partial information.
Skills referencing Python commands (python -m module.name or
python -c "from module import ...") where the referenced
module does not exist in the plugin's src/ directory. These
are stale references to renamed or removed code.
Load modules based on refinement focus:
modules/duplication-analysis.md (~400 tokens): Duplication detection and consolidationmodules/algorithm-efficiency.md (~400 tokens): Complexity analysis and optimizationmodules/clean-code-checks.md (~450 tokens): Clean code, anti-slop, error handlingmodules/architectural-fit.md (~400 tokens): Paradigm alignment and couplingLoad all for thorough refinement. For focused work, load only relevant modules.
refine:context-established: Scope, language, framework detectionrefine:scan-complete: Findings across all dimensionsrefine:prioritized: Findings ranked by impact and effortrefine:plan-generated: Concrete refactoring plan with before/afterrefine:evidence-captured: Evidence appendix per imbue:proof-of-workrefine:findings-verified: Citations confirmed by citation_verifier.pyrefine:execution-complete: All wave-listed candidates closed-or-rationale'd (only required when invocation includes "execute findings" or stronger; see Step 6)refine:context-established)Detect project characteristics:
# Language detection
find . -not -path "*/.venv/*" -not -path "*/__pycache__/*" \
-not -path "*/node_modules/*" -not -path "*/.git/*" \
\( -name "*.py" -o -name "*.ts" -o -name "*.rs" -o -name "*.go" \) \
| head -20
# Framework detection
ls package.json pyproject.toml Cargo.toml go.mod 2>/dev/null
# Size assessment
find . -not -path "*/.venv/*" -not -path "*/__pycache__/*" \
-not -path "*/node_modules/*" -not -path "*/.git/*" \
\( -name "*.py" -o -name "*.ts" -o -name "*.rs" \) \
| xargs wc -l 2>/dev/null | tail -1
refine:scan-complete)Load relevant modules and execute analysis per tier level.
For dimension 7 (Additive Bias), run Skill(imbue:justify)
to compute the bias score, check Iron Law compliance,
and flag unnecessary additions or workarounds.
refine:prioritized)Rank findings by:
Priority = HIGH impact + SMALL effort + LOW risk first.
refine:plan-generated)For each finding, produce:
refine:evidence-captured)Document with imbue:proof-of-work (if available):
[E1], [E2] references for each findingFallback: If imbue is not installed, capture evidence inline in the report using the same [E1] reference format without TodoWrite integration.
refine:execution-complete)Steps 1-5 produce a plan. Steps 6 produces closures. Both are part of the skill. Execution does not stop at planning unless the user explicitly says "plan only".
Match the user's invocation phrasing against this table to determine execution scope:
| User said | Mode | Stop when |
|---|---|---|
| /code-refinement (no qualifier) | Plan only | After Step 5 |
| --dry-run or "just plan" | Plan only | After Step 5 |
| "execute findings" / "apply fixes" | Plan, execute Wave 1 | After all SMALL-effort, and LOW-risk findings closed |
| "execute all findings" / "all phases" / "all waves" | Plan and execute every wave | After every finding (or every wave-listed candidate) is either closed by commit or has explicit per-item rationale in the synthesis |
| "ignore scope guard" | Override branch-size limits | Branch metrics do not gate execution. Continue past RED zone. |
| "do not stop until complete" / "until ALL ... complete" | No mid-task summaries | Only declare done when synthesis has every wave-listed candidate closed-or-rationale'd |
The triggers compose: --tier 3 --execute all findings --ignore-scope-guard means run every Wave 2 and Wave 3 candidate to closure regardless of branch size.
The task is not complete until ALL of the following hold:
docs/refinement/<date>/00-synthesis.md records every closure with its commit SHA and every deferral with one-sentence rationale.If the model finds itself doing any of the following during execution, this is a stop-hook leak. Go back to executing findings:
| Anti-pattern | Recognise as |
|---|---|
| "Wave 2 closed. Moving to Wave 3." (mid-run summary) | Premature turn-completion signal: keep working |
| "Documenting deferred items with rationale" before all mechanical items are done | Skipping execution under a paper trail |
| Writing a completion summary while >0 listed candidates lack closure-or-rationale | Violation of completion gate |
| Re-asking user "should I continue?" when invocation included "do not stop" | Ignoring the explicit no-mid-task-summary contract |
If the harness fires a stop signal mid-execution and the completion gate is not met, immediately resume with the next finding.
refine:findings-verified)Every finding must cite a real location and a verbatim anchor. Write
findings to .review/findings.json and confirm each citation resolves:
python plugins/imbue/scripts/citation_verifier.py \
--findings .review/findings.json --repo-root .
Drop or label UNVERIFIED any finding the verifier fails (exit 1); only
verified findings enter the report. See Skill(imbue:review-core) Step 5
and Skill(imbue:structured-output) for the schema.
detected") for the target scope.
Anchor (the exact source text at that line).
Location + verbatim Anchorconfirmed by citation_verifier.py (exit 0), or unverified
findings were dropped or labeled UNVERIFIED.
| Tier | Time | Scope |
|------|------|-------|
| 1: Quick (default) | 2-5 min | Complexity hotspots, obvious duplication, naming, magic values |
| 2: Targeted | 10-20 min | Algorithm analysis, full duplication scan, architectural alignment |
| 3: Deep | 30-60 min | All above and cross-module coupling, paradigm fitness, thorough plan |
| Dependency | Required? | Fallback |
|------------|-----------|----------|
| imbue:proof-of-work | Optional | Inline evidence in report |
| conserve:code-quality-principles | Optional | Built-in KISS/YAGNI/SOLID checks |
| archetypes:architecture-paradigms | Optional | Principle-based checks only (no paradigm detection) |
When optional plugins are not installed, the skill degrades gracefully:
imbue: Evidence captured inline, no TodoWrite proof-of-workconserve: Uses built-in clean code checks (subset)archetypes: Skips paradigm-specific alignment, uses coupling/cohesion principles onlyExecute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical grouping
Comprehensive GitHub code review with AI-powered swarm coordination
Create high-quality git commits: review/stage intended changes, split into logical commits, and write clear commit messages (including Conventional Commits). Use when the user asks to commit, craft a commit message, stage changes, or split work into multiple commits.
Comprehensive truth scoring, code quality verification, and automatic rollback system with 0.95 accuracy threshold for ensuring high-quality agent outputs and codebase reliability.
GitHub CLI (gh) comprehensive reference for repositories, issues, pull requests, Actions, projects, releases, gists, codespaces, organizations, extensions, and all GitHub operations from the command line.
GitHub CLI - manage repositories, issues, pull requests, actions, releases, and more from the command line.
You are a code refactoring expert specializing in clean code principles, SOLID design patterns, and modern software engineering best practices. Analyze and refactor the provided code to improve its quality, maintainability, and performance.
You are a technical debt expert specializing in identifying, quantifying, and prioritizing technical debt in software projects. Analyze the codebase to uncover debt, assess its impact, and create acti
Take athola/code-refinement from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.