boy-scout-rule
Skill10 starsChanged 9 months agoMITView on GitHub
When touching existing code and wanting to leave it better. Use when the user says "clean this up while I'm here," "should I fix this," "tech debt," "while I'm in this file," or "incremental improvement." For full refactoring, see solid or separation-of-concerns.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- sbrudz/agent-skillstheir own version, first seen Nov 1, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- sbrudz/agent-skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- convention-over-configurationSkill
- detect-stackSkill
- drySkill
- kissSkill
- law-of-demeterSkill
- separation-of-concernsSkill
- solidSkill
- yagniSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 12
If .agents/stack-context.md exists, read it first.
- Distinctive: line 16
Leave every file you touch a little better than you found it.
- Distinctive: line 28
Fix what you see, within scope: If you open a file to fix a bug and notice a misleading variable name, rename it.
- Distinctive: line 30
Don't refactor what you don't understand: If you open an unfamiliar file and something looks wrong, investigate before "fixing" it.
- Very specific: line 32
Leave a trail: If you notice a problem too large to fix in passing, create an issue or add a TODO(ticket-number) so it doesn't get …
- Distinctive: line 54
Size limit: If a cleanup would touch more than ~20 lines or span multiple modules, it's not a Boy Scout improvement — it's a refactoring …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill 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
Boy Scout Rule
Before Applying
If .agents/stack-context.md exists, read it first. Apply this principle using idiomatic patterns for the detected stack. For framework-specific details, use context7 MCP or web search — don't guess.
Principle
Leave every file you touch a little better than you found it. Not a lot better — a little better. Incremental improvement compounds into a clean codebase over time.
Why This Matters in Production
Codebases don't rot overnight. They degrade one shortcut at a time — a hardcoded value here, a skipped rename there, a TODO that lives for three years. The Boy Scout Rule is the antidote: it makes improvement the default, not a scheduled event.
Teams that practice this never need "cleanup sprints." Their code stays healthy because maintenance happens continuously, embedded in regular feature work.
But this only works with discipline: improvements must be small, safe, and scoped. A "cleanup" that touches 40 files and breaks two features is worse than leaving the mess.
Rules
- Fix what you see, within scope. If you open a file to fix a bug and notice a misleading variable name, rename it. If you see a dead import, remove it. These are safe, low-risk improvements.
- Keep cleanups in separate commits. A feature commit should contain the feature. A cleanup commit should contain the cleanup. Mixing them makes code review harder and reverts dangerous.
- Don't refactor what you don't understand. If you open an unfamiliar file and something looks wrong, investigate before "fixing" it. What looks like dead code might be a critical fallback. What looks like a typo might be intentional.
- Scope your improvements. Boy Scout Rule means fixing a confusing name or adding a missing type annotation. It does not mean redesigning a module you happened to walk past.
- Leave a trail. If you notice a problem too large to fix in passing, create an issue or add a
TODO(ticket-number)so it doesn't get forgotten.
What Counts as "A Little Better"
- Renaming a variable from
xtouser_count - Removing an unused import or dead code
- Adding a missing type annotation
- Fixing a misleading comment (or removing a comment that restates the code)
- Replacing a magic number with a named constant
- Simplifying a conditional that's more complex than necessary
- Fixing a compiler/linter warning
What Does NOT Count
- Rewriting a function in a "better" style without functional change
- Migrating to a new pattern across the whole codebase
- Adding features or changing behavior
- Reformatting files to match a different style (use autoformatters for this)
- Refactoring code that is unfamiliar to you without full understanding
Boundaries
- Size limit: If a cleanup would touch more than ~20 lines or span multiple modules, it's not a Boy Scout improvement — it's a refactoring task that deserves its own ticket and review.
- Tension with "don't touch what you don't own": In shared codebases, small improvements are generally welcome. Large refactors across module boundaries require coordination. Know the difference.
- Tension with minimal diffs: Some teams prefer PRs that only contain the intended change. In that case, put Boy Scout cleanups in a separate PR.
Code Review Checklist
- Are the cleanups genuinely low-risk and obviously correct?
- Are cleanups in separate commits from feature work?
- Does the cleanup touch only code the author is actively working in?
- Would reverting the cleanup leave the feature intact?
Related Skills
- kiss: For identifying what "simpler" looks like
- convention-over-configuration: For knowing what the project's conventions are before "fixing" things
- dry: For spotting duplication worth consolidating
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.

