Shai-Hulud Cleanup.
Personal toolkit of shell scripts with a bundled Claude Code skill. It finds and removes the damage a supply-chain worm in JavaScript packages does to Git repositories (forged commits, obfuscated build configs, editor tasks that run on folder open) and guards against a repeat, locally and on the server side.
- Year
- 2026
- Personal project
- My part
- Sole developer
- Website
- Not public
- No public link
My role
I designed and wrote the whole toolkit alone, from the detection library to the guards, the cleanup scripts and the Claude Code skill.
Capabilities
Detection
- Three signature tiers, with infection decided on the current tree of every branch and tag
- Bulk scan of a code root and a deep per-repository report with a suggested action
- No-clone scan through the GitHub API for one repository, a list, or every repository an account can push to
Cleanup
- Five scripts for five repository states, chosen by a decision matrix
- Surgical recovery that keeps legitimate changes from a poisoned branch and drops payload folders
- Batch orchestrator that plans first and acts only with an explicit flag, and a remote reset with a dry-run plan and a lease on every branch
Prevention
- Five global Git hooks, including one that aborts a fetch or clone whose remote tip carries a payload
- Machine installer with optional steps and a verifier, plus a daily scheduled scan with desktop notification
- Server-side rulesets and a GitHub Actions workflow that resets a branch on a hit
- Audit that finds repositories whose own hook path switches the global guard off
Claude Code
- Bundled skill with a playbook, a decision tree and reference notes
- Command guard that blocks one-shot package runners and global installs, with 30+ self-test checks for the hooks
Patterns and decisions
The toolkit is plain Bash with no build step and no dependencies. Every script shares one detection library. The Git hooks repeat its patterns on purpose, so they run in any repository without loading anything. They are installed as the global Git hook path and read from the toolkit folder each time, so a new pattern reaches every repository with a plain pull of the toolkit.
Infection is decided on the current tree of every branch and tag. A search through history also matches the commit that cleans a repository, so it serves forensics only. Remote content goes from the network straight into a pattern match through pipes and never touches the disk.
No destructive command runs without a lease: every forced push checks that the remote branch is still where the scan saw it. A batch run prints a plan first and acts only on an explicit flag. The guards have three escape hatches, each meant to be typed for one command and never exported. The bundled Claude Code skill forbids setting them unless the conversation asks for it. More than 30 self-test checks replay clean and infected fetches, pulls, clones and the overrides.
Cases
Deciding what counts as infected. Obfuscator-style names also appear in honest minified libraries, so a naive scanner either cried wolf or never reported clean. I split the signatures into three tiers. Markers that exist only in the attack are flagged anywhere. Patterns that real libraries share count only inside sensitive files such as build configs and editor settings. Structural tells cover payloads with no marker: a font file that Git reads as text, an editor task that runs on folder open and executes an asset, and an ignore file that stops excluding the editor folder. A scan of a whole code root is fast enough to run daily.
Rescuing real work from a poisoned branch. The forged commit on the remote often mixed my own changes with the payload, so a reset lost work and trusting the branch kept the payload. The surgical recovery keeps the remote version of each changed file unless it sits in a sensitive path, was deleted, or carries a signature. One bad file drops its whole folder. A final scan of the staged diff aborts on any hit, and the result is committed forward and pushed with a lease. When nothing legitimate remains, the script falls back to a plain push of the clean local branch.
Refusing a bad pull before it reaches the working tree. A hook on commit and push does nothing when the poisoned commit arrives from the remote. I added a hook that runs inside every reference update and aborts it on a hit. The objects are already downloaded, so the scan is local, and the remote branch never advances on this machine. Nothing can merge, rebase or reset onto it. Clones are refused too. A hook manager can override the hook path per repository and switch the global hooks off without a sound, so an audit lists such repositories and chains the guard back in.
Cleaning without a clone. A clone of a live payload puts it on disk in front of the antivirus. The remote scan goes through the GitHub API: it lists each branch tip as paths and blob hashes, downloads only the blobs at the known payload locations, and caches verdicts by hash. The reset route reads the push activity log to find the overwritten commit and the latest recorded push, which serves as the lease. It prints a dry-run plan, checks every branch before writing any, and writes only with an apply flag.