code-polish — Claude Code skill: simplify and review code
A skill that walks the changed files, simplifies code without touching behavior, and fixes defects ranked by risk. Handy right after a big edit.
npx skills add PaulRBerg/agent-skills --skill code-polish -a claude-codeWhat code-polish does
Two modes: --simplify only simplifies, --review only reviews and fixes. Pass neither or both and the skill simplifies first, then reviews the simplified result. Review profiles come in with --with-profile <name> and go out with --skip-profile <name>; skip wins on conflict.
Scope is resolved once and never widened. A Git repository is required. Explicit paths, patterns, ranges or a supplied resolved-scope block are used as given; otherwise the skill takes files modified in this session, and falls back to all uncommitted tracked and untracked files when session history is unavailable. Lockfiles, generated output, vendored code, minified bundles and large data snapshots stay out of manual review unless you ask for them. An empty scope stops the run.
Simplification preserves public contracts, inputs and outputs, side effects, error behavior and operational guards. Only changes with a real payoff in comprehension or defect risk land: flattened nesting, clearer names, genuine duplication, tighter local types. Splitting by line count, architecture cleanup, sync/async API swaps and speculative configurability are off the table. A no-op is a valid outcome. Profiles live at references/profiles/<name>.md, and a missing selected profile is a stop condition — worth checking that the references directory came over in full.
What it helps with
- flatten needless nesting in a function you just wrote
- find defects in the diff and fix them by rising risk
- check changed files for resource leaks and test gaps
- review Go or Rust code against its language profile
- get a report with evidence for every finding
Example prompts for the agent
- /code-polish --simplify src/
- /code-polish --review --with-profile security
- /code-polish src/api src/db --skip-profile naming
How to install code-polish
1Skills CLI (Vercel)
npx skills add PaulRBerg/agent-skills --skill code-polish -a claude-code2Manually: put the files in place
~/.claude/skills/code-polish/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/code-polish/
1Skills CLI (Vercel)
npx skills add PaulRBerg/agent-skills --skill code-polish -a codex2Manually: put the files in place
.agents/skills/code-polish/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add PaulRBerg/agent-skills --skill code-polish -a cursor2Manually: put the files in place
.cursor/skills/code-polish/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install PaulRBerg/agent-skills code-polish2Manually: put the files in place
.github/skills/code-polish/SKILL.md1Skills CLI (Vercel)
npx skills add PaulRBerg/agent-skills --skill code-polish -a gemini-cli2Platform CLI
gemini skills install https://github.com/PaulRBerg/agent-skills --path skills/code-polishManually: put the files in place
.devin/skills/code-polish/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add PaulRBerg/agent-skills --skill code-polish -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about code-polish
How do I install code-polish in Claude?
Run npx skills add PaulRBerg/agent-skills --skill code-polish -a claude-code. The skill lands at ~/.claude/skills/code-polish/SKILL.md.
What does code-polish do?
It simplifies changed code and reviews it, fixing defects ranked from CRITICAL down to LOW. It finishes by running the narrowest formatter, targeted tests and invariant checks.
What does code-polish need to run?
A Git repository and the selected review profiles at references/profiles/<name>.md. If a selected profile is missing, the skill stops.
Source text
SKILL.md · MIT
--- argument-hint: "[paths] [--simplify] [--review] [--with-profile <name>] [--skip-profile <name>]" name: code-polish description: "Polish changed code when the user explicitly asks, or when an active workflow requests post-implementation simplification and risk-profiled review over a fixed file scope." --- # Code Polish Resolve scope once. Make only high-confidence simplifications. Fix defects supported by evidence according to their risk. Verify the final state. ## Modes - `--simplify`: simplify only. - `--review`: review and fix only. - Neither or both: simplify, then review the simplified result. - `--with-profile <name>` / `--skip-profile <name>`: add or suppress review profiles. Skip wins. ## Fixed Scope 1. Require a Git repository. 2. Use explicit paths, patterns, ranges, natural-language targets, or a supplied `resolved-scope` block when present. Otherwise, use only files modified in this session. If session history is unavailable, use all uncommitted tracked and untracked files. 3. Exclude lockfiles, generated outputs, vendored code, minified bundles, and large data snapshots from manual review unless explicitly requested. Validate relevant excluded outputs through their generator, schema, or invariants. 4. Resolve and retain one authoritative scope set and optional exclusions for execution. Do not broaden or recompute scope later. Stop if it is empty. ## Simplify Preserve public contracts, inputs, outputs, side effects, error behavior, performance-sensitive characteristics, telemetry, and operational guards. Apply only changes with a concrete comprehension or defect-risk benefit: - flatten avoidable control-flow nesting. - clarify misleading names or dense transforms. - remove real duplication when the abstraction reduces total complexity. - tighten local types and contracts without broad churn. - remove only dead code caused by this session's edits. Do not split by line count, perform architecture cleanup, convert sync/async APIs, add speculative configurability, or replace readable duplication with a one-use abstraction. A no-op is a valid result. ## Review and Fix Judge the diff against the user's request. Prioritize `CRITICAL → HIGH → MEDIUM → LOW`: - **CRITICAL**: exploitable security, data loss, or critical outage path. - **HIGH**: behavior, error-path, boundary, or performance defect affecting core behavior. - **MEDIUM**: resource leak, complexity hotspot, test gap, over-scoped change, speculative complexity, or weak success criterion likely to cause defects. - **LOW**: localized clarity or style issue with a real maintenance cost. Every finding must cite a verified location, triggering input/state, failure mode, blast radius, and evidence in the changed code. Merge duplicates and apply the smallest defensible fix. Resolve ambiguous intent from the request and repository first. State routine assumptions. Ask only when the answer changes behavior or scope. While that item waits, continue independent in-scope fixes. Select every applicable profile and read it once. Read all selected profiles together in one parallel turn: | Surface | Profile | | ------------------------------------------------------------- | ----------------------- | | auth, secrets, crypto, external input/network, unsafe parsing | `security` | | env, config, timeouts, retries, pools, limits | `configuration` | | Go behavior, concurrency, context, errors | `go` | | Rust, Cargo/workspaces, async/concurrency, unsafe/FFI | `rust` | | TypeScript types, modules, packages, async behavior | `typescript` | | Python services, scripts, async, packaging, data IO | `python` | | shell, CI, deploy, installers, quoting | `shell` | | CSV/JSON/YAML/binary, schemas, migrations, generated data | `data-formats` | | naming and intent clarity | `naming` unless skipped | Profiles live at `references/profiles/<name>.md`. Missing selected profiles are a stop condition. ## Verification and Report Run the narrowest formatter/lint, targeted tests, typecheck, and invariant checks that prove the final touched behavior. Broaden only for shared contracts. Name skipped checks and why. Summarize scope with the file count and smallest useful repository-relative roots, globs, ranges, or user-supplied targets. Do not enumerate every file merely to prove scope. Name individual paths only for a small explicit scope or to clarify exceptions and findings. Findings include severity, location, impact, evidence, fix, and confidence. A residual risk states the assumption, consequence if wrong, and how to check it. Under `Issues and caveats`, group verified fixes with evidence as `Resolved`, and remaining problems, limitations, or unverified assumptions as `Open`, with their impact and next step. Omit empty groups. Report each item once. Put neutral context and agreed decisions under changes or scope. Reserve `blocker` for something preventing required work and `risk` for a specific potential adverse outcome. A workaround leaves an item open when the underlying issue still affects the result. Completion requires fixed scope, traceable edits/findings, and validation evidence. Lead a successful report with `### ✨ Code polish — ✅ complete`, then summarize scope, meaningful changes, and verification. For small results, use short prose. Add tables or sections only when they clarify multiple changes or findings. Honor the user's requested format. When review ran and found no defects, state `✅ No verified review findings.` If a stop condition below prevents completion, lead with `### ✨ Code polish — ⛔ blocked` and report the evidence and required decision. Keep severity tokens, profile IDs, commands, locations, reproduction inputs, and security evidence exact and undecorated. Stop when behavior parity or required high-risk validation cannot be established, or a fix requires an unrequested public-contract change or larger redesign.
© PaulRBerg · MIT · PaulRBerg/agent-skills