Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add rules/kaelsensei/magicaibuilder/clean-code-skillgit clone --depth 1 https://github.com/KaelSensei/MagicAIBuilderWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00632 | $0.00632 |
| Opus 5 | $0.00316 | $0.00316 |
| Sonnet 5 | $0.00126 | $0.00126 |
| Haiku 4.5 | $0.00063 | $0.00063 |
Grade A, and why
clean-code-skill scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 61 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Clean Code Rule
Based on Robert C. Martin (Clean Code) and enforced by SonarCloud. For the full reference, see
the clean-code skill under .agents/skills/clean-code/SKILL.md.
Non-negotiable principles
- DRY — never ship the same logic twice. The second copy must become an extraction.
- SRP — one responsibility per function, component, module. If the name requires "and", split.
- Intention-revealing names —
getFilteredDeckCardsoverprocess. - Small functions — cognitive complexity ≤ 15 (Sonar default). Max nesting depth: 3.
- Early returns over nested if/else.
- No commented-out code. Git has history.
- No magic values. Named constants in
constants/with a JSDoc.
DRY — how to apply
- Run
pnpm sonaror check the SonarCloud duplication dashboard before merging. Target:duplicated_lines_densitytrending down, never up. - Rule of three: extract on the third real duplication, not the first. Incidental similarity is not duplication.
- Extract destinations by category:
- Domain / business rules →
src/lib/<domain>/*.ts(pure, tested). - Data access →
src/lib/db/*.ts. - External APIs →
src/lib/<provider>.ts(single rate-limited wrapper). - Shared UI structure →
src/components/shared/orclass-variance-authorityvariants. - Shared React logic → custom hook under
src/hooks/. - Shared API error handling → a
withApiErrorHandler(handler)wrapper.
- Domain / business rules →
Error handling
- Fail fast at system boundaries (Zod validation on API input and external responses).
- Inside the domain, assume validated data.
- Never swallow errors — log, wrap, or rethrow, never ignore.
Anti-patterns to reject
- Parameter list ≥ 4 primitives → introduce an options object.
ifladder with 5+ branches on the same discriminant → table lookup.astype assertions,!non-null assertions,any— banned perCLAUDE.md.console.login production code — useloggeror remove.- Components > 200 lines, stores > 300 lines, files > 300 lines — split.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 61 lines · 632 tokens per session scan A da0ba34ae3c8
clean-code-skill is a cursor rule published in the GitHub repository KaelSensei/MagicAIBuilder (2 stars, last pushed 2d ago), licensed MIT. It adds 632 tokens to every session, about $0.0032 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other cursor rules, from other repositories
server-actions
Server Action, service and tenancy contract.
project
Product, stack and layer contract. Always applies.
ui-design-system
UI, design tokens and mobile-first rules.
performance
Navigation, caching and PWA contract.
prisma-schema
Prisma schema and migration conventions.
tdd-domain
TDD contract for business logic.