Skip to content
Back to skills

Lean Code

ASecurity

Write the least code that fully solves the task: reuse before writing, delete before adding, design key interfaces twice, prefer deep modules, refactor in small behaviour-preserving steps. Use when implementing, simplifying or refactoring.

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 29, 2026
ai-agentsrustrefactoringsecurity

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 29, 2026

npx -y skills add k6w/baton --skill lean-code --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Lean Code?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Lean Code
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/k6w-lean-code/badge)](https://www.skillsdirectory.com/skills/k6w-lean-code)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: lean-code
description: "Write the least code that fully solves the task: reuse before writing, delete before adding, design key interfaces twice, prefer deep modules, refactor in small behaviour-preserving steps. Use when implementing, simplifying or refactoring."
keywords: [refactor, refactoring, simplify, cleanup, clean up, minimal, yagni, over-engineering, bloat, dead code, abstraction, interface, module, design, restructure, duplication]
---
# Lean code

Every line you add has to be read, tested and fixed by someone later, usually another agent with less
context than you. Solve the whole task with as little new code as possible. Be lean about the
solution, never about the job: every caller, test, fixture and doc your change breaks is still yours
to fix.

## Before writing: find the real scope

Read the task and the code it touches. List every place the change must reach: callers, tests,
fixtures, config, exports, docs. Check what it could break for users: data lost or exposed, callers
that stop working. That list is the scope. Features nobody asked for are not.

## Take the first option that fully works

1. **Does it need to exist?** Skip options, flexibility and "for later" code nobody asked for; name
   what you skipped in one line of your report.
2. **Already in the codebase?** Use the existing helper, component or pattern the way nearby code
   does.
3. **Standard library or platform feature?** Use it (unless the project wraps it; then use the wrap).
4. **An installed dependency?** Use it. Never add a dependency for a few lines.
5. **Otherwise** the minimum code that works, in the structure the codebase already has.

## Rules

- **Delete before adding.** If the change gets simpler by removing dead code, an unused option or a
  pass-through layer that sits in your path, remove it.
- No wrapper, abstraction, config knob or type conversion without a second real use. Keep values in
  the form the platform gives them.
- The shortest diff wins once you know everything it must touch. A clever one-liner that needs
  decoding is not short.
- Comment only the why the code can't show, in one line. A known limit gets
  `shortcut: <the limit>, <when to upgrade>` so reviewers treat it as a decision.
- Code you move or merge keeps its validation and error handling.
- Between two options of equal size, take the one correct on edge cases.
- Never cut: validation at trust boundaries, error handling that prevents data loss, security,
  accessibility, anything the task asked for.
- New non-trivial logic (a branch, a loop, a parser, money, auth) leaves at least one test (how:
  `test-driven`).

## Interfaces: design it twice

For a new module or a public function other code will depend on, sketch two or three genuinely
different interfaces before coding (different in shape, not in naming): e.g. one call that does the
whole job versus a small set of steps, or data in/data out versus an object with state. Compare them
on what a caller must know, how easy each is to test, and what a likely future change would cost.
Pick one and say why in a sentence. Worked guidance:
`load_skill("lean-code", "references/design-it-twice.md")`.

Aim for **deep modules**: a small interface hiding real work. Warning signs of shallow ones: a
function that only forwards its arguments, a class whose methods each wrap one call, an interface as
complicated as its implementation, callers that must call things in a particular order.

## Refactoring without changing behaviour

1. Run the tests first; they must be green before you start. If coverage of the code you'll move is
   thin, add characterisation tests that pin today's behaviour (even odd behaviour) first.
2. Move in small, named steps: rename, extract, inline, move, merge duplicates, delete. Run the tests
   after every step; commit at green points (see `shipping`).
3. Never mix a refactor with a behaviour change or a formatting sweep in the same commit.
4. Keep public interfaces unless the task says otherwise; update every call site you touch.
5. Large, cross-cutting renames: add the new form next to the old, move callers over in batches, then
   delete the old form. The build stays green at every step.
6. Report what moved where, what was deleted (with line counts), and the test results.

Files in this skill

  • SKILL.md4.2 KB
  • references/design-it-twice.md2.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.