---
id: 18738
lang: en
title: "A developer cut Claude Code's rules from 965 to 156 lines and made tasks 42% cheaper"
published_at: "2026-11-30 20:25:55"
source_name: "Habr AI"
source_url: "https://habr.com/ru/articles/1114200/?utm_campaign=1114200&utm_source=habrahabr&utm_medium=rss"
canonical_url: "https://news.hamidun.com/en/news/18738"
categories: ["llm", "autonomous"]
publisher: "AI News by Jemal Hamidun (news.hamidun.com)"
---

# A developer cut Claude Code's rules from 965 to 156 lines and made tasks 42% cheaper

> **Краткая суть (BLUF):** Before every task, Claude Code read about 1,500 lines of rules, even for a minor fix in the routes, including the App Store release process and SEO guidelines. The author cut the studio's and product's shared rules from 965 to 156 lines and moved rarely needed topics into separate files. On eight real bugs, the cost of 24 runs dropped from $39.88 to $23.04 (−42%), and the tests passed everywhere. So cut first what the agent reads every time.  • Splitting the rules into module folders saved about 8% — within the range of noise • The agent's first request shrank from 66k to 28k tokens • The 24 runs used 31 million tokens instead of 67 million

Rule files for AI agents grow on their own: after every incident, someone adds one more line. The developer behind Metro, a London Underground map app from Mammoth Studio, once counted how much text Claude Code (Anthropic's AI programming agent) reads before each task and got about 1,500 lines. Even to fix a single condition in the routes, the agent first loaded the App Store release process, the rules for payment screens, and the SEO requirements. Of those 1,500 lines, 965 belonged to the studio's shared rules (634) and the product's rules (331), which the agent always reads. The author cut them to 156 lines and moved rarely needed topics into separate files. As a result, eight real bugs, each run three times, cost 42% less: $23.04 instead of $39.88 for 24 runs. The agents solved the tasks just as they did before.

## What was compared

The project is large: four repositories, about 300,000 lines of code, almost all written by agents. The rules live in CLAUDE.md files at three levels: the studio (634 lines), the product (331 lines), and the repository (350–570 lines). These files are inserted at the start of every session, so everything the agent must always know lives there.

Three variants were tested with identical rule text; only the storage location changed:

- A — everything as before, large files.
- B — repository rules split across AGENTS.md files in module folders, which the agent loads when it opens a module's code. This is the most popular tip in the community.
- C — the same as B, plus the studio and product rules cut from 965 to 156 lines. Only what is needed in any task stays at the top, while payment walls, releases, and SEO are moved into separate files with an index like "if the task is about a release, read releases.md."

Claude Code itself performed the restructuring, and the author designed the measurement. They took eight real, already fixed bugs, ranging from a backend proxy to a stuck GPS tracker on iOS. Each bug was run three times in each variant, in a clean copy of the project without commit history. Then hidden tests from the real fix were added to the agent's code. In total, there were 72 runs.

## What we found

The module split (variant B) yielded about 8% savings at the median, and across the eight bugs this is indistinguishable from chance. In some cases it was even more expensive than the original. There are two reasons. First, it did not touch the 965 lines of studio and product rules, which account for about two-thirds of the mandatory reading. Second, the agent still opens the module with the bug, and that module's rules get loaded, so part of the savings comes back.

Variant C was cheaper on all eight bugs, by 32% to 53%. The total for the 24 runs fell from $39.88 to $23.04, a 42% reduction. The work processed 31 million tokens versus 67 million. The agent's first request, before it read any code, weighed 66,000 tokens in variant A and 28,000 in variant C. Those 38,000 tokens repeat at every step, and a task has 30–50 steps. Server-side caching makes the repeated start of the request cheaper, but it does not make it free.

The number of steps (the agent's calls to the model) also dropped on all eight bugs: a median of 32 versus 41. The experiment does not show why. The author suspects that hundreds of lines about releases and payments prompt the agent to check against irrelevant material, and plans to test this with a separate variant containing neutral text of the same length. Quality did not decline: the hidden tests passed in all 72 runs. The single exception was a test the agent itself named the same as a hidden test, which kept the project from building. Readability and code style were not evaluated.

A curious side effect: with the module split, agents more often edited files outside the module with the bug. In six of nine cases, they updated an outdated comment that had become untrue after the fix and had sat in master for a month. The author believes module descriptions help the agent see connections, and so kept the split even though it barely saves money.

## How to replicate, and the limitations

The practical recipe is short. Use wc -l to count all CLAUDE.md and AGENTS.md files from the root of the disk down to the project folder. For each line, ask whether it is needed in every task; if not, move it into a separate topic file without rewriting the text, and add an index. Put module rules in that module's folder as AGENTS.md, with a CLAUDE.md alongside containing the line @AGENTS.md. Use a script to verify that the paths and names referenced in the rules exist in the code: an outdated rule is more harmful than a missing one.

The limitations are honest. Eight bugs is a small sample, and on a different project the numbers would differ. None of the bugs touched the moved-out topics, so it is unknown whether the agent will find the right file through the index in a release-related task. Everything was tested on one setup, Claude Code with Opus. Variant C was run a day after the others, but control reruns of A on the same day cost more than any run of C. The author also warns that overnight, some runs were cut short by a locked keychain and were recorded as "$0," which nearly skewed the total. Always check the raw data before drawing conclusions.

---
- **Первоисточник:** [Habr AI](https://habr.com/ru/articles/1114200/?utm_campaign=1114200&utm_source=habrahabr&utm_medium=rss)
- **Каноническая ссылка:** https://news.hamidun.com/en/news/18738
- **Экосистема автора:** [Бесплатный интенсив по вайбкодингу — предзапись в Нике](https://t.me/vibecodeguidebot?start=agent_intensive_news_md) · [Nomad AI](https://nomadnet.ai) · [Telegram @jemal_hamidun](https://t.me/jemal_hamidun)
