
Code With the Grain: The Skill That Stops AI Coding Agents Bloating Your Repo
AI coding agents add. They write a second helper next to the first, a new layer beside the existing one, a wrapper around a function that already did the job. T...

Left alone, AI coding agents add duplication, drift, and unproven fixes. Three composable skills removed 821 lines across five Tier-3 PRs while shipping features.
We hand coding agents real tickets every day, and they almost always ship something that works. That was never the worry. The worry is how they work: a new helper next to three that already do the job, a fresh abstraction for a single caller, a fix that patches the one path the ticket named and leaves four siblings broken, a finding that is “probably a bug” with no proof either way. Every change is locally reasonable. In aggregate they are entropy.
TL;DR: Across five Tier-3 pull requests on our agent-orchestration core, three composable skills —
ponytail(subtract),grain(align), andreview-proof(prove) — removed 821 lines while shipping five features, caught a silent contract break that plausibility alone would have merged, and kept every change going with the grain of the existing architecture. Here is what each one does, with the real diffs to back it.
Take the guardrails away and a coding agent is a very fast generator of plausible-looking liabilities. So we lean on three small skills that push the other way — one instinct each: subtract, align, prove.
ponytail — write the laziest thing that actually works. Delete before you add. (We didn’t write this one — it’s an open-source skill by Dietrich Gebert
that we adapted for our stack.)grain / grain-review — put it where the codebase already decided it goes. Don’t invent a second way.review-proof — don’t believe a finding until it reproduces as a failing test.grain and review-proof we built in the same spirit as ponytail, tuned to our architecture. Every one of the five PRs below touches our agent-orchestration core — the single most expensive place in the repo to get sloppy — and every one is classified Tier 3: extra test coverage and human review on top of the automated reviewer, no exceptions.
The three skills at a glance: ponytail subtracts, grain aligns, review-proof proves.
Here’s the thing nobody warns you about when you hand a repo to AI agents: each agent optimizes locally and remembers nothing. It sees the ticket, not the months of conventions your team converged on. It has no reason to prefer your existing email service over a fresh one, no memory that the redirect-status set is already defined three files over, no instinct that “the fix goes in the shared function, not this one caller.” Left to run, N agents produce N slightly-different ways to do the same thing. That’s not a code-quality problem you can lint away — it’s a structural drift that compounds.
The three skills each target one axis of that drift.
ponytail — the laziest thing that worksPonytail is a senior developer who has been paged at 3am for someone else’s clever abstraction and refuses to write the next one. It runs a ladder and stops at the first rung that holds: does this need to exist at all (YAGNI) → is it already in this codebase → does the standard library do it → native platform feature → already-installed dependency → can it be one line → only then, the minimum code that works.
The rung that matters most for agents is “is it already in this codebase?” Re-implementing what’s a few files over is the single most common form of agent slop. And ponytail’s bug-fix rule keeps diffs honest: fix the root cause, not the symptom. Grep every caller of the function you’re about to touch; one guard in the shared function is a smaller diff than a guard in every caller — and it doesn’t leave the siblings broken.
grain / grain-review — go with the grainIf ponytail governs how little you write, grain governs where it goes and what shape it takes. Its one rule: find the nearest existing example, copy its shape, name what you copied. New code should read as though the person who wrote the file next to it wrote this one too.
Grain is also where architecture is enforced. Our backend is a fairly standard vertical-slice + hexagonal layout — presentation calls application calls domain, infrastructure depends inward, and the domain never reaches back out. A finding like “this route skips its controller and pulls the service directly” isn’t pedantry — it’s the difference between a codebase an agent can navigate next month and one it can’t. grain-review hunts exactly these: duplicated helpers, crossed layer boundaries, reaching into another feature’s internals, a second convention for something already done one way.
review-proof — earn the findingStandard AI code review produces plausible findings. Some are real; some are confident nonsense; from the outside they look identical. review-proof refuses to trust itself: it reviews, then forces every correctness finding to reproduce as a real failing test or runnable repro, and drops anything that won’t. It closes with a grain-review pass for structural fit. What ships is a review where each item comes with executable evidence — not a vibe.
Five real changes to our agent core. We’re keeping the internals vague on purpose — the repo is private — but the numbers are computed from the actual diffs and the lessons are the transferable part.
One family of flow steps fetched user-supplied URLs without a DNS-resolving safety check, so a hostname that resolved to an internal address could reach cloud metadata from the backend. The tempting fix adds a check at each of the dozen-plus fetch sites. Ponytail’s answer was the opposite: one shared, guarded fetch helper, used everywhere — and we deleted a hand-rolled private-network table that a wildcard-DNS trick walked straight past, plus three duplicated redirect loops and a network check copy-pasted into several files.
The diff added the shared helper and removed ~90 lines of duplication across 22 files. That deletion is the story: this is H2 in the flesh — the root-cause fix routed every caller through one guard instead of patching the one path the ticket named.
The root-cause fix: a dozen ad-hoc fetch sites collapse onto one shared, guarded helper. The lazy fix and the safe fix are the same fix.
Our worker runtime persists a run’s result as a serialized string, sometimes wrapped in a single-element list. Consumers that expected a plain object crashed on it. The wrong fix scatters defensive type-checks at each consumer. Instead: one small shape-normalizing helper, and every consumer re-pointed at it — a near-pure addition of one guard that replaces the N ad-hoc ones a less disciplined agent would have written (+558 / −24, 7 files).
The part that makes this a review-proof story is the test. Instead of asserting against an assumed serialization shape, we ran a real workflow through the actual runtime and storage — no mocks — and proved the shape the runtime actually persists. The open question in the ticket was literally what does the runtime serialize here? — and the only honest answer is one you can run.
Feature: a per-node fallback model, so a flow pinned to one provider degrades gracefully during an outage. The obvious first cut wrapped the model in the framework’s built-in fallback combinator.
It worked in the happy path. It also silently switched off two provider features that gate on the concrete model type via isinstance — a wrapped object is no longer that type, so native structured output and prompt caching both quietly turned off. No error. No failing happy-path test. Exactly the kind of thing a human review skims past and a “looks fine” agent approves.
review-proof didn’t approve it — it reproduced both breaks as failing tests, which forced the redesign: apply the fallback lower down, at execution time, so every model stays its concrete type and the type-gated features keep working. H3, confirmed decisively: proof caught a bug that plausibility would have shipped.
Adding a second notification channel meant the channel-picker UI now had two homes — a create wizard and a settings modal. The default agent move adds the new branch to both, growing two copies of the same state machine. grain said: there is already one way this should be shaped — make it shared. We extracted a single picker hook and drove both screens through it, slotted the new channel into the existing config union, and reused the existing email service instead of adding new send machinery.
+1,735 / −340 across 24 files. A feature this size removing 340 lines is H1 made visible: the dedup of two picker copies into one paid for a good chunk of the new channel.
Letting users attach files at issue creation could have meant a new upload endpoint, a new dispatch mechanism, a new prompt path. grain routed nearly all of it onto existing rails: the existing upload endpoint, a frontend accept-list that mirrors the backend whitelist exactly, and a deferred-dispatch fix that reused the eligibility mechanism scheduled work already used. It shipped with proof-backed fixes, including a real transaction-isolation bug that would have lost data under parallel uploads. +1,776 / −218 across 27 files — a big feature that still found 218 lines to remove by joining existing slices instead of inventing new ones.
Five Tier-3 PRs: what each added, what it removed, and the instinct behind it.
Five feature and fix PRs on the agent core removed 821 lines — not by doing less, but by refusing to duplicate what already existed and to keep symptom-patches a root-cause fix made redundant.
ponytail is not ours. It’s an open-source skill by Dietrich Gebert
; we adapted it. grain and review-proof are ours, built in the same spirit. All three run as local project skills on Claude Code — prompt-and-procedure, not a binary you install.What shipped. Three composable skills. ponytail and grain run while writing; ponytail-review, grain-review, and review-proof run on a diff. review-proof chains grain-review as its final phase, so a single proven review also gets a structural pass for free.
What you can do on Monday — you don’t need our exact skills:
Try it, especially if it fails for you. If you run coding agents on a real codebase, the entropy is already happening — you just haven’t measured it. Turn one of these into a review pass on your next ten agent PRs and count the deletions. If subtract-align-prove doesn’t shrink your diffs or catch a silent break, we’d genuinely like to hear it. Corrections and counterexamples especially welcome.
An agent adds. The job is to make the agent earn every line.
Štefan is an AI and software engineer building FlowHunt. Beyond the product itself, he designs agentic software-engineering workflows for developers that cut development costs while raising code quality.

FlowHunt helps engineering teams design agentic workflows, review gates, and MCP integrations that cut development costs while raising code quality.

AI coding agents add. They write a second helper next to the first, a new layer beside the existing one, a wrapper around a function that already did the job. T...

Same pull request, same prompt, same model — only the context loading differed. A context-engine digest plus one policy-file read beat reading the docs on both ...

Ten months, 1,409 merged PRs, three forensic audits: how a staged agent pipeline took one enterprise codebase from 12% to 92% agent-involved development — with ...
Cookie Consent
We use cookies to enhance your browsing experience and analyze our traffic. See our privacy policy.