agentic-clean-code

agentic-clean-code is a cursor rule for coding agents from adriannoes/awesome-agentic-ai. It costs 692 tokens per session, scanned A, original, MIT.

A set of code-writing and code-review rules focused on making source code easy for both people and coding agents to navigate. It covers file structure, naming, types, duplication, and error details across programming languages.

In plain words
What is it for?
Use it when writing or reviewing code to keep files focused, functions short, names specific, interfaces typed, and error messages informative.
Why use it?
Small, clearly named modules and explicit types make code easier to find, understand, test, and change. Consistent error context also makes failures easier to diagnose.

Cursor rule

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/adriannoes/awesome-agentic-ai/agentic-clean-code
Clone the repo
git clone --depth 1 https://github.com/adriannoes/awesome-agentic-ai

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for agentic-clean-code

README.md
[![agentmods](https://agentmods.dev/badge/rules/adriannoes/awesome-agentic-ai/agentic-clean-code.svg)](https://agentmods.dev/rules/adriannoes/awesome-agentic-ai/agentic-clean-code)
Your own site
<a href="https://agentmods.dev/rules/adriannoes/awesome-agentic-ai/agentic-clean-code"><img src="https://agentmods.dev/badge/rules/adriannoes/awesome-agentic-ai/agentic-clean-code.svg" alt="Measured on agentmods" height="20"></a>
Per session 692 This file is loaded in full into every session.
When invoked 692 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.00692 $0.00692
Opus 5 $0.00346 $0.00346
Sonnet 5 $0.00138 $0.00138
Haiku 4.5 $0.00069 $0.00069

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

Security

Grade A, and why

agentic-clean-code 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 4d 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.

cursor-claude-codex/best-practices/agentic-clean-code.mdc · 75 lines

How it starts

The opening of the file, as written. The whole thing — 75 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Agent Clean Code

The primary reader of this code is an AI agent. Optimize for grep navigation, single tool-call comprehension, and headless test loops.

Size and structure

  • Functions: 4–30 lines; split if longer.
  • Files: under 500 lines; ideal 200–300. Split by responsibility.
  • One responsibility per module (SRP).
  • Follow framework conventions (Rails, Django, Next.js, etc.) so paths are predictable.
  • Prefer small focused modules over god files.

Grep-friendly names

  • Names must reveal intent and be distinct in the codebase.
  • Avoid generic names: data, process, handler, Manager, Service, util, helper.
  • Prefer specific names: UserRegistrationValidator, InvoiceLineItemTotal.
  • Target: rg "<symbol>" returns fewer than 5 hits; if not, rename or namespace.

Types

  • Explicit types everywhere the language supports them.
  • No untyped public APIs (any, bare Dict, untyped function signatures).
  • Typed code gives the agent immediate contracts and reduces inference errors.

DRY and control flow

  • No duplicated logic across files — extract shared functions or modules.
  • Named constants instead of magic numbers.
  • Early returns and guard clauses; max 2 indentation levels.
  • Prefer pattern matching / guard clauses over deep nesting.

Comments (provenance, not narration)

  • Write WHY and provenance, not WHAT the syntax does.
  • Keep agent-written comments on refactor — do not strip them.
  • Document non-obvious constraints: upstream bugs, business rules, protocol quirks.
  • Reference issue numbers when logic exists because of a specific bug or decision.
  • Docstrings on public APIs: intent + one usage example.
  • Skip obvious comments (// increment counter above count++).

Errors

  • Error and exception messages must include the offending value and expected shape.
  • Bad: raise ValueError("invalid input")
  • Good: raise ValueError(f"invalid input: received {x!r}, expected non-empty string of digits")

Testability

  • Inject dependencies through constructor, parameter, or context — not hidden globals.
  • Wrap third-party libraries behind a thin project-owned interface when they may be swapped.
  • Mock external I/O (API, DB, filesystem) with named fakes, not scattered inline stubs.
  • Every new public function gets a test; every bug fix gets a regression test.

Read the full file on GitHub · 75 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. 4d ago First seen · 75 lines · 692 tokens per session scan A 6b1b3b94b786

Subscribe to this mod's changes

agentic-clean-code is a cursor rule published in the GitHub repository adriannoes/awesome-agentic-ai (54 stars, last pushed 6d ago), licensed MIT. It adds 692 tokens to every session, about $0.0035 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-30.