Clean Code rules are tools, not dogma. If strictly applying a rule makes the code harder to understand, less simple, or more complex overall — DO NOT apply it.
Before applying any rule, ask: "Does this change make the code easier to understand for the next developer?"
If the answer is NO or UNCERTAIN → skip the change, explain why.
Examples where NOT to apply Clean Code blindly:
- Extracting a 3-line helper function that will only ever be called once → adds indirection without clarity
- Renaming a well-understood abbreviation (
url, id, i) to a verbose name → noise, not clarity
- Splitting a simple 25-line function that reads naturally as a single block → fragmentation hurts comprehension
- Applying polymorphism to a switch with 2 cases that will never grow → over-engineering
- Extracting a boolean condition into a named function when the condition is already obvious
The goal is a codebase that any developer can read fluently. Rules serve that goal — not the other way around.
Audit existing code:
/clean-code src/features/auth
/clean-code src/services/user.service.ts
Auto mode (no confirmation):
/clean-code -a src/features/auth
Report only (no fixes applied):
/clean-code -r src/features/auth
Guide mode (during code writing):
/clean-code --guide
→ Loads principles into context to guide the current writing session.
| Flag |
Description |
-a |
Auto mode: apply all fixes without confirmation |
-e |
Economy mode: no subagents, direct tools only |
-r |
Report only: produce the report without applying fixes |
--guide |
Guide mode: load principles to guide code writing |
REVIEW mode (default)
Analyze existing code → identify violations → propose/apply fixes.
Workflow: step-01-analyze.md → step-02-fix.md
GUIDE mode (--guide)
Load Clean Code principles into context to guide a code writing session.
No multi-step workflow — act as an active reference while the agent writes.
In guide mode:
- Read
references/clean-code-principles.md
- Confirm: "Clean Code principles loaded. I'll apply naming, SOLID, DRY, small functions, and error handling rules — but only when they improve readability."
- While writing: proactively flag violations before committing code
| Variable |
Type |
Description |
{target} |
string |
File, feature or folder to analyze |
{auto_mode} |
boolean |
-a: apply without confirmation |
{economy_mode} |
boolean |
-e: no subagents |
{report_only} |
boolean |
-r: report only, no fixes |
{guide_mode} |
boolean |
--guide: writing mode |
| File |
When to load |
references/clean-code-principles.md |
Always — before any analysis or writing |
If --guide:
→ Load references/clean-code-principles.md + confirm guide mode. Done.
Otherwise:
→ Load steps/step-01-analyze.md
| Step |
File |
Purpose |
| 01 |
steps/step-01-analyze.md |
Read code, identify violations |
| 02 |
steps/step-02-fix.md |
Apply corrections |
Trigger this skill when:
- An agent just wrote new code →
/clean-code --guide before writing or review after
- Code reviewing a PR →
/clean-code src/features/xxx
- Refactoring an existing module →
/clean-code -a src/module
- Doubt about naming, function structure, or SOLID compliance
Principles covered:
- Intent-revealing naming (no magic numbers, consistent verb choices)
- Small functions, single responsibility, CQS, no hidden side effects
- Comments: when to write, when to delete
- DRY — duplicate elimination
- SOLID: SRP, OCP, LSP, ISP, DIP
- Law of Demeter — no train wrecks
- Error handling: exceptions vs return codes, never null
- Code smells: rigidity, fragility, needless complexity, Feature Envy, etc.
1---2name: clean-code3description: Analyze and fix code using Robert C. Martin's Clean Code principles — naming, functions, SOLID, DRY, code smells. Usable in review mode (audit) or guide mode (during code writing).4---56<objective>7Apply Robert C. Martin's Clean Code principles to make code readable, maintainable, and clean.8Two modes: audit existing code (review) or guide code writing (guide).9</objective>1011<prime_directive>12**READABILITY AND SIMPLICITY ALWAYS WIN.**1314Clean Code rules are tools, not dogma. If strictly applying a rule makes the code harder to understand, less simple, or more complex overall — DO NOT apply it.1516Before applying any rule, ask: "Does this change make the code easier to understand for the next developer?"17If the answer is NO or UNCERTAIN → skip the change, explain why.1819Examples where NOT to apply Clean Code blindly:20- Extracting a 3-line helper function that will only ever be called once → adds indirection without clarity21- Renaming a well-understood abbreviation (`url`, `id`, `i`) to a verbose name → noise, not clarity22- Splitting a simple 25-line function that reads naturally as a single block → fragmentation hurts comprehension23- Applying polymorphism to a switch with 2 cases that will never grow → over-engineering24- Extracting a boolean condition into a named function when the condition is already obvious2526**The goal is a codebase that any developer can read fluently. Rules serve that goal — not the other way around.**27</prime_directive>2829<quick_start>3031**Audit existing code:**32```bash33/clean-code src/features/auth34/clean-code src/services/user.service.ts35```3637**Auto mode (no confirmation):**38```bash39/clean-code -a src/features/auth40```4142**Report only (no fixes applied):**43```bash44/clean-code -r src/features/auth45```4647**Guide mode (during code writing):**48```bash49/clean-code --guide50```51→ Loads principles into context to guide the current writing session.5253</quick_start>5455<parameters>5657| Flag | Description |58|------|-------------|59| `-a` | Auto mode: apply all fixes without confirmation |60| `-e` | Economy mode: no subagents, direct tools only |61| `-r` | Report only: produce the report without applying fixes |62| `--guide` | Guide mode: load principles to guide code writing |6364</parameters>6566<modes>6768### REVIEW mode (default)69Analyze existing code → identify violations → propose/apply fixes.7071Workflow: `step-01-analyze.md` → `step-02-fix.md`7273### GUIDE mode (`--guide`)74Load Clean Code principles into context to guide a code writing session.75No multi-step workflow — act as an active reference while the agent writes.7677**In guide mode:**781. Read `references/clean-code-principles.md`792. Confirm: "Clean Code principles loaded. I'll apply naming, SOLID, DRY, small functions, and error handling rules — but only when they improve readability."803. While writing: proactively flag violations before committing code8182</modes>8384<state_variables>8586| Variable | Type | Description |87|----------|------|-------------|88| `{target}` | string | File, feature or folder to analyze |89| `{auto_mode}` | boolean | `-a`: apply without confirmation |90| `{economy_mode}` | boolean | `-e`: no subagents |91| `{report_only}` | boolean | `-r`: report only, no fixes |92| `{guide_mode}` | boolean | `--guide`: writing mode |9394</state_variables>9596<reference_files>9798| File | When to load |99|------|--------------|100| `references/clean-code-principles.md` | Always — before any analysis or writing |101102</reference_files>103104<entry_point>105106**If `--guide`:**107→ Load `references/clean-code-principles.md` + confirm guide mode. Done.108109**Otherwise:**110→ Load `steps/step-01-analyze.md`111112</entry_point>113114<step_files>115116| Step | File | Purpose |117|------|------|---------|118| 01 | `steps/step-01-analyze.md` | Read code, identify violations |119| 02 | `steps/step-02-fix.md` | Apply corrections |120121</step_files>122123<when_to_use>124125Trigger this skill when:126- An agent just wrote new code → `/clean-code --guide` before writing or review after127- Code reviewing a PR → `/clean-code src/features/xxx`128- Refactoring an existing module → `/clean-code -a src/module`129- Doubt about naming, function structure, or SOLID compliance130131**Principles covered:**132- Intent-revealing naming (no magic numbers, consistent verb choices)133- Small functions, single responsibility, CQS, no hidden side effects134- Comments: when to write, when to delete135- DRY — duplicate elimination136- SOLID: SRP, OCP, LSP, ISP, DIP137- Law of Demeter — no train wrecks138- Error handling: exceptions vs return codes, never null139- Code smells: rigidity, fragility, needless complexity, Feature Envy, etc.140141</when_to_use>142143<execution_rules>144- Always read `references/clean-code-principles.md` before analyzing or fixing145- **PRIME DIRECTIVE FIRST**: if a fix reduces overall readability or simplicity, skip it and explain why146- Never modify functional behavior — pure refactoring only147- Cite exact file:line for each violation148- Reference the exact principle (DRY, SRP, CQS, etc.) for each violation149- Do not invent patterns not present in the reference150- In review mode: propose fixes before applying (unless `-a`)151- In guide mode: proactively flag violations during writing152</execution_rules>153154<success_criteria>155- All violations identified with file:line + principle156- Code more readable, names that reveal intent157- Small functions, no hidden side effects158- SOLID respected where it genuinely improves the code159- No functional regression160- Clean TypeScript build after fixes161- Every skipped rule has an explicit reason ("skipped: would add indirection without clarity gain")162</success_criteria>