The Andrej Karpathy Skills project identifies drive-by editing as one of the most disruptive LLM behaviors: while fixing a bug or adding a feature, the model also reformats whitespace, improves comments, adds type hints, refactors adjacent code, and removes what it thinks is dead code. Every extra change is noise in the diff, a potential new bug, and a violation of the user’s intent. This principle — Surgical Changes — draws a hard boundary: touch only the lines that the user’s request requires.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/multica-ai/andrej-karpathy-skills/llms.txt
Use this file to discover all available pages before exploring further.
The core problem
From Andrej Karpathy’s observation:“They still sometimes change/remove comments and code they don’t sufficiently understand as side effects, even if orthogonal to the task.”Drive-by changes are especially damaging because they make diffs harder to review, introduce style drift across a codebase, and occasionally break things that were working fine. The model may believe it’s being helpful — but the user asked for a fix, not a refactor.
Rules for editing existing code
- Don’t “improve” adjacent code, comments, or formatting. If the code next to your change uses single quotes, old-style string formatting, or a pattern you’d do differently — leave it alone.
- Don’t refactor things that aren’t broken. A working function with an inelegant implementation is not your problem to solve unless you were asked to solve it.
- Match existing style, even if you’d do it differently. Consistency within a file matters more than your personal preferences. If the file uses
snake_case, two-space indents, and single quotes, your additions should too. - If you notice unrelated dead code, mention it — don’t delete it. Call it out in a comment or a note to the user. Let them decide whether to remove it.
Rules for cleaning up orphans
Your changes may make things unused: an import that’s no longer referenced, a helper variable that your new approach eliminates, or a function that nothing calls anymore. You are responsible for those — but only those.- Remove imports, variables, and functions that YOUR changes made unused.
- Don’t remove pre-existing dead code unless you were asked to.
The key test: Every changed line should trace directly to the user’s request. If you can’t draw that line, the change shouldn’t be in the diff.
Examples from real requests
Drive-by refactoring: “Fix the bug where empty emails crash the validator”
The bug is narrow: the validator crashes whenemail is empty. The fix touches exactly the lines that handle that case.
Bad example — too many changes
Good example — only the that fix the crash
Style drift: “Add logging to the upload function”
Adding logging means inserting log calls. It does not mean adding type hints, changing quote style, adding a docstring, or restructuring the boolean return logic.Bad example — reformats everything while adding logging
' to "), added type hints, added docstring, reformatted whitespace, restructured the boolean return. None of that was asked for.
Good example — adds logging, matches existing style
What success looks like
This principle is working when:- Diffs are small and focused. Only the lines that address the request appear as changed.
- No style drift. Files look consistent before and after a change.
- Clean, minimal PRs. Reviewers can see exactly what changed and why.
Related principles
Simplicity First
Keep changes minimal not just in scope but in complexity — don’t add abstractions the request didn’t ask for.
Think Before Coding
Clarify scope before starting so you know exactly which lines need to change.