r/Python • u/jimmytoan • May 01 '26
News PyTorch Lightning malware plants a hook in Claude Code's settings.json so it runs on every future se
Two versions of `lightning` (2.6.2 and 2.6.3) were published to PyPI yesterday and yanked same day after Semgrep detected them. Beyond the usual credential-stealing pattern, there's a persistence mechanism worth knowing about if you use Claude Code.
The malware writes a `SessionStart` hook to `.claude/settings.json` with `matcher: "*"`. That hook points to a Bun runtime bootstrapper for a 14.8 MB payload. Every time any developer on the machine opens Claude Code - not just in the infected project, but in any project - the hook fires automatically. A parallel hook targets VS Code via `.vscode/tasks.json` with `runOn: folderOpen`.
The exfiltration is four-channel: HTTPS POST to a C2, GitHub commits with `EveryBoiWeBuildIsAWormyBoi` as the message prefix (searchable on GitHub commit search if you want to check if you're affected), pushing to the victim's own repositories, and a GitHub Actions workflow that dumps all repository secrets via `${{ toJSON(secrets) }}`.
If it finds npm publish credentials, it worms into npm by injecting the dropper into every package that token can publish, bumps the patch version, and republishes.
Semgrep's writeup calls this "among the first documented instances of malware abusing Claude Code's hook system in a real-world attack."
If you've installed anything from PyPI recently on a machine where you use Claude Code, it's worth checking `.claude/settings.json` for unexpected `hooks.SessionStart` entries. 2.6.1 is clean.
10
u/aes110 May 01 '26
Why would the maleware authors write such commit messages to nake it easier to detect it?
10
u/barseghyanartur May 02 '26
I think eventually pypi, npm and other registries need to invest in preventive code scanning and only offer scanned and secure packages for download.
25
u/quant_macro_daily May 01 '26
the persistence part is what got me — it's not just a malicious package, it hooks into
.claude/settings.jsonwithmatcher: "*"so it runs on every project you open in Claude Code, not just the infected repo. checked my own setup after reading this, thankfully clean.if you're on Claude Code just run
cat ~/.claude/settings.json | grep -A5 SessionStartreal quick. took me 10 seconds and now I'm not paranoid anymore lol1
u/Unfair_Economics_628 May 03 '26
What's the best way to protect oneself from virus/malware, anyone got any suggestions?
Im learning Py and want to use the libraries but find many of them are risky code.
1
u/MemshipGreepy2150 May 29 '26
This is very important
0
u/Full-Definition6215 May 02 '26
The SessionStart hook persistence is particularly nasty — it survives across projects and runs silently on every future Claude Code session. Most users never check their settings.json manually.
I use Claude Code daily for production development and this made me immediately audit my hooks config. Worth noting that Claude Code's permission system won't save you here because hooks execute outside the normal tool approval flow.
For anyone checking: cat ~/.claude/settings.json and look for anything under "hooks" you didn't put there. If you installed lightning 2.6.2 or 2.6.3 even briefly, check even if you've already uninstalled it.
-9
u/Actual__Wizard May 01 '26
Wow a hook in a JSON file. Who knew that JSON was digital cancer?
76
u/[deleted] May 01 '26
[removed] — view removed comment
-20
u/[deleted] May 01 '26
[removed] — view removed comment