Clean Code - Pragmatic AI Coding Standards
CRITICAL SKILL - Be concise, direct, and solution-focused.
Core Principles
| Principle |
Rule |
| SRP |
Single Responsibility - each function/class does ONE thing |
| DRY |
Don't Repeat Yourself - extract duplicates, reuse |
| KISS |
Keep It Simple - simplest solution that works |
| YAGNI |
You Aren't Gonna Need It - don't build unused features |
| Boy Scout |
Leave code cleaner than you found it |
Naming Rules
| Element |
Convention |
| Variables |
Reveal intent: userCount not n |
| Functions |
Verb + noun: getUserById() not user() |
| Booleans |
Question form: isActive, hasPermission, canEdit |
| Constants |
SCREAMING_SNAKE: MAX_RETRY_COUNT |
Rule: If you need a comment to explain a name, rename it.
Function Rules
| Rule |
Description |
| Small |
Max 20 lines, ideally 5-10 |
| One Thing |
Does one thing, does it well |
| One Level |
One level of abstraction per function |
| Few Args |
Max 3 arguments, prefer 0-2 |
| No Side Effects |
Don't mutate inputs unexpectedly |
Code Structure
| Pattern |
Apply |
| Guard Clauses |
Early returns for edge cases |
| Flat > Nested |
Avoid deep nesting (max 2 levels) |
| Composition |
Small functions composed together |
| Colocation |
Keep related code close |
AI Coding Style
| Situation |
Action |
| User asks for feature |
Write it directly |
| User reports bug |
Fix it, don't explain |
| No clear requirement |
Ask, don't assume |
Anti-Patterns (DON'T)
| ❌ Pattern |
✅ Fix |
| Comment every line |
Delete obvious comments |
| Helper for one-liner |
Inline the code |
| Factory for 2 objects |
Direct instantiation |
| utils.ts with 1 function |
Put code where used |
| "First we import..." |
Just write code |
| Deep nesting |
Guard clauses |
| Magic numbers |
Named constants |
| God functions |
Split by responsibility |
🔴 Before Editing ANY File (THINK FIRST!)
Before changing a file, ask yourself:
| Question |
Why |
| What imports this file? |
They might break |
| What does this file import? |
Interface changes |
| What tests cover this? |
Tests might fail |
| Is this a shared component? |
Multiple places affected |
Quick Check:
File to edit: UserService.ts
└── Who imports this? → UserController.ts, AuthController.ts
└── Do they need changes too? → Check function signatures
🔴 Rule: Edit the file + all dependent files in the SAME task.
🔴 Never leave broken imports or missing updates.
Summary
| Do |
Don't |
| Write code directly |
Write tutorials |
| Let code self-document |
Add obvious comments |
| Fix bugs immediately |
Explain the fix first |
| Inline small things |
Create unnecessary files |
| Name things clearly |
Use abbreviations |
| Keep functions small |
Write 100+ line functions |
Remember: The user wants working code, not a programming lesson.
🔴 Self-Check Before Completing (MANDATORY)
Before saying "task complete", verify:
| Check |
Question |
| ✅ Goal met? |
Did I do exactly what user asked? |
| ✅ Files edited? |
Did I modify all necessary files? |
| ✅ Code works? |
Did I test/verify the change? |
| ✅ No errors? |
Lint, Types, and Active Terminals checked? |
| ✅ Nothing forgotten? |
Any edge cases missed? |
🔴 Rule: If ANY check fails, fix it before completing.
🔴 Terminal Hygiene (CRITICAL)
Always check running terminals for background errors (e.g., webpack/vite build failures, proxy errors).
- Read outputs of
dev, start, or watch tasks.
- Ignore them at your own peril.
Verification Commands (MANDATORY)
🔴 CRITICAL: Each agent runs ONLY their own skill's checks after completing work.
Agent → Command Mapping
| Skill/Agent |
Check |
Command |
| react-ux (Frontend) |
Lint Check |
cd frontend && npm run lint |
| react-ux (Frontend) |
Test Check |
cd frontend && npm run test |
| tdd-jest (Backend) |
Lint Check |
npm run lint |
| tdd-jest (Backend) |
Test Check |
npm run test |
| security |
Audit |
npm audit |
| clean-code (General) |
Type/Format |
npm run format |
| neon-dba |
Build/Schema |
npm run build |
| nestjs |
Build/Schema |
npm run build |
| nestjs |
Test |
npm run test |
❌ WRONG: security running npm run test (inefficient).
✅ CORRECT: tdd-jest running npm run test (verifies functionality).
🔴 Command Output Handling
When running a validation command, you MUST:
- Run the command and capture ALL output.
- Parse the output - identify errors, warnings, and passes.
- Summarize if there are failures, fix them before notifying the user.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: clean-code-143description: Pragmatic coding standards - concise, direct, no over-engineering, no unnecessary comments. Use when this capability is needed.4---56# Clean Code - Pragmatic AI Coding Standards78> **CRITICAL SKILL** - Be **concise, direct, and solution-focused**.910---1112## Core Principles1314| Principle | Rule |15|-----------|------|16| **SRP** | Single Responsibility - each function/class does ONE thing |17| **DRY** | Don't Repeat Yourself - extract duplicates, reuse |18| **KISS** | Keep It Simple - simplest solution that works |19| **YAGNI** | You Aren't Gonna Need It - don't build unused features |20| **Boy Scout** | Leave code cleaner than you found it |2122---2324## Naming Rules2526| Element | Convention |27|---------|------------|28| **Variables** | Reveal intent: `userCount` not `n` |29| **Functions** | Verb + noun: `getUserById()` not `user()` |30| **Booleans** | Question form: `isActive`, `hasPermission`, `canEdit` |31| **Constants** | SCREAMING_SNAKE: `MAX_RETRY_COUNT` |3233> **Rule:** If you need a comment to explain a name, rename it.3435---3637## Function Rules3839| Rule | Description |40|------|-------------|41| **Small** | Max 20 lines, ideally 5-10 |42| **One Thing** | Does one thing, does it well |43| **One Level** | One level of abstraction per function |44| **Few Args** | Max 3 arguments, prefer 0-2 |45| **No Side Effects** | Don't mutate inputs unexpectedly |4647---4849## Code Structure5051| Pattern | Apply |52|---------|-------|53| **Guard Clauses** | Early returns for edge cases |54| **Flat > Nested** | Avoid deep nesting (max 2 levels) |55| **Composition** | Small functions composed together |56| **Colocation** | Keep related code close |5758---5960## AI Coding Style6162| Situation | Action |63|-----------|--------|64| User asks for feature | Write it directly |65| User reports bug | Fix it, don't explain |66| No clear requirement | Ask, don't assume |6768---6970## Anti-Patterns (DON'T)7172| ❌ Pattern | ✅ Fix |73|-----------|-------|74| Comment every line | Delete obvious comments |75| Helper for one-liner | Inline the code |76| Factory for 2 objects | Direct instantiation |77| utils.ts with 1 function | Put code where used |78| "First we import..." | Just write code |79| Deep nesting | Guard clauses |80| Magic numbers | Named constants |81| God functions | Split by responsibility |8283---8485## 🔴 Before Editing ANY File (THINK FIRST!)8687**Before changing a file, ask yourself:**8889| Question | Why |90|----------|-----|91| **What imports this file?** | They might break |92| **What does this file import?** | Interface changes |93| **What tests cover this?** | Tests might fail |94| **Is this a shared component?** | Multiple places affected |9596**Quick Check:**97```98File to edit: UserService.ts99└── Who imports this? → UserController.ts, AuthController.ts100└── Do they need changes too? → Check function signatures101```102103> 🔴 **Rule:** Edit the file + all dependent files in the SAME task.104> 🔴 **Never leave broken imports or missing updates.**105106---107108## Summary109110| Do | Don't |111|----|-------|112| Write code directly | Write tutorials |113| Let code self-document | Add obvious comments |114| Fix bugs immediately | Explain the fix first |115| Inline small things | Create unnecessary files |116| Name things clearly | Use abbreviations |117| Keep functions small | Write 100+ line functions |118119> **Remember: The user wants working code, not a programming lesson.**120121---122123## 🔴 Self-Check Before Completing (MANDATORY)124125**Before saying "task complete", verify:**126127| Check | Question |128|-------|----------|129| ✅ **Goal met?** | Did I do exactly what user asked? |130| ✅ **Files edited?** | Did I modify all necessary files? |131| ✅ **Code works?** | Did I test/verify the change? |132| ✅ **No errors?** | Lint, Types, and **Active Terminals** checked? |133| ✅ **Nothing forgotten?** | Any edge cases missed? |134135> 🔴 **Rule:** If ANY check fails, fix it before completing.136137---138139## 🔴 Terminal Hygiene (CRITICAL)140141**Always check running terminals for background errors (e.g., webpack/vite build failures, proxy errors).**142- Read outputs of `dev`, `start`, or `watch` tasks.143- Ignore them at your own peril.144145---146147## Verification Commands (MANDATORY)148149> 🔴 **CRITICAL:** Each agent runs ONLY their own skill's checks after completing work.150151### Agent → Command Mapping152153| Skill/Agent | Check | Command |154|-------|--------|---------|155| **react-ux** (Frontend) | Lint Check | `cd frontend && npm run lint` |156| **react-ux** (Frontend) | Test Check | `cd frontend && npm run test` |157| **tdd-jest** (Backend) | Lint Check | `npm run lint` |158| **tdd-jest** (Backend) | Test Check | `npm run test` |159| **security** | Audit | `npm audit` |160| **clean-code** (General) | Type/Format | `npm run format` |161| **neon-dba** | Build/Schema | `npm run build` |162| **nestjs** | Build/Schema | `npm run build` |163| **nestjs** | Test | `npm run test` |164165166> ❌ **WRONG:** `security` running `npm run test` (inefficient).167> ✅ **CORRECT:** `tdd-jest` running `npm run test` (verifies functionality).168169---170171### 🔴 Command Output Handling172173**When running a validation command, you MUST:**1741751. **Run the command** and capture ALL output.1762. **Parse the output** - identify errors, warnings, and passes.1773. **Summarize** if there are failures, fix them before notifying the user.178179---180> Converted and distributed by [TomeVault](https://tomevault.io/claim/404-profit-not-found) — claim your Tome and manage your conversions.181<!-- tomevault:4.0:skill_md:2026-04-14 -->