The Nx “s1ngularity” attack: malware that ran AI agents to find secrets
In August 2025 malicious Nx packages on npm ran Claude Code, Gemini CLI and Amazon Q with permission-skipping flags to search developers’ machines for secrets. What happened, what was taken and what to change.
On this page
- When
- August 26–27, 2025
- Agents used
- Claude Code, Gemini CLI, Amazon Q’s CLI
- What was hit
- Machines that installed the bad versions: tokens, SSH keys, .env files, wallets
- Outcome
- ✕Secrets published to public GitHub repositories
- Fix
- ✓Versions removed after about four hours; Nx moved to trusted publishing
On August 26, 2025, an attacker published malicious versions of Nx, a JavaScript build system with about six million weekly installs, to npm. The versions were live for about four hours. Their install script searched the machine for credentials and uploaded what it found to a public GitHub repository in the victim’s own account. Part of the search was handed to AI agents: if Claude Code, Gemini CLI or Amazon Q’s CLI was installed, the script ran it with the flag that skips approval prompts and asked it to find secret files. Nx’s postmortem · Nx security advisory GHSA-cxm3-wv7p-598c
- August 21
Damage: A workflow that puts pull request titles into a shell command is added.
- August 24
Damage: Nx believes the attacker used it to send the npm publishing token to a webhook.
- Aug 26, 6:32 PM
Damage: Malicious versions are published. Their install script runs installed AI CLIs with approvals off.
- Aug 26, 10:44 PM
Fixed or contained: npm removes the versions and revokes Nx’s tokens.
- Afterwards
Fixed or contained: Nx moves to trusted publishing with a manual approval for every release.
The attack did not exploit a bug in any of those agents. It used them as they were designed to be used, with the safety prompts turned off by a command-line flag. That is why it matters to anyone who runs AI agents on a machine that also holds credentials.
What happened
| When (US Eastern, per Nx’s advisory) | Event |
|---|---|
| August 21, 2025 | A pull request introduced a GitHub Actions workflow that ran on pull_request_target and put pull request titles into a shell command without sanitizing them. |
| August 24 | Nx believes, from its audit logs, that the attacker used that injection to make the workflow send Nx’s npm publishing token to a webhook. |
| August 26, 6:32 to 8:37 PM | Malicious versions of nx and several @nx/* plugins were published with the stolen token. |
| August 26, 10:44 PM | npm removed the malicious versions and revoked Nx’s tokens. The affected @nx/key and @nx/enterprise-cloud versions were removed at 6:20 AM the next morning. |
The affected nx versions were 20.9.0, 20.10.0, 20.11.0, 20.12.0, 21.5.0, 21.6.0, 21.7.0 and 21.8.0, plus some versions of @nx/devkit, @nx/js, @nx/workspace, @nx/node, @nx/eslint, @nx/key and @nx/enterprise-cloud. The advisory lists them all. GHSA-cxm3-wv7p-598c
How the AI agents were used
Nx’s postmortem says the post-install script “attempted to use local AI tools (like Claude and Gemini)”. StepSecurity, which analyzed the payload, published the code that did it. For each tool it found, the script ran:
| Tool | Command the malware ran |
|---|---|
| Claude Code | claude --dangerously-skip-permissions -p PROMPT |
| Gemini CLI | gemini --yolo -p PROMPT |
| Amazon Q CLI | q chat --trust-all-tools --no-interactive PROMPT |
The prompt asked the agent to search the file system for files that looked like secrets and write their paths to /tmp/inventory.txt. The script then collected environment variables, GitHub and npm tokens, SSH keys, .env files and cryptocurrency wallet files, encoded them and pushed them to a new public repository named s1ngularity-repository in the victim’s GitHub account. It also appended sudo shutdown -h 0 to the user’s .bashrc and .zshrc. StepSecurity’s analysis · GHSA-cxm3-wv7p-598c
Each of those flags is a documented option. --dangerously-skip-permissions in Claude Code and --yolo in Gemini CLI run every tool call without asking; --trust-all-tools does the same in Amazon Q’s CLI. With a human at the keyboard they are a convenience. Inside a malicious script they turn an installed agent into a search tool that runs with your access. What YOLO modes turn off
Nx did not publish a count of affected users. Wiz, which tracked the public repositories the malware created, reported more than a thousand valid GitHub tokens in the first phase, and in a second phase on August 28 and 29 counted more than 400 users and organizations whose private repositories had been made public with stolen tokens. Those are Wiz’s figures. Wiz’s analysis
If you installed an affected version
Nx’s advisory lists the steps. In short:
- Check your GitHub account’s security log and repositories for one named
s1ngularity-repository, and check for/tmp/inventory.txton the machine. - Run
npm ls nx(and the same for the plugins) to see which version you have, removenode_modules, clear your package manager’s cache and install a current version. - Remove the
shutdownline from.bashrcand.zshrc. - Rotate every credential the machine could reach: GitHub and npm tokens, SSH keys, cloud keys and anything in
.envfiles. Revoke the GitHub CLI’s authorization and sign in again.
What Nx changed
Nx stopped using long-lived npm tokens and moved to npm’s Trusted Publishers, which authenticates publishing from its CI with OIDC. Every release now needs a manual approval, pipeline runs for outside contributors are disabled, and the vulnerable workflow is gone. Nx’s postmortem
How to prevent it
- Every engineer’s laptop
✓Approvals stay on
Skip-permission and YOLO modes only in a disposable container with no keys or tokens.
How → - CI and the package registry
✓Short-lived publishing
Trusted publishing (OIDC) and a manual approval for releases, so no long-lived token sits in CI.
- GitHub, npm, cloud, SSH
✓Rotate what it could reach
After a bad install, revoke and reissue every credential on the machine.
- Session logs
✓Know what ran
Which machines installed the package, and which agent sessions ran with approvals off.
How →
An installed agent is a capability any code on the machine can use. A post-install script runs with your user’s rights, so it can run any program you can run, with any flag. The approval prompt only protects you when the agent is started without the flag that removes it.
Keep permission-skipping modes in disposable environments. Run skip-permission and YOLO modes in a container or VM that has no production credentials, no SSH keys and no publishing tokens. On an everyday laptop, keep approvals on. AI agent policy template, clause 4
Treat publishing credentials as the target. The root cause was a CI workflow that let an outsider read a publishing token. Short-lived, CI-bound publishing (trusted publishing, OIDC) and a manual approval for releases close that path.
Know what ran on your machines. After an incident like this the first question is which machines installed the package and which sessions ran with approvals off. Excellent’s free scan reads supported agents’ session logs on a Mac and reports risky actions such as force pushes and keys that ended up in a log, after the fact. It reads agents’ logs; it would not detect a malicious npm package by itself. Run the free scan · Public AI agent incidents





