You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Claude Code pre-tool hook that checks new dependencies against [Socket.dev](https://socket.dev) before they're added to the project. It runs automatically every time Claude tries to edit or create a dependency manifest file.
4
-
5
-
## What it does
6
-
7
-
When Claude edits a file like `package.json`, `requirements.txt`, `Cargo.toml`, or any of 17+ supported ecosystems, this hook:
8
-
9
-
1.**Detects the file type** and extracts dependency names from the content
10
-
2.**Diffs against the old content** (for edits) so only *newly added* deps are checked
11
-
3.**Queries the Socket.dev API** to check for malware and critical security alerts
12
-
4.**Blocks the edit** (exit code 2) if malware or critical alerts are found
13
-
5.**Warns** (but allows) if a package has a low quality score
14
-
6.**Allows** (exit code 0) if everything is clean or the file isn't a manifest
15
-
16
-
## How it works
1
+
# check-new-deps
2
+
3
+
A **Claude Code hook** that runs whenever Claude tries to edit or
4
+
create a dependency manifest (`package.json`, `requirements.txt`,
5
+
`Cargo.toml`, and 14+ other ecosystems). It extracts the
6
+
*newly added* dependencies, asks [Socket.dev](https://socket.dev) if
7
+
any of them are known malware or have critical security alerts, and
8
+
**blocks** the edit if so.
9
+
10
+
> If you haven't worked with Claude Code hooks before: hooks are tiny
11
+
> scripts that run at specific lifecycle points. A `PreToolUse` hook
12
+
> like this one fires *before* Claude calls a tool (here, `Edit` or
13
+
> `Write`). It can either **prime** (write to stderr, exit 0, model
14
+
> carries on) or **block** (exit 2, edit never happens). This one
15
+
> blocks for malware/critical findings and primes for low-quality
16
+
> warnings.
17
+
18
+
## What it does, step by step
19
+
20
+
1. Claude tries to edit `package.json` (or any other supported
21
+
manifest).
22
+
2. The hook reads the proposed edit from stdin.
23
+
3. It detects the file type and extracts dependency names from the
24
+
new content.
25
+
4. For an `Edit` (not a `Write`), it diffs new content vs. old, so
26
+
only *newly added* dependencies get checked — existing deps
27
+
aren't re-scanned every time you bump an unrelated version.
28
+
5. It builds a [Package URL (PURL)](https://github.com/package-url/purl-spec)
29
+
for each new dep and calls Socket.dev's `checkMalware` API.
30
+
6. Three outcomes:
31
+
-**Malware or critical alert** → exit `2`. Edit is blocked,
32
+
Claude reads the alert reason from stderr and either picks a
33
+
different package or asks the user.
34
+
-**Low quality score** → exit `0` with a warning. Edit proceeds.
API responses are cached in-memory for 5 minutes (max 500 entries) to avoid redundant network calls when Claude checks the same dependency multiple times in a session.
124
+
| Code | Meaning | What Claude does next |
125
+
|------|---------|----------------------|
126
+
|`0`| Allow | Edit/Write proceeds normally. |
127
+
|`2`| Block | Edit/Write is rejected; Claude reads the block reason from stderr. |
96
128
97
-
## Exit codes
129
+
## Cross-fleet sync
98
130
99
-
| Code | Meaning | Claude behavior |
100
-
|------|---------|----------------|
101
-
| 0 | Allow | Edit/Write proceeds normally |
102
-
| 2 | Block | Edit/Write is rejected, Claude sees the error message |
0 commit comments