Package registries
For a library, the package registry is often the first and only web surface a coding agent touches. Agents with shell access run npm view, npm search, pip index or cargo search directly, or they curl the registry’s JSON API, and what they read is the registry’s copy of your README, description and keywords rather than your docs site. Those requests go from the developer’s machine to npm, PyPI or crates.io, so they never show up in your own server logs. Registry metadata is also what a careful agent uses to check that a package it remembers from training data actually exists, which makes it the defence against hallucinated package names.
Two ways a registry is used
Section titled “Two ways a registry is used”A model meets your package in one of two ways. The first is recall, where the name is in its training data, so it suggests the package unprompted and then installs it. The second is verification or discovery, where the agent searches the registry or reads the package’s metadata before or after suggesting it. Recall depends on how much text about you existed before the model’s cutoff, while verification depends on what the registry returns at run time inferred.
- npm / pip / cargo → registry.npmjs.org
npm view pkg - curl → pypi.org
JSON lookup - registry.npmjs.org → README + keywords
served copy - pypi.org → GitHub repo
project_urls - crates.io → Docs site
homepage
How each registry search ranks
Section titled “How each registry search ranks”| Registry | Search surface | What is matched and ranked | Evidence |
|---|---|---|---|
npm (website and npm search) | OpenSearch over title, description, README and keywords | Keyword match by default, with optional sorting by downloads, dependents or publish date. npm says it applies “no subjective ranking” apart from a small boost against spam and brand-new packages; new packages take up to two weeks to appear, and deprecated ones are excluded (npm docs) | documented |
| npm registry API | /-/v1/search?text=...&quality=&popularity=&maintenance= | Still documents the npms-style quality, popularity and maintenance weights (REGISTRY-API.md); the website docs no longer describe them, so whether they still affect ranking is unclear | inferred |
| PyPI | No public search API; /pypi/NAME/json and /simple/ are name lookups only (PyPI JSON API) | Nothing to rank: an agent can verify a PyPI name but cannot discover one through the registry, only through web search or training data | documented |
| crates.io | GET /api/v1/crates?q= and cargo search | Relevance over name, description, keywords and categories; no published formula | inferred |
| MCP Registry | registry.modelcontextprotocol.io | Distribution surface for MCP servers; ownership proven by mcpName in package.json or an mcp-name: marker in the README (quickstart) | documented |
The useful consequence for npm is that ranking is mostly lexical. A package whose description and keywords contain the words a developer (or a model) would type, such as “markdown parser” or “rate limiter redis”, matches those queries, and a clever brand name with a vague description doesn’t. PyPI offers no such lever, so Python packages depend entirely on web search, GitHub and training data for discovery.
What agents actually run
Section titled “What agents actually run”Coding agents treat registries as tools they already know how to use from training data. As far as we can tell, nothing in Claude Code, Codex or Gemini CLI wraps a registry API specifically, and the model simply writes a shell command inferred. These are the typical commands you’ll see in agent transcripts:
npm view some-package # description, versions, repository, homepagenpm view some-package readme # README as publishednpm search "markdown parser" # keyword searchcurl -s https://pypi.org/pypi/some-package/json | head -c 4000pip index versions some-packagecargo search some-crate --limit 5Sandboxing decides whether these commands work at all. Codex’s cloud environment offers a “Common dependencies” network preset whose allowlist includes npmjs.org, pypi.org, pythonhosted.org and crates.io alongside github.com and githubusercontent.com documented, so registry lookups often work even when general web access doesn’t. In our Dec 2026 lab run, Codex reached our canary page only through curl once network access was enabled, and Pi, which has no web tools, wrote a Python urllib one-liner instead measured in our lab. The same improvisation applies to registries, because when an agent has a shell, the registry is one command away.
An agent verifying a package before installing it
- Model→Agent shell
npm view fast-md-parse - Agent shell→npm registry
GET /fast-md-parse - npm registry→Agent shell
404 Not Found - Model→Agent shell
npm search "markdown parser" - Agent shell→npm registry
GET /-/v1/search?text=... - npm registry→Agent shell
names + descriptions - Model→Agent shell
npm view chosen-pkg readme - Model→Agent shell
npm install chosen-pkg
Whether the model performs the verification step at all is a model behaviour, not a tool feature. Many sessions go straight from a remembered name to npm install, and that’s exactly where hallucinated names do their damage.
Package hallucination: what the research measured
Section titled “Package hallucination: what the research measured”The strongest evidence I’ve found that training data and live lookup diverge comes from the package-hallucination studies.
- Spracklen et al., “We Have a Package for You!” (arXiv 2406.10279, USENIX Security 2025) generated 576,000 code samples in Python and JavaScript with 16 code LLMs. About 19.7% of the packages referenced did not exist; the rate was at least 5.2% for commercial models and 21.7% for open-source models, and the study found 205,474 unique hallucinated names. Many hallucinated names recurred across repeated prompts, which is what makes them registrable by an attacker documented.
- Djire et al., “Evaluating Inference-Time Defenses Against Package Hallucination” (arXiv 2608.22652, ASE 2026) tested 8 models across Python, JavaScript, Ruby and Rust. Retrieval-augmented generation reduced hallucination in only 18 of 32 model-language configurations, prompts seeded with fake package names raised the rate by up to 45 percentage points, and earlier studies overstated Python rates by up to 9.4 points by counting standard-library modules as hallucinations documented.
- The
huggingface-clicase. Bar Lanyado of Lasso Security registered a name that models kept inventing; it received roughly 15,000 to 30,000 real downloads in three months (reports differ), and an Alibaba repository’s README told users to install it (Willison, The Register) documented. - The attack has a name, slopsquatting, credited to Seth Larson of the PSF (Socket glossary).
What to put in the registry
Section titled “What to put in the registry”- Description: one plain sentence with the task words a developer would search (“Rate limiter for Express backed by Redis”), not a tagline.
- Keywords: 5-10 literal terms, including the problem category and the frameworks you integrate with. npm and crates.io match on them.
- README first screen: the install command, a minimal working example and the current major version. Agents that run
npm view pkg readmeor read the PyPI JSONdescriptionfield often read only the head of the output. repository,homepageand PyPIproject_urls: point to the GitHub repo and a docs URL that serves clean HTML or Markdown, so the agent’s next hop lands somewhere fetchable. See GitHub and docs sites.- Deprecations and renames: deprecate old names with a message naming the replacement (
npm deprecate), because npm search drops deprecated packages and the message is what an agent sees when it installs a remembered old name. - Don’t register hallucinated variants as traps. Registering a name to catch mistaken installs is only defensible as a clearly labelled stub that you own and that points to the real package, and registries may still reject it.
Tests to run
Section titled “Tests to run”The test catalog has the full procedures. The two most useful ones for registries are a dilution ladder (ask each agent for a library by brand name, then by category, then by bare capability, with web tools off and on, and record where your package drops out) and a version-skew probe (ask for the install command and check whether the agent cites your latest major version or the one in its training data).
Open questions
Section titled “Open questions”- Whether npm’s API-level quality, popularity and maintenance weights still influence
npm searchordering. - How often each agent verifies a package with the registry before installing it; this needs transcript-level measurement across many sessions.
- Whether registry download counts feed back into training-data prominence for later models.
Further reading
Section titled “Further reading”- npm: searching for and choosing packages
- npm registry API documentation
- PyPI JSON API
- Spracklen et al., package hallucinations
- Djire et al., inference-time defences
- MCP Registry quickstart
Last reviewed 2026-12-02 against npm, PyPI and crates.io public documentation. This site is re-reviewed monthly; see maintenance.