Part 12 of 13 9 min read

Don't reinvent the wheel

Don't Depend on It

Every dependency was a trade: someone else's code for some amount of trust. Trust got more expensive at the same time AI made code cheap. Rerun the trade.

I taught beginners to reach for a gem before writing a line. Don't reinvent the wheel. Someone smarter already solved this, it's tested, it's maintained, add it to the Gemfile and move on. Rails apps I've shipped had a couple hundred gems in the lockfile and nobody thought that was weird. It was the responsible thing to do.

The trade underneath that advice was simple. A dependency gave you a solved problem, and in exchange you trusted a stranger: their code, their account, their release pipeline, and everyone they trusted in turn. For twenty years that was usually a great deal. The dependency didn't just save typing. It imported knowledge you couldn't afford to acquire, and supply chain abuse was rare enough to round to zero.

Two things changed, separately. The trust got expensive because the attacks got relentless. The code got cheap because an agent can write it. Rerun the trade with the new numbers and most of the lockfile comes out the other side.

The trust got expensive

A dependency hurts you in two different ways, and they're worth keeping apart. Sometimes the dependency has a vulnerability: honest code with a bug in it. Sometimes the supply chain is compromised: someone steals a maintainer's account, a publishing token, or a CI credential, or poisons something further down the tree. The first is a security bug. The second is an attack on the channel you get your code from.

The first is the one we always knew about. This July, CVE-2026-66066 made a very common Rails configuration readable by an unauthenticated attacker: Active Storage, image uploads from the public, and libvips, the default image processor in modern Rails. Arbitrary file reads, including secret_key_base, with a path to remote code execution from there. No dependency was malicious. Active Storage trusted the content type the client declared, and didn't turn off the libvips operations that are unsafe on untrusted input. libvips sniffed the actual bytes and handed them to whatever decoder matched. Each component made a locally reasonable decision, and the composition opened a hole nobody intended. I had six apps to patch that morning.

The second is the one that's become impossible to ignore: the distribution channel itself turning hostile. In September 2025 someone phished one maintainer and shipped malicious versions of chalk, debug, and sixteen other packages that together see over two billion downloads a week. Two months later the Shai-Hulud worm stole publishing tokens and spread itself to nearly 800 packages. In March 2026 a hijacked account turned axios, 100 million downloads a week, into a dropper. The only change to the source was one new line in package.json: a dependency called plain-crypto-js whose postinstall script was the malware. In June a North Korean crew did the same to 140 Mastra packages in 19 minutes.

Those aren't libraries with security bugs. They're legitimate packages, with legitimate version numbers, executing attacker code with whatever privileges your laptop, your CI runner, your build system, or your application happens to have. A string-coloring utility ended up inside applications that moved cryptocurrency, and inside developer machines holding the keys to everything else.

And when an honest bug does land, the window is closing. Mandiant tracked the average time from disclosure to exploitation falling from 63 days in 2018 to five days in 2023, and individual vulnerabilities are now hit within hours. LMDeploy was attacked twelve and a half hours after its advisory went up in April, and the Cloud Security Alliance cites research systems turning some fresh CVEs into working exploits in ten to fifteen minutes. An unpatched dependency used to be a slow leak. Now it's a race, and you're entered once for every package in the lockfile.

The code got cheap

Here's the other half, and it's the part I actually find interesting.

The reason you took on a color picker dependency was that building one well is genuinely hard. Keyboard handling, touch, hex and RGB and HSL, screen reader labels, a decade of Safari weirdness. A weekend of work, and it's not your product. Of course you installed the package.

Last week I needed a color picker. I pointed Claude Code at the package I would have installed and said:

Read through this color picker library and study how good pickers behave.
Build our own version as a single Stimulus controller plus a CSS file in our
design system. Keep the keyboard handling and the hex/RGB inputs, drop the
gradient editor and the plugin system, no external dependencies. Then write a
system spec that picks a color with the mouse and one that does it with only
the keyboard.

Forty minutes later I had about 300 lines instead of 3,000 plus eleven transitive packages. It uses our tokens, and it's in my repo where I can read it, grep it, and change it.

Notice what that removed. Not the supply chain; my repo, my CI, Rails, and the browser are all still supply chain. What's gone is a set of people I had to trust and never met: a package author, their GitHub account, their CI, the registry, their dependencies, and those dependencies' maintainers. All of that collapsed into my repo, which I already had to defend. There is no external publisher who can change it underneath me, no registry account to compromise, and no postinstall.

The agent made implementation cheap. It didn't make correctness free, and I want to be careful here. The library I didn't install carries years of fixes for edge cases my 300 lines may get wrong. What the agent did is bring much of that knowledge to bear on a small implementation, cheaply, and then keep the result small enough that I can actually read it and write tests around the behavior I care about. I traded 3,000 opaque lines plus a dependency graph for 300 bounded lines that do exactly my job. The first thing the agent should ask is whether we need to build anything at all. Browsers ship <input type="color">. Platform primitive first, then a small local implementation, then a dependency, in that order.

