agentleFS
AboudjemAboudjem/solidity-style-guide/AGENTS.md

solidity-style-guide

AGENTS.md32 starsChanged 8 months agoMITView on GitHub

A short context file for coding agents (Claude Code, Cursor, Codex, Aider, etc.) working in this repository. For humans: see README.md. The full rule catalog lives in the README; this file is the short version for coding agents. A Solidity style guide: conventions, formatting, best practices, testing, gas, and security rules for modern Solidity (≥ 0.8.20, targeting 0.8.34). It is documentation, not deployable code. Treat the following as hard rules (block the PR on violation): Treat the following as warnings…

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository3 other files it gives its agents.

The file

We split this AGENTS.md into the rules it gives an agent

10 rules. About 0 are common, 6 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Pragma in examples: use ^0.8.20 for libraries and 0.8.34 (pinned) for application contracts, unless the rule is specifically about version …

    line 16
  2. Distinctive:

    Treat the following as hard rules (block the PR on violation):

    line 23
  3. Very specific:

    Use calldata for read-only array/struct parameters on external functions

    line 34
  4. Distinctive:

    Treat the following as warnings (suggest, don't block):

    line 38
  5. Distinctive:

    Prefer named arguments for calls with ≥ 3 args

    line 41
  6. Very specific:

    Add a new rule? Match the existing pattern: #### Rule Name → short rationale → ✅ Yes: / ❌ No: Solidity blocks → > …

    line 83
  7. Very specific:

    Update the table of contents if you add an H3/H4.

    line 84
  8. Distinctive:

    Keep the tone practical. Cite the relevant EIP, Solidity release note, or audit finding where possible.

    line 85
  9. Distinctive:

    No Solidity toolchain (Foundry / Hardhat) is installed here — examples compile conceptually, not in CI.

    line 90
  10. Distinctive:

    No breaking of the core doc into a docs site generator.

    line 91

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md

A short context file for coding agents (Claude Code, Cursor, Codex, Aider, etc.) working in this repository. For humans: see README.md. The full rule catalog lives in the README; this file is the short version for coding agents.

What this repo is

A Solidity style guide: conventions, formatting, best practices, testing, gas, and security rules for modern Solidity (≥ 0.8.20, targeting 0.8.34). It is documentation, not deployable code.

Ground rules for agents editing this repo

  1. No emojis in code examples. Emojis are fine in READMEs when they aid scanning, but avoid adding them where none exist.
  2. Do not shorten the guide. Each rule is load-bearing; prefer adding a new rule section over collapsing two.
  3. Every rule must have a ✅ Yes / ❌ No Solidity example. Single-example rules are incomplete.
  4. Max line length 120 (Solidity and Markdown prose). Indent Solidity with 4 spaces.
  5. Pragma in examples: use ^0.8.20 for libraries and 0.8.34 (pinned) for application contracts, unless the rule is specifically about version pragmas.
  6. Prefer named imports. import {X} from "./X.sol";. Never use bare import "./X.sol";.
  7. Prefer custom errors over require strings. Use require(cond, CustomError()) (Solidity ≥ 0.8.26) or revert CustomError().
  8. When in doubt, cite a source in the rule (Solidity docs, EIP, Foundry book, RareSkills, Coinbase guide).

When asked to apply the style guide to a codebase

Treat the following as hard rules (block the PR on violation):

  • SPDX license identifier present on every .sol file
  • Single contract / interface / library per file
  • Layout order: pragmas → imports → events → errors → interfaces → libraries → contracts
  • Inside a contract: type declarations → state vars → events → errors → modifiers → functions
  • Function order: constructor → receive → fallback → external → public → internal → private (view/pure last in each group)
  • Interfaces prefixed I (e.g., IToken)
  • Constants SNAKE_UPPER_CASE, private constants _SNAKE_UPPER_CASE
  • Internal / private identifiers prefixed with _
  • No uint / int / byte — always explicit uint256, int256, bytes1
  • Use calldata for read-only array/struct parameters on external functions
  • Cache .length outside the loop header
  • For upgradeable contracts, use ERC-7201 namespaced storage

Treat the following as warnings (suggest, don't block):

  • Prefer named returns
  • Prefer named arguments for calls with ≥ 3 args
  • Named parameters in nested mappings

Commands agents can run

This repo is docs-only, so there's no compile step. Quality gates:

# Verify Markdown
npx markdownlint-cli2 "**/*.md" "#node_modules"

# Verify formatting
npx prettier --check .

# Check links in top-level docs
npx markdown-link-check README.md AGENTS.md CONTRIBUTING.md SECURITY.md

# Everything
npm run check

File map

/README.md                Main guide (SEO-optimised, animated banner)
/AGENTS.md                This file
/CLAUDE.md                Claude Code specific instructions
/llms.txt                 LLM discovery index
/.cursorrules             Cursor IDE rules mirror
/SECURITY.md              Disclosure policy
/CONTRIBUTING.md          PR workflow
/CODE_OF_CONDUCT.md       Community standards
/.solhint.json            Linter config matching this guide
/.prettierrc              Formatter config matching this guide
/.editorconfig            Editor-level defaults
/assets/banner.svg        Animated hero banner
/skill/                   Claude Code skill package (solidity-style-guide)
/.github/                 Issue / PR templates and CI

Style for edits to this guide

  • Add a new rule? Match the existing pattern: #### Rule Name → short rationale → **✅ Yes:** / **❌ No:** Solidity blocks → > [!TIP|NOTE|IMPORTANT|WARNING|CAUTION] callout.
  • Update the table of contents if you add an H3/H4.
  • Keep the tone practical. Cite the relevant EIP, Solidity release note, or audit finding where possible.

Non-goals

  • This repo does not ship example contracts to deploy.
  • No Solidity toolchain (Foundry / Hardhat) is installed here — examples compile conceptually, not in CI.
  • No breaking of the core doc into a docs site generator. Keep README.md as the canonical source.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.