Code Improver — Always-Active Review Skill
This skill is always active across chat, Cowork, and the standalone
scripts/code-improver.js CLI. Apply it whenever code is in scope.
Companion CLI: npm run review -- <file-or-directory>
Programmatic entry: require('./scripts/code-improver') → { reviewFile, reviewDirectory, formatReport }.
When to Engage
Engage automatically when any of the following is true:
- The user pastes code (any language) into the conversation.
- The user names a source file (
server/providers.js, main.py, etc.).
- The user asks to refactor, optimize, clean up, "make this better", review a PR/diff, or debug.
- Code appears in a tool result (file read, git diff, grep match) that is relevant to the task.
Do not engage when:
- The user explicitly asks for something else and the code is incidental (e.g. "just run this").
- The code is a one-line example purely for illustration.
- The user says "don't review" / "skip review" / "just do X".
The Three Lenses
Review every snippet through exactly these three lenses, in order:
1. Readability
- Naming: are identifiers self-explanatory at the point of use?
- Structure: function length, nesting depth, early returns vs. pyramids.
- Comments: absent where non-obvious? Redundant where obvious?
- Consistency: style matches surrounding code (spacing, quotes, casing)?
2. Performance
- Algorithmic: is there an O(n²) loop where O(n) would do? Repeated work inside a hot path?
- I/O: synchronous calls that should be async? Unbatched network/DB calls?
- Allocation: objects/arrays rebuilt every render/iteration? Regexes compiled in a loop?
- Memory: unbounded caches, leaks from retained closures or listeners.
3. Best Practices
- Correctness: off-by-one, null/undefined, error swallowing, race conditions.
- Security: injection (SQL / shell / XSS), hardcoded secrets, unsafe
eval, path traversal.
- Language idioms: uses the language's native constructs (JS:
for...of, optional chaining; Py: comprehensions, with).
- Testability: pure functions where possible, dependencies injected not imported in-place.
- Maintainability: dead code, duplicated blocks, magic numbers, missing types.
Output Format
For each issue found, produce exactly this block:
### <N>. <Short title> — <Readability | Performance | Best Practice>
**Why it matters:** <1–2 sentences. Concrete consequence, not abstract principle.>
**Current:**
```<lang>
<exact snippet from the source>
```
**Improved:**
```<lang>
<minimal rewrite that fixes the issue and nothing else>
```
After all issue blocks, end with a one-line summary:
Summary: <N> issues — <X> readability, <Y> performance, <Z> best-practice.
Rules for the output
- Minimum change. Do not rewrite code that isn't broken. One fix per block.
- Preserve behavior unless the behavior itself is the bug (then say so explicitly in "Why it matters").
- No speculative refactors. Don't introduce abstractions, configuration, or tests that weren't asked for.
- Rank by impact. Correctness/security issues first, then performance, then readability.
- If nothing is wrong, say so. Output:
No issues found — code is idiomatic and correct for its scope. Do not invent problems.
- Language tag the fences. Always use
js, ts, py, go, rs, sh, etc. — not bare .
Scope Discipline
- Review what was shown, not what you imagine. If the user pastes a function, don't critique the imagined caller.
- File-level review: at most 10 issues per file. If more exist, report the top 10 and note
<M> additional issues suppressed — ask to see them if wanted.
- Directory review (CLI): summarize per-file counts in a table, then show the top 5 highest-impact issues across the whole tree.
Edge Cases
- Generated code (bundler output, protobuf, migrations): skip readability lens, keep correctness/security.
- Tests: readability matters extra (tests are documentation); performance matters less.
- Config files (JSON/YAML/TOML): only flag schema or security issues, not "style."
- Unfamiliar language: if you are not confident in idiomatic patterns, say so and limit review to correctness/security.
Interaction with Other Skills
- If
clarifying-questions triggers (ambiguous request), ask questions first, then review.
- If
truthfinder flags a source (e.g. copy-pasted code from a questionable site), surface the classification before reviewing.
- Does not override user refusal: "don't review" means don't review, even though this skill is always-active.
1---2name: code-improver3description: Always-active code review skill. Whenever the user shares code — pasted, referenced by file path, or implied by a task — scan it for readability, performance, and best-practice issues. For each issue, explain *why* it matters, show the current snippet, and provide an improved version. Applies to in-chat review, Cowork sessions, and standalone CLI use via `npm run review`.4license: MIT5---67# Code Improver — Always-Active Review Skill89This skill is **always active** across chat, Cowork, and the standalone10`scripts/code-improver.js` CLI. Apply it whenever code is in scope.1112Companion CLI: `npm run review -- <file-or-directory>`13Programmatic entry: `require('./scripts/code-improver')` → `{ reviewFile, reviewDirectory, formatReport }`.1415---1617## When to Engage1819Engage automatically when any of the following is true:20- The user pastes code (any language) into the conversation.21- The user names a source file (`server/providers.js`, `main.py`, etc.).22- The user asks to refactor, optimize, clean up, "make this better", review a PR/diff, or debug.23- Code appears in a tool result (file read, git diff, grep match) that is relevant to the task.2425Do **not** engage when:26- The user explicitly asks for something else and the code is incidental (e.g. "just run this").27- The code is a one-line example purely for illustration.28- The user says "don't review" / "skip review" / "just do X".2930---3132## The Three Lenses3334Review every snippet through exactly these three lenses, in order:3536### 1. Readability37- Naming: are identifiers self-explanatory at the point of use?38- Structure: function length, nesting depth, early returns vs. pyramids.39- Comments: absent where non-obvious? Redundant where obvious?40- Consistency: style matches surrounding code (spacing, quotes, casing)?4142### 2. Performance43- Algorithmic: is there an O(n²) loop where O(n) would do? Repeated work inside a hot path?44- I/O: synchronous calls that should be async? Unbatched network/DB calls?45- Allocation: objects/arrays rebuilt every render/iteration? Regexes compiled in a loop?46- Memory: unbounded caches, leaks from retained closures or listeners.4748### 3. Best Practices49- Correctness: off-by-one, null/undefined, error swallowing, race conditions.50- Security: injection (SQL / shell / XSS), hardcoded secrets, unsafe `eval`, path traversal.51- Language idioms: uses the language's native constructs (JS: `for...of`, optional chaining; Py: comprehensions, `with`).52- Testability: pure functions where possible, dependencies injected not imported in-place.53- Maintainability: dead code, duplicated blocks, magic numbers, missing types.5455---5657## Output Format5859For each issue found, produce exactly this block:6061````62### <N>. <Short title> — <Readability | Performance | Best Practice>6364**Why it matters:** <1–2 sentences. Concrete consequence, not abstract principle.>6566**Current:**67```<lang>68<exact snippet from the source>69```7071**Improved:**72```<lang>73<minimal rewrite that fixes the issue and nothing else>74```75````7677After all issue blocks, end with a one-line summary:7879```80Summary: <N> issues — <X> readability, <Y> performance, <Z> best-practice.81```8283### Rules for the output84- **Minimum change.** Do not rewrite code that isn't broken. One fix per block.85- **Preserve behavior** unless the behavior itself is the bug (then say so explicitly in "Why it matters").86- **No speculative refactors.** Don't introduce abstractions, configuration, or tests that weren't asked for.87- **Rank by impact.** Correctness/security issues first, then performance, then readability.88- **If nothing is wrong, say so.** Output: `No issues found — code is idiomatic and correct for its scope.` Do not invent problems.89- **Language tag the fences.** Always use `js`, `ts`, `py`, `go`, `rs`, `sh`, etc. — not bare ``` ```.9091---9293## Scope Discipline9495- **Review what was shown, not what you imagine.** If the user pastes a function, don't critique the imagined caller.96- **File-level review:** at most 10 issues per file. If more exist, report the top 10 and note `<M> additional issues suppressed — ask to see them if wanted.`97- **Directory review (CLI):** summarize per-file counts in a table, then show the top 5 highest-impact issues across the whole tree.9899---100101## Edge Cases102103- **Generated code** (bundler output, protobuf, migrations): skip readability lens, keep correctness/security.104- **Tests:** readability matters extra (tests are documentation); performance matters less.105- **Config files (JSON/YAML/TOML):** only flag schema or security issues, not "style."106- **Unfamiliar language:** if you are not confident in idiomatic patterns, say so and limit review to correctness/security.107108---109110## Interaction with Other Skills111112- If `clarifying-questions` triggers (ambiguous request), ask questions **first**, then review.113- If `truthfinder` flags a source (e.g. copy-pasted code from a questionable site), surface the classification before reviewing.114- Does not override user refusal: "don't review" means don't review, even though this skill is always-active.