There's a quieter benefit too. A local implementation doesn't make bugs disappear, and client-side code is hardly secret. But it takes me out of the monoculture. A vulnerability in a package on 100,000 sites gives an attacker a reason to automate the exploit and run it against all 100,000. A bug unique to my color picker doesn't. That's no help against someone who's after me specifically, but a huge amount of commodity exploitation isn't aimed at anyone in particular. It's aimed at whatever is widespread.

Depend on expertise, not effort

I'm not writing my own TLS. Dependencies can reduce risk, and OpenSSL is safer than anything I'd ask an agent to invent. The question is what you're buying, and there are four questions I now ask before anything goes in the lockfile.

Vendoring is the most AI-native of the three, and it deserves a closer look. The old objection was that vendored code rots: a human has to understand someone else's code to maintain it, and nobody does, so it sits there untouched. Agents are good at exactly that work. Pull in a well-tested MIT implementation, have the agent cut the 70% you don't use, and you keep the battle-tested behavior without giving its publisher an ongoing ability to modify your application. Vendoring kills the live publishing relationship, not the maintenance obligation. I still watch upstream for security fixes. The difference is that nobody else decides when new code enters my repo.

For the dependencies I do keep, these are the signals I look at:

Keep itBuild or vendor it instead
The maintainerA foundation, a company, or a project with release signing and a security processOne person, a tired volunteer, or you can't tell
The transitive treeSmall and stableDozens of packages, several of which exist to pad a string
Install scriptsNone, or explicitly justified and reviewedLifecycle scripts you didn't expect and can't explain
Security visibilityWidely monitored, a disclosure process, a response teamLittle monitoring, unclear ownership, nobody to call

The right column is where most of a typical lockfile lives. The left column is maybe twenty packages, and they get pinned, watched, and updated the day an advisory drops.

The ecosystem matters

This is harsher for JavaScript than for Ruby. Node has a real standard library and the browser is an enormous platform. The problem is that the ecosystem got in the habit of pulling the small stuff from npm anyway. That's how unpublishing eleven lines called left-pad broke React, Babel, and thousands of builds in 2016. That wasn't an attack. It was a maintainer having a bad day, and it showed how deep the tree went.

Lockfiles buy you real protection against the attacks above. A frozen install won't silently move from yesterday's clean version to today's poisoned one, and integrity hashes keep the artifact you pinned from changing underneath you. That's a defense, not a solution. You still have to update eventually, every automated dependency bump is a chance to walk into the poisoned release, and a lockfile does nothing when the version you pinned turns out to have an ordinary vulnerability. Fewer dependencies means fewer of those upstream decisions I eventually have to make.

Your package manager is part of the surface too. The axios payload was a postinstall script, and npm ran it. Bun won't run lifecycle scripts from dependencies unless they're on its short built-in allowlist or in your trustedDependencies, lets you plug in a security scanner that aborts a bad install, and has a minimumReleaseAge setting so a version has to exist for a few days before you'll take it. That last one is the cheapest defense there is: let the rest of the internet find the poisoned release first. npm 12 finally blocks install scripts by default, which tells you how obvious the fix was.

What I do now

When I'm about to add something, I ask the agent to look at it first. How big is the transitive tree, who maintains it, does it have install scripts, what am I actually buying. Half the time the answer is "this is 300 lines, want me to just write it." Yes.

For what's already in the lockfile, I had an agent sort every dependency in each app through the four questions, then rewrite or vendor the ones that came out "own it," one at a time, with tests. Each app lost between a third and half its dependencies and nothing changed for the user. Audits got shorter. The next advisory morning will be shorter too.

The old advice assumed the code was the expensive part. It isn't anymore. The expensive part is trust, and the useful metric isn't lines of code or even dependency count. It's trust surface: how many people, accounts, build systems, registries, release processes, and transitive projects can put code into mine. Rails is enormous and I trust it on purpose, because what I'm buying is twenty years of expertise. A 50-line utility with a maintainer I've never heard of adds more trust surface than 500 lines I own. I'd rather extend trust to twenty things I chose deliberately than two hundred I never looked at.

For decades, code was expensive enough that we casually widened our trust boundary to avoid writing it. We were importing whole factories because making one wheel was too expensive. It isn't, so shrink the boundary back.

This is part of Rethink Everything, where I own the servers and duplicate code for the same reason: the agent made owning things cheap, and owning things is how you know what's in them.

The whole series

  1. 1Code is written for humans to readStop Writing and Reading Code
  2. 2Never rewrite from scratchRewrites Might Be Better Than Massive Refactors
  3. 3Use the language your team already knowsLanguage Strengths Over Language Familiarity
  4. 4Build it once for the web and wrap itGo Native Everywhere
  5. 5Keep the monolith majesticI Hated Microservices. Agents Love Them.
  6. 6Pay someone else to run your serversOwn Your Infrastructure
  7. 7Don't repeat yourselfDuplicate Code So Your Agents Stop Colliding
  8. 8Types are ceremonyTypeScript, I Don't Hate You Anymore
  9. 9Respect the testing pyramidMore E2E Tests, Fewer Unit Tests
  10. 10Refactor for readabilityStop Refactoring for Humans. Refactor for the Agent.
  11. 11Get fast on the keyboardVoice is Your Interface
  12. 12Don't reinvent the wheelDon't Depend on It
  13. 13Only engineers touch the codebaseProduct Over Code