# 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 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](https://nx.dev/blog/s1ngularity-postmortem) · [Nx security advisory GHSA-cxm3-wv7p-598c](https://github.com/nrwl/nx/security/advisories/GHSA-cxm3-wv7p-598c)

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](https://github.com/nrwl/nx/security/advisories/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](https://www.stepsecurity.io/blog/supply-chain-security-alert-popular-nx-build-system-package-compromised-with-data-stealing-malware) · [GHSA-cxm3-wv7p-598c](https://github.com/nrwl/nx/security/advisories/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](https://www.excellent.so/guides/yolo-mode-ai-agents)

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](https://www.wiz.io/blog/s1ngularity-supply-chain-attack)

## 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.txt` on the machine.
- Run `npm ls nx` (and the same for the plugins) to see which version you have, remove `node_modules`, clear your package manager’s cache and install a current version.
- Remove the `shutdown` line from `.bashrc` and `.zshrc`.
- Rotate every credential the machine could reach: GitHub and npm tokens, SSH keys, cloud keys and anything in `.env` files. Revoke the GitHub CLI’s authorization and sign in again.

[Nx’s remediation steps](https://github.com/nrwl/nx/security/advisories/GHSA-cxm3-wv7p-598c)

## 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](https://nx.dev/blog/s1ngularity-postmortem)

## How to prevent it

**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](https://www.excellent.so/guides/ai-agent-policy-template)

**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](https://www.excellent.so/scan) · [Public AI agent incidents](https://www.excellent.so/incidents)

Source: https://www.excellent.so/guides/nx-s1ngularity-ai-cli-supply-chain-attack
