Stop Letting AI Agents Bloat Your Codebase: The Karpathy-Inspired CLAUDE.md Blueprint

Stop Letting AI Agents Bloat Your Codebase: The Karpathy-Inspired CLAUDE.md Blueprint

By Reggi, 31 Oct 2026

Look at the git diff from your latest automated agentic coding session. You asked for a routine validation check. The model returned a sprawling 400-line abstraction, reformatted adjacent utility files, deleted contextual inline comments it failed to grasp, and injected configuration parameters nobody asked for.

Autonomous coding tools possess raw generation capabilities, but their unconstrained execution path defaults to technical debt. The fundamental bottleneck is not model intelligence. It is the absence of operational boundaries.

To solve this, developer workflows can enforce behavioral constraints through a single CLAUDE.md file. Derived directly from observations shared by Andrej Karpathy, this configuration translates core agent pitfalls into explicit, deterministic rules for Claude Code.

The LLM Coding Pathology

Andrej Karpathy pinpointed the recurring failure modes that plague large language models when tasked with real-world software engineering:

"The models make wrong assumptions on your behalf and just run along with them without checking. They don't manage their confusion, don't seek clarifications, don't surface inconsistencies, don't present tradeoffs, don't push back when they should."

"They really like to overcomplicate code and APIs, bloat abstractions, don't clean up dead code... implement a bloated construction over 1000 lines when 100 would do."

"They still sometimes change/remove comments and code they don't sufficiently understand as side effects, even if orthogonal to the task."

Left to their own devices, coding models optimize for speculative completion rather than system stability. They guess silently, build over-engineered scaffolding, rewrite unaffected modules, and deliver changes that are impossible to review cleanly.

The Four Principles of Systemic Restraint

The solution distills Karpathy's diagnosis into four operational principles contained entirely within a single CLAUDE.md file.

PrincipleAddresses
Think Before CodingWrong assumptions, hidden confusion, missing tradeoffs
Simplicity FirstOvercomplication, bloated abstractions
Surgical ChangesOrthogonal edits, touching code you shouldn't
Goal-Driven ExecutionLack of verification, missing leverage through tests-first criteria

1. Think Before Coding

Models frequently pick an arbitrary interpretation of a vague prompt and run with it to completion. This principle forces Claude Code to halt and reason out loud before generating code:

  • State assumptions explicitly: If uncertain about context or requirements, ask rather than guess.
  • Present multiple interpretations: Never pick an implementation path silently when structural ambiguity exists.
  • Push back when warranted: If a requested implementation is unnecessary or a simpler approach exists, surface it.
  • Stop when confused: Identify the specific unknown, name what is unclear, and demand clarification before continuing.

2. Simplicity First

Large models gravitate toward speculative architecture, adding interfaces, single-use classes, and layers of indirection that balloon codebases. The Simplicity First rule establishes hard constraints:

  • Deliver only the minimum code required to solve the task. Nothing speculative.
  • No features beyond what was explicitly requested.
  • No abstractions for single-use code.
  • No unrequested "flexibility" or "configurability."
  • No complex error handling for impossible scenarios.
  • If 200 lines could be written in 50 lines, rewrite it immediately.
  • The baseline test: Would a senior engineer say this is overcomplicated? If the answer is yes, strip it down.

3. Surgical Changes

Agentic edits often corrupt source control hygiene by touching files, lines, and formatting completely detached from the assigned problem. Surgical discipline enforces code containment:

  • Touch only what you must, and clean up only your own mess.
  • Do not "improve" adjacent code, existing comments, or style formatting.
  • Do not refactor code that is not broken.
  • Match the existing repository style, even if you prefer an alternative pattern.
  • If you find unrelated dead code, mention it in your response. Do not delete it.
  • When your changes create orphaned dependencies, clean them up: remove imports, variables, and functions that your edits rendered useless.
  • Never remove pre-existing dead code unless explicitly instructed.
  • The baseline test: Every single changed line in the diff must trace directly to the user's prompt.

4. Goal-Driven Execution

Open-ended instructions like "make it work" leave models drifting in loops. Goal-Driven Execution forces every imperative request into a verifiable test harness.

Imperative CommandVerifiable Goal Transformation
"Add validation""Write tests for invalid inputs, then make them pass"
"Fix the bug""Write a test that reproduces it, then make it pass"
"Refactor X""Ensure tests pass before and after"

For multi-step initiatives, Claude Code must declare a step-by-step verification loop:

  1. [Step] -> verify: [check]
  2. [Step] -> verify: [check]
  3. [Step] -> verify: [check]

Clear, deterministic success criteria allow the agent to iterate independently and terminate accurately once the verification succeeds.

Deploying the Guidelines

These guidelines can be integrated into your development environment either globally as a Claude Code plugin or directly within individual repositories.

Option A: Install via Claude Code Plugin (Recommended)

This method installs the guidelines as a reusable skill across all repositories.

From within your Claude Code environment, add the marketplace source:

bash
/plugin marketplace add forrestchang/andrej-karpathy-skills

Next, install the plugin:

bash
/plugin install andrej-karpathy-skills@karpathy-skills

Option B: Deploy per Project via CLAUDE.md

If you want project-level containment, pull the raw configuration file directly into your working tree.

For a new repository:

bash
curl -o CLAUDE.md https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/main/CLAUDE.md

To append the guidelines to an existing CLAUDE.md:

bash
echo "" >> CLAUDE.md curl https://raw.githubusercontent.com/forrestchang/andrej-karpathy-skills/main/CLAUDE.md >> CLAUDE.md

This configuration framework also underpins ecosystem tools like Multica, an open-source platform built for managing and executing coding agents powered by modular, reusable skills.

By injecting clear operational constraints at the root of your agent's context window, you eliminate speculative code generation, protect your commit history from messy refactors, and transform Claude Code into a precise engineering utility.

References


Popular Reads