Tegoby Attention SpanBlogBook a demo

The npm worm that planted AI agent hooks

Strict rules refuse key steps

In August 2026, a self-spreading npm package, the ChainDrop worm, stole credentials from machines that installed it and planted a startup command for Claude Code in repositories. With strict rules and the list of programs tego learn proposes after one normal run, Tego would refuse the tool the worm needs to fetch and run. We reproduced the incident's steps under these rules to confirm it.

What happened?

The details come from StepSecurity's report, last updated 4 August 2026 at 18:10 UTC, when the count of poisoned packages was still rising.

According to StepSecurity, an attacker who took over a maintainer's GitHub account pushed poisoned commits to three repositories. The projects' own release workflows then published keyv@6.0.0 and ten more packages, with valid provenance, the signature that says a package was built from its repository.

Each package gained a preinstall line (node setup.mjs), a command npm runs automatically before installing, and two files: a dropper (a small script that fetches and starts the real attack) and a second stage. The dropper downloads Bun v1.3.13, a JavaScript runtime like Node, from Bun's GitHub releases, or uses a Bun already installed. It then runs the 727,680-byte second stage.

The second stage harvests npm, GitHub, AWS, Kubernetes and Vault credentials, plus AI tool logins such as .codex/auth.json and .cursor/credentials.json, and sends them to a server it finds through an Ethereum contract. With stolen tokens it republished itself: 444 packages and 2,212 versions in under four hours, by StepSecurity's count.

It also pushed two files to every eligible branch it could reach. .claude/settings.json holds a SessionStart hook (a command Claude Code runs every time a session starts). .vscode/tasks.json holds a task that runs when the folder opens. The commits use the author name claude to pass as AI assistant output, StepSecurity says.

StepSecurity and Unit 42 say the hook runs node .vscode/setup.mjs; Elastic Security Labs says node .claude/setup.mjs. Unit 42 adds that "only the VS Code path reaches a payload at all", so the Claude Code hook found nothing to run. No source shows it stealing anything.

StepSecurity found ten runs in a public project's CI that reached the worm's server, with "no evidence of credential loss" there. Unit 42 describes a developer's VS Code case where Bun ran the payload; details such as cmd.exe point to Windows. No source says an AI agent ran the poisoned install, but AI agents run npm install all the time.

Why didn't the usual safety catch it?

StepSecurity puts it plainly: "Any machine or CI job that installed an affected version executed attacker code with full user privileges."

npm runs install scripts by default. Claude Code runs the hooks in a project's settings once the folder is trusted, and its hooks documentation says a print-mode (-p, one-shot) session treats the folder as trusted. Neither is a bug, but agent settings are code in the repository, and anything that can write the repository can change them.

How it could have been prevented

The general habit: decide what a run may start, change and reach, and refuse everything else from outside the agent. You don't need to know this worm in advance; a new runtime, an unlisted host and a new agent settings file are refused because nobody listed them.

Tego's strict setup is three built-in rule sets: the agent can't read your secrets, can only reach the hosts you list, and can only change files in the folders you name. The setup's last step adds a list of allowed programs: after one normal run, tego learn proposes the programs that run started. Bun isn't on it, so an installed Bun fails to start with a permission error (contract semantics; what each level enforces). The download from github.com is refused, and the run can't start programs from the temp folder the dropper uses. With no Bun, the second stage never runs: no credential sweep, no republishing, no new hooks. See the strict setup for the full file and the learn step.

In Tego's rules file, that's:

YAML
extends: [tego/no-secrets, tego/no-prod, tego/repo-only-writes]
fs:
  write: ["./src/", "./tests/", "./node_modules/"]   # tego init adds node_modules for package.json
net:
  allow: ["registry.npmjs.org:443"]                  # not github.com

Started in a poisoned clone, Claude Code should run the planted hook inside the run, and the same refusals follow. It needs no root, but a kernel with Landlock ABI 2 or newer and cgroup v2, so not Ubuntu 22.04's stock 5.15 kernel (TIERS). The print-mode Claude Code example shows the rest, and validates against the schema; we have not run it on a real project. The cost: ./node_modules/ stays writable for test runners, so anything written there can run, a Bun from the bun npm package included. Packages that download from other hosts, such as browser test tools, fail.

The honest limit: a variant that runs its second stage under node would pass the program list, since an allowed interpreter "can do anything in-process" (Tego's known limits, item A2), and Claude Code's own Linux binary is built with Bun (example).

How Tego handles it

Without the program list, here is what Tego does when the agent runs npm install and gets a poisoned version.

  • The dropper starts. npm runs sh -c "node setup.mjs", two ordinary programs.
  • The Bun download is refused. github.com:443 is not an allowed host, and Tego checks this even on 6.1 kernels (contract semantics; what each level enforces).
  • The plants are refused. The agent may not write the project's top folder, so the worm can't create ./.claude/ or ./.vscode/ (README). Tego also always refuses writes to .claude, .vscode, .cursor, .codex, .gemini and .mcp.json at the top of each writable folder and each repository inside one (contract semantics).
  • Secret files stay closed. Tego's built-in list blocks ~/.npmrc, ~/.config/gh, ~/.aws, ~/.ssh and the Claude Code, Codex and Gemini token stores (contract semantics).
  • Every refusal is recorded. Without root, Tego calls that record "advisory against a hostile process" (what each level enforces).

The gap: a Bun already installed would run, and the stealer with it; the program list closes that. And the poisoned files still install, so opening a planted clone in VS Code or in an agent outside Tego runs the dropper.

Other edges: the secret list misses .cursor/credentials.json, and the model key you pass is in the run. Data can leave through any allowed host (Tego's known limits, item A1), here the npm registry, where a token in a project .npmrc could publish. Without root, Tego's write blocks inside writable folders are "not race-free" (Tego's feature list, item S1), so the top folder is never writable. The account takeover, the workflows and the registry never ran under Tego (Tego's known limits, item A5). And for the Windows case, all of this applies only on Linux.

The lesson

An agent that installs dependencies runs other people's code with your access. Agent settings files are a target because they turn a clone into a command. List what a run may start, write and reach, keep the project's top folder and agent settings off the write list, and install with scripts off where you can, as StepSecurity advises.

Sources (10 links)

Checked on 5 November 2026.