When AI Invents a Package: How Slopsquatting Works
When AI Invents a Package: How Slopsquatting Works
AI coding tools sometimes recommend packages that do not exist, and attackers can register those names. What the research measured, a real case from 2026, and the cheap habits that protect you.
Most talk about AI writing bad code is about logic bugs: an off-by-one, a missed edge case, a function that looks right and is not. Those are annoying, but your tests usually catch them. There is a quieter failure that tests do not catch, because it happens before your code even runs. Sometimes the model tells you to install a package that does not exist.
That sounds harmless. Worst case, npm install fails and you move on. The problem is what happens when somebody else notices the same made-up name first and publishes something under it. People have started calling this slopsquatting, and I think every developer who lets an AI touch their dependencies should understand how it works.
Why a model invents a package at all
A language model does not look anything up when it writes an import line. It predicts the next bit of text based on patterns it has seen. Package names follow very strong patterns: react-something, something-utils, py-something. So when the model needs a tool for a job, it can produce a name that fits the pattern perfectly and simply is not real. It has no built-in sense of the difference between "a package I have seen" and "a package that sounds like one I have seen".
That is the same reason I keep saying the model is not the clever part of an AI coding tool. It writes text. Whether that text points at something real is somebody else's job, and right now that somebody is usually you.
What the research actually measured
The best study on this I have found is We Have a Package for You! by researchers at the University of Texas at San Antonio, the University of Oklahoma and Virginia Tech. The authors also summarised it for USENIX's ;login: magazine in June 2025. They ran 16 popular code-generating models over two prompt datasets and generated 576,000 code samples in Python and JavaScript, then checked every package those samples referred to against the real registries.
The headline numbers, from the paper and the authors' USENIX write-up:
- Across all 16 models, about 19.6% of recommended packages did not exist.
- Commercial models did a lot better, around 5%, while open-source models averaged around 21%.
- In total the models produced 205,474 unique package names that did not exist.
- About 45% of hallucinated packages came back every single time the same prompt was repeated, and about 60% reappeared at least once in ten repeats.
That last point is the one that matters. If the fake names were random, they would be noise. Because the same fake names come back again and again, they are predictable, and anything predictable is something an attacker can plan around.
One more detail I liked: when some models were asked afterwards whether a package they had suggested was real, they caught their own mistake about 80% of the time. So the model can often tell, if anyone bothers to ask it. Nobody asks it during a normal coding session.
This already happened, and agents ran it
For a while this was a mostly theoretical worry. In January 2026, Charlie Eriksen at Aikido Security wrote up a real case. A package name, react-codeshift, had never been published on npm. It looks like a mash-up of two real tools, jscodeshift and react-codemod. He traced it back to a single commit in October 2025 that added 47 LLM-generated "agent skill" files to a popular repository, with at least two of them telling the agent to run npx react-codeshift.
Those skill files got forked and copied until 237 repositories referenced the fake package. He claimed the name on npm himself, with nothing inside it, and then watched the download numbers. After the usual first-day spike from mirrors and scanners, there was a steady trickle of one to four downloads a day. His reading is that those were AI agents following the skill instructions and trying to run the command. If an attacker had claimed the name instead, those agents would have run whatever was in it.
Notice how little had to go wrong. Nobody was hacked. A model made up a name, a person committed it without checking, other people copied it, and agents did what the text told them.
What I actually do about it
None of this means you should stop using AI tools. I use them every day. It means a dependency is a decision, and a decision should not be made by autocomplete. A few habits that cost almost nothing:
- Check any package you do not recognise before installing it.
npm view package-nametells you if it exists, who publishes it and when it was first published. For Python, look it up on pypi.org. A package that was created last week with no repository link is a red flag. - Read install commands before you approve them. If your agent asks to run
npxorpip installon something new, that is exactly the moment to slow down, not the moment to hit yes. - Treat skill files, rules files and READMEs as code. If they tell an agent to run a command, review them the way you would review a script, especially ones you copied from someone else's repo.
- Keep the lockfile honest. Look at what changed in
package.jsonorrequirements.txtin every AI-assisted diff. New dependencies should stand out, not slip through with forty other lines. - Ask the model. Given the self-detection result above, a quick "are all of these packages real and maintained?" is a cheap extra check. It is not a guarantee, so it does not replace the steps above.
The bigger point
The real lesson for me is not about npm. It is that AI tools are very good at producing things that look correct, and looking correct is exactly what makes a mistake travel. A fake package name with the right shape gets past a tired reviewer, then a fork, then an agent. The skill that keeps you valuable as a developer is not typing speed. It is knowing which parts of the output to trust and which parts to check, and checking them.