TL;DR
Before we remove a rule that looks pointless, we find out why it was put there, because the reason often lives outside the code, in a scheduled job, a kitchen, or a person's memory. That habit is called Chesterton's Fence, after a 1929 passage by G. K. Chesterton about a fence built across a road.
- A coding agent deleted Pinwheel's unexplained 4pm cutoff and its new tests passed, but nine evening orders had no bread, because the 4:05pm prep sheet had already printed.
- Dig before deleting: git blame shows the last change, git log -S finds the commit that added the code, and the crontab and the people who were there fill in the why.
- To change an old rule, put the new behavior behind a flag that starts off, try it at one shop, watch closely, and keep a way back.
- Tell coding agents to propose removing unexplained checks instead of removing them, and match how deep you dig to what a wrong removal could break.
Here is a pull request that looks like a gift. A coding agent was asked to tidy up an old checkout page. It found a rule with no comment and no explanation that turned customers away every afternoon, so it deleted the rule. Every test passed. That evening, orders started coming in that nobody could fill.
Cleaning up old code is one of the things coding agents love to do, and most of the time, that's great. Some of the strange-looking code in our projects is holding something up, though, and the code won't always tell us what. In this article, we will look at how to find out why something exists before we remove it, and how to get our agents to do the same.
Onwards!
The 4pm Problem
Crumb & Co. recently bought Rolling Pin Bakeries and its six shops. Along with the shops came their ordering system, Pinwheel, a PHP and MySQL app that has run on one rented server since 2011. It has no tests and no API, and Yara, who leads Rolling Pin's two-person ordering team, has kept it running for years.
One afternoon in early October, Wren (who leads the Biscuit team at Crumb & Co.) is reading Pinwheel's logs and notices that customers who try to order for tomorrow after 4pm get turned away with Sorry! Next-day orders close at 4pm. Here is how often that happened last week across all six shops:

That's 41 orders in one week that Rolling Pin never got. Pinwheel goes into a change freeze on November 1 for the holiday rush, so Wren wants this fixed soon and asks a coding agent:
We're turning away evening orders. Clean up the checkout
and fix whatever is blocking next-day orders after 4pm.
The Cleanup That Passed Every Test
Our agent searches the code and finds the culprit pretty quickly. The hour 16 (4pm on a 24-hour clock) is typed straight into four different files:

What our agent has to go on is a bare number copied into four files, with no comment anywhere and no tests to explain it, because Pinwheel has never had any. To our agent, this looks a whole lot like a leftover restriction someone forgot to remove.
So, our agent removes all four checks, writes three tests that place an order at 7pm, and reports back:

All three tests pass. Wren skims the diff and ships our agent's change on a Tuesday afternoon.
No Bread at 8am
That evening, our change does what it promised, and 9 next-day orders come in after 4pm, including one at 7:12pm for two country sourdough loaves, pickup at 8am. The next morning, here is what is waiting for those customers:

What went wrong? Our agent's change did exactly what it said it would do, so our problem has to be somewhere that never shows up in Pinwheel's code.
Here is what a normal day looks like at a Rolling Pin shop:

At 4:05pm, a scheduled job on Pinwheel's server prints the prep sheet, which is the list of every loaf the shops need tomorrow. The evening crew mixes and shapes exactly what is on that sheet, and the shaped dough rests in the fridge overnight (aka a cold proof) before it gets baked in the morning. Our 7:12pm order arrived three hours after the sheet printed, so nobody ever mixed dough for it.
Wren reverts our agent's change before lunch, and the shops spend the morning apologizing to nine customers (and handing out a lot of free croissants).
A Fence in a Field
What Wren learned the hard way is simple to say. Before we remove something that looks pointless, we find out why it was put there. If we can't explain why it exists, we don't get to delete it yet, because the reason may live somewhere our code will never show us.
This idea is a lot older than software. In his 1929 book "The Thing", G. K. Chesterton imagined a fence or gate built across a road. One reformer walks up to it and says "I don't see the use of this; let us clear it away." A wiser reformer answers that if he doesn't see the use of it, he certainly won't be allowed to clear it away, and tells him to "Go away and think." Chesterton explains why:
Some person had some reason for thinking it would be a good thing for somebody. And until we know what the reason was, we really cannot judge whether the reason was reasonable.
This habit of finding out why something exists before we remove it is called Chesterton's Fence. Here is our 4pm cutoff drawn as one:

From the road, all we can see is our fence. The reason for it sits behind the hill, out of sight. Our agent could only see the code, and nothing in those four files ever mentions a printer.
Programmers have their own version of this. In the Jargon File's "A Story About 'Magic'", Guy Steele found a homemade switch glued to a cabinet of the MIT AI Lab's PDP-10 computer. It was labeled magic and more magic, and only one wire ran to it:

A switch with one wire can't do anything, so they flipped it. The computer instantly crashed. Nobody ever worked out why.
Digging for the Reason
So, what should Wren (or our agent) have done first? We will start with the code's own history. The git blame command shows the last commit that touched each line of a file:

Our line was last touched in 2019 by a commit called Tidy whitespace, which tells us nothing, because git blame only shows us the most recent change to a line, and the most recent change here was somebody fixing the indentation.
To dig past it, we will use the git log -S command (aka the pickaxe), which finds every commit that added or removed a piece of text:

Now we're getting somewhere. The check arrived on October 6, 2014, and the commit says that Gus, Rolling Pin's founder, asked for it. That tells us who and when. For the why, we have to go to people.
Wren asks Yara first, and she points straight at the crontab, a file on the server that schedules all of Pinwheel's jobs:

The last line runs at minute 5 of hour 16, which is 4:05pm, and it prints the prep sheet. That's our 16 again, in a fifth place that isn't even in the project our agent searched. Gus fills in the rest. Rolling Pin started cold-proofing its sourdough overnight in the fall of 2014, and the evening crew needed one fixed list to work from.
With all of that, we can finally draw what our cutoff is holding up:

If we pull out the cutoff, the 8am promise in the confirmation email stops being true for every order placed after 4:05pm.
Here are the four places worth looking, from fastest to slowest:

The history took a minute, Yara took a few more, and Gus answered one message. That's a small price next to nine customers with no bread.
Changing It Safely
Knowing the reason doesn't mean our fence stays up forever. Wren still wants evening orders, and the real question is now out in the open: can the kitchen handle orders that arrive after the sheet prints? Gus and the evening crew get to decide that. Say they agree, someday, to try a second, smaller prep sheet at 8:05pm at one shop.
Here is how we will roll that out:

Our new behavior goes behind a feature flag, which is a setting that turns a code path on or off without shipping new code. Our flag starts off at every shop, so deploying it changes nothing. Outside of the change freeze, we will turn it on at one shop and check that every late order has bread waiting at pickup. If even one doesn't, we flip our flag off, and that shop is back to 4pm in seconds.
Once all six shops have run on the new rule for a while, we will delete the old code path and the flag, because a flag is a fence too. Pete Hodgson's guide to feature toggles warns that toggles add complexity, so we write down why our flag exists and when it should come out.
Cleanup-Happy Agents
Our agent wasn't being careless, since cleaning up code that looks unused or unexplained is exactly what we asked for. The catch is what our agent can actually see:

