# Why less code

AI coding agents bloat software in recurring, documented ways. [The pattern catalog](https://lessloc.org/patterns/index.md) lists each one, the software-engineering standard that already calls it a bad practice, and what lessloc does about it. This page explains why unneeded size does more harm than good, and why agents need this more than people do.

## Why unneeded size does more harm than good

Code, text, files and folders that a requirement does not need cost something every time anyone works on the software:

- **Every line is spent, not produced.** Dijkstra (EWD1036): "if we wish to count lines of code, we should not regard them as 'lines produced' but as 'lines spent'."
- **Complexity grows unless someone reduces it.** Lehman's second law: "As an evolving program is continually changed, its complexity, reflecting deteriorating structure, increases unless work is done to maintain or reduce it."
- **Errors grow with size.** McConnell, *Code Complete*, ch. 27: error density rises with program size.
- **Duplicated knowledge breaks.** A rule written in two places gets fixed in one. DRY says "every piece of knowledge must have a single, unambiguous, authoritative representation within a system."
- **Big changes get worse reviews.** Google's engineering practices: "100 lines is usually a reasonable size for a CL, and 1000 lines is usually too large."
- **For AI agents, size is attention.**
  - Models do worse as their input grows: "performance grows increasingly unreliable as input length grows" ([Chroma, Context Rot](https://research.trychroma.com/context-rot)).
  - Models miss what sits in the middle of long contexts ([Liu et al., TACL 2024](https://aclanthology.org/2024.tacl-1.9/)).
  - Anthropic calls context "a finite resource with diminishing marginal returns." Every extra line, comment, file or doc is read by every later agent session, and it competes with what matters.
- **Comments and docs that restate code drift into lies.** [CWE-1116](https://cwe.mitre.org/data/definitions/1116.html), Inaccurate Source Code Comments. *Code Complete* counts a comment that repeats the code as unacceptable in finished code.
- **Fragmentation costs navigation.** Shallow files and folders hold little behind each name (Ousterhout). Always-loaded overviews raised agents' cost by more than 20% without helping ([arXiv:2602.11988](https://arxiv.org/abs/2602.11988)).

None of this applies to code a requirement needs. Tests, validation, error handling, security and the docs a reader needs are never "bloat", and duplication is still cheaper than the wrong abstraction (Metz). lessloc targets growth nobody needs, and [the counterweights](https://lessloc.org/patterns/index.md#what-lessloc-never-pushes-an-agent-toward) keep it from going further.

## Why agents need this more than people do

- **Duplication up, reuse down.** From 2021 to 2024, copy-pasted lines rose from 8.3% to 12.3% of changed lines, and moved or refactored lines fell from 25% to under 10% (211M lines; [GitClear 2025](https://www.gitclear.com/ai_assistant_code_quality_2025_research)).
- **Lasting complexity.** Adopting Cursor brought +30% static-analysis warnings and +42% cognitive complexity in about 800 repositories. Both persisted while the speed gain faded ([arXiv:2511.04427](https://arxiv.org/abs/2511.04427)).
- **Short-lived code.** Functions and classes that agents add are deleted after a median of 3 days, against 34 for human code ([arXiv:2601.17627](https://arxiv.org/abs/2601.17627)).
- **Debris in passing patches.**
  - In passing patches, 18–33% of the patch could be removed with the tests still passing ([arXiv:2607.18161](https://arxiv.org/abs/2607.18161)).
  - 29% of passing SWE-bench patches wrapped obsolete code in a guard instead of deleting it ([arXiv:2607.28887](https://arxiv.org/abs/2607.28887)).
- **Weak tests.**
  - 80% of agent test patches have a weak oracle or none ([arXiv:2606.18168](https://arxiv.org/abs/2606.18168)).
  - Agent commits add mocks more often than human commits: 36% against 26% ([arXiv:2602.00409](https://arxiv.org/abs/2602.00409)).
- **Type escapes.** In TypeScript agent pull requests, `any` appears at 9 times the human rate ([arXiv:2602.17955](https://arxiv.org/abs/2602.17955)).
- **Made-up packages.** Between 5.2% and 21.7% of the packages that models recommend do not exist ([Spracklen et al., USENIX Security 2025](https://www.usenix.org/conference/usenixsecurity25/presentation/spracklen)).
- **The cost lands on the next agent.** Cleaner code cut Claude Code's tokens by 7–8% and its file revisits by 34%, at an equal pass rate ([arXiv:2605.20049](https://arxiv.org/abs/2605.20049)).
- **Less stable delivery.** A 25% rise in AI adoption went with 7.2% lower delivery stability ([DORA 2024](https://dora.dev/ai/gen-ai-report/)).

The figures come from the cited studies, as each reports them, not from lessloc. lessloc's own measurements are in [Benchmarks](https://lessloc.org/benchmarks.md).
