Skip to content

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.

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.

Registry paths from a coding agent to your package metadataDeveloper machineRegistryYour propertyAgent shell toolBash / execnpm / pip / cargoCLI user agentcurlcurl/8.xregistry.npmjs.org/-/v1/search, /pkgpypi.org/pypi/name/jsoncrates.io/api/v1/crates?q=README + keywordspublished with pkgGitHub reporepository fieldDocs sitehomepage field12 npm view pkg3 JSON lookupserved copyproject_urlshomepage
Registry paths from a coding agent to your package metadataDeveloper machineRegistryYour propertyAgent shell toolBash / execnpm / pip / cargoCLI user agentcurlcurl/8.xregistry.npmjs.org/-/v1/search, /pkgpypi.org/pypi/name/jsoncrates.io/api/v1/crates?q=README + keywordspublished with pkgGitHub reporepository fieldDocs sitehomepage field123abc
  1. npm / pip / cargo → registry.npmjs.orgnpm view pkg
  2. curl → pypi.orgJSON lookup
  3. registry.npmjs.org → README + keywordsserved copy
  4. pypi.org → GitHub repoproject_urls
  5. crates.io → Docs sitehomepage
All registry traffic is issued from the developer's machine through the shell. Your docs site sees none of it unless the README sends the agent there.
RegistrySearch surfaceWhat is matched and rankedEvidence
npm (website and npm search)OpenSearch over title, description, README and keywordsKeyword 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 unclearinferred
PyPINo 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 datadocumented
crates.ioGET /api/v1/crates?q= and cargo searchRelevance over name, description, keywords and categories; no published formulainferred
MCP Registryregistry.modelcontextprotocol.ioDistribution 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.

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:

Terminal window
npm view some-package # description, versions, repository, homepage
npm view some-package readme # README as published
npm search "markdown parser" # keyword search
curl -s https://pypi.org/pypi/some-package/json | head -c 4000
pip index versions some-package
cargo search some-crate --limit 5

Sandboxing 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 itModelAgent shellnpm registry1. npm view fast-md-parse2. GET /fast-md-parse3. 404 Not Found4. npm search "markdown parser"5. GET /-/v1/search?text=...6. names + descriptions7. npm view chosen-pkg readme8. npm install chosen-pkg

An agent verifying a package before installing it

  1. Model→Agent shell
    npm view fast-md-parse
  2. Agent shell→npm registry
    GET /fast-md-parse
  3. npm registry→Agent shell
    404 Not Found
  4. Model→Agent shell
    npm search "markdown parser"
  5. Agent shell→npm registry
    GET /-/v1/search?text=...
  6. npm registry→Agent shell
    names + descriptions
  7. Model→Agent shell
    npm view chosen-pkg readme
  8. 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-cli case. 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).
  1. Description: one plain sentence with the task words a developer would search (“Rate limiter for Express backed by Redis”), not a tagline.
  2. Keywords: 5-10 literal terms, including the problem category and the frameworks you integrate with. npm and crates.io match on them.
  3. README first screen: the install command, a minimal working example and the current major version. Agents that run npm view pkg readme or read the PyPI JSON description field often read only the head of the output.
  4. repository, homepage and PyPI project_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.
  5. 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.
  6. 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.

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).

  • Whether npm’s API-level quality, popularity and maintenance weights still influence npm search ordering.
  • 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.

Last reviewed 2026-12-02 against npm, PyPI and crates.io public documentation. This site is re-reviewed monthly; see maintenance.