clean-code-skill

A set of code-quality rules based on Robert C. Martin’s Clean Code principles and checked with SonarCloud, a service that detects code problems. It covers duplication, function size, naming, nesting, and constants.

In plain words
What is it for?
Use it when writing or reviewing TypeScript code, extracting shared logic, naming functions, reducing nesting, and checking SonarCloud duplication results.
Why use it?
It gives the coding agent consistent standards for readable, maintainable code and helps catch repeated or overly complex logic before merging.

Cursor rule for Codex

Install

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.

agentmods
npx agentmods add rules/kaelsensei/magicaibuilder/clean-code-skill
Clone the repo
git clone --depth 1 https://github.com/KaelSensei/MagicAIBuilder

Made for: Codex.

Per session 632 This file is loaded in full into every session.
When invoked 632 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What 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.

ModelPer sessionOnce 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

Measured 2d ago against content hash da0ba34ae3c8, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

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.

.agents/rules/clean-code-skill.mdc · 61 lines

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 namesgetFilteredDeckCards over process.
  • 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 sonar or check the SonarCloud duplication dashboard before merging. Target: duplicated_lines_density trending 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/ or class-variance-authority variants.
    • Shared React logic → custom hook under src/hooks/.
    • Shared API error handling → a withApiErrorHandler(handler) wrapper.

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.
  • if ladder with 5+ branches on the same discriminant → table lookup.
  • as type assertions, ! non-null assertions, any — banned per CLAUDE.md.
  • console.log in production code — use logger or remove.
  • Components > 200 lines, stores > 300 lines, files > 300 lines — split.

Read the full file on GitHub · 61 lines

Changes

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.

  1. 2d ago First seen · 61 lines · 632 tokens per session scan A da0ba34ae3c8

Subscribe to this mod's changes

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.