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.
- CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- solidity-style-guideSkill
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
- Very specific: line 16
Pragma in examples: use ^0.8.20 for libraries and 0.8.34 (pinned) for application contracts, unless the rule is specifically about version …
- Distinctive: line 23
Treat the following as hard rules (block the PR on violation):
- Very specific: line 34
Use calldata for read-only array/struct parameters on external functions
- Distinctive: line 38
Treat the following as warnings (suggest, don't block):
- Distinctive: line 41
Prefer named arguments for calls with ≥ 3 args
- Very specific: line 83
Add a new rule? Match the existing pattern: #### Rule Name → short rationale → ✅ Yes: / ❌ No: Solidity blocks → > …
- Very specific: line 84
Update the table of contents if you add an H3/H4.
- Distinctive: line 85
Keep the tone practical. Cite the relevant EIP, Solidity release note, or audit finding where possible.
- Distinctive: line 90
No Solidity toolchain (Foundry / Hardhat) is installed here — examples compile conceptually, not in CI.
- Distinctive: line 91
No breaking of the core doc into a docs site generator.
≈ “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.
Files
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
- No emojis in code examples. Emojis are fine in READMEs when they aid scanning, but avoid adding them where none exist.
- Do not shorten the guide. Each rule is load-bearing; prefer adding a new rule section over collapsing two.
- Every rule must have a ✅ Yes / ❌ No Solidity example. Single-example rules are incomplete.
- Max line length 120 (Solidity and Markdown prose). Indent Solidity with 4 spaces.
- Pragma in examples: use
^0.8.20for libraries and0.8.34(pinned) for application contracts, unless the rule is specifically about version pragmas. - Prefer named imports.
import {X} from "./X.sol";. Never use bareimport "./X.sol";. - Prefer custom errors over
requirestrings. Userequire(cond, CustomError())(Solidity ≥ 0.8.26) orrevert CustomError(). - 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
.solfile - 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 explicituint256,int256,bytes1 - Use
calldatafor read-only array/struct parameters on external functions - Cache
.lengthoutside 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 checkFile 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 CIStyle 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.mdas the canonical source.
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
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.