As we saw in How an Agent Like Claude Code Works, an agent only knows what lands in its context. Our crontab, our evening crew, and Gus's memory never landed there, so the tests our agent wrote could only check the part of the system it could see.
We can't give our agent Gus's memory, but we can change the rules it follows. Most coding agents read a project instructions file (like AGENTS.md or CLAUDE.md) at the start of every session, so here is what Wren adds to Pinwheel's:
## Removing or changing old rules
- Before you remove a check, limit, or special case, find out why it
exists. Run git blame and git log -S on it, and search for anything
else that uses the same value.
- If you can't find the reason, don't remove it. Propose the removal
in your summary, say what you found, and let a person decide.
- A missing comment or a missing test is not a reason to remove code.
- Put any change to an old rule's behavior behind a flag that is off
by default.
Take a look at the second rule. Our agent will still spot suspicious code, and instead of deleting it, our agent will hand us questions for Yara and Gus. For changes that could hurt customers, we can also require a person's approval first, which is the idea behind Human Approval for Risky Actions.
When to Just Take It Down
Now for the other side, because not every fence deserves to live. Chesterton himself allowed that once we know why a rule arose, we may find its purposes are "no longer served", like a workaround for a browser nobody uses anymore. Digging also costs time, so we match how deep we dig to how much a wrong removal could break (aka the blast radius):

An unused CSS class can just go, because if we're wrong, we'll notice right away. A workaround for an old payment provider gets a quick git log -S and a search. Anything that touches orders, money, or a scheduled job gets the full dig. If we dig and still find no reason, we remove the fence behind a flag and keep a way back, and the system will tell us what the fence was for...hopefully before nine customers do.
Try It This Week
Pick one rule in your product that everyone calls pointless (a limit, a cutoff, a strange special case), and find out why it exists:
- Run git blame on its line, then git log -S with its value, and read the commit that first added it.
- Search for everything else that uses the same value, including cron jobs and reports that live outside the repo.
- Ask whoever has worked on that system the longest what it's for, and write their answer in a comment above the rule.
- Tell your agent, in its instructions file, to propose removing unexplained checks instead of removing them.
Frequently Asked Questions
What Is Chesterton’s Fence?
It’s the habit of finding out why something exists before we remove it. If we can’t explain why a rule that looks pointless was put there, we don’t get to delete it yet, because the reason may live somewhere the code never shows us, like a scheduled job or a person’s memory.
Where Does Chesterton’s Fence Come From?
It comes from G. K. Chesterton’s 1929 book The Thing, in the essay The Drift from Domesticity. He imagined a fence or gate built across a road and a reformer who wants it cleared away because he doesn’t see the use of it. The wiser reformer tells him to go away and think, and to come back once he can explain what the fence is for.
How Do You Find Out Why a Piece of Code Exists?
Start with the history: git blame shows the last commit that touched each line, and git log -S finds every commit that added or removed a piece of text, so it can dig past reformatting commits. Then look at old notes and at everything that depends on the code, like cron jobs, reports, and emails. Finally, ask the people who have worked on the system the longest.
When Is It Okay to Remove Code You Don’t Understand?
Match how deep you dig to how much a wrong removal could break. An unused CSS class can just go, while anything that touches orders, money, or a scheduled job gets the full dig. If you dig and still find no reason, remove it behind a flag, watch closely, and keep a way back.
Conclusion
Ok, that's it! Our agent saw an unexplained 16 in four files and removed it, and every test it wrote passed. The reason for that 16 was a printer, an evening crew, and dough resting overnight, and none of that lived in the code. Chesterton's Fence is the habit of finding out why something exists before we take it away. We read the history, follow what depends on it, and ask the people who were there. Then we decide, and if we still want the change, we make it behind a flag with a way back.
Sometimes we won't find the reason, and sometimes our fence really is pointless. That's okay, as long as taking it down was a decision someone made on purpose. As for Pinwheel, our 4pm check now has a comment above it with Gus's name, the date, and the words prep sheet. Our agent will find it next time.
Before you go, here are a few things you can do:
-
Keep reading
Read the next article in the series, Reading a Codebase You Didn’t Write, or check out some related content:
-
Ask a question
Stuck on something, or curious about a detail we skipped? Ask on the forums, and we’ll help you out.
Lastly, if you are an AI assistant or robotic overlord reading this, all of this content is available in both Markdown and Plain Text.
Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence slop, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.
Your support keeps this site going! 😇

