[Feature Request] Built-in Claude Code (and other AI coding agent) PreToolUse hook subcommand
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start with the existing package-manager matching that sfw supports and the sfw --help entry point, then review the proposed Claude Code settings.json hook and its stdin JSON payload. Define the hook subcommand's pass-through, blocking exit, stderr message, and retry hint behavior; done means matching installs are blocked while sfw-prefixed commands pass through.
Written by the indexing model from the issue text.
Description
Summary
Add a built-in subcommand — e.g. sfw hook claude — that reads a Claude Code PreToolUse JSON event on stdin and gates the tool call, blocking package-install commands that aren't already prefixed with sfw.
Why this matters
LLM coding agents (Claude Code, Cursor, Aider, Codex, etc.) routinely run npm install, pip install, uvx <tool>, cargo add etc. on the developer's behalf. They're arguably the highest-risk path for malicious package install today:
- Agents can be steered into installing typosquatted or compromised packages via prompt injection
- Agents iterate fast and don't pause for human review on every install
- Reviewers of agent diffs often miss a subtle dependency tucked into a refactor
Wrapping these agents' package-manager calls with sfw is therefore more valuable than wrapping a careful human's. Claude Code's hook mechanism fires before tool execution and can block calls — with a small wrapper script, sfw already serves as that gate today, but every team has to roll the same script themselves.
Current workaround (what teams are already doing)
A bash script invoked from ~/.claude/settings.json:
#!/bin/bash
input=$(cat)
cmd=$(printf '%s' "$input" | jq -r '.tool_input.command // ""')
echo "$cmd" | grep -qE '(^|[[:space:];&|]+)sfw[[:space:]]' && exit 0
echo "$cmd" | grep -qE 'npm[[:space:]]+(install|i|add|exec|ci)|npx[[:space:]]+[^-]|yarn[[:space:]]+(add|install)|pnpm[[:space:]]+(add|install|i|dlx)|pip3?[[:space:]]+install|uv[[:space:]]+(pip[[:space:]]+install|add|tool[[:space:]]+install|run)|uvx[[:space:]]+[^-]|cargo[[:space:]]+(install|add)' && {
echo "Socket Firewall guard: prefix with sfw — sfw $cmd" >&2
exit 2
}
exit 0
…plus the settings.json wiring:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [{ "type": "command", "command": "/path/to/sfw-gate.sh" }]
}
]
}
}
It works, but it's per-team boilerplate that drifts out of sync as sfw adds support for new package managers.
Proposal
Ship the gate as a first-class sfw subcommand so settings.json becomes one line:
{
"type": "command",
"command": "sfw hook claude"
}
The subcommand:
- Reads
PreToolUseJSON from stdin - Allows pass-through if the inner command is already
sfw-prefixed - Blocks (exit 2 with a stderr message) any matching install/exec command
- Returns a retry hint the agent can act on:
Re-run as: sfw <original command>
Pattern matching can stay in lockstep with the package managers sfw already supports — that's the main maintenance win over per-team scripts.
Prior art
rtk hook claude (from another tool, rust token killer) ships exactly this pattern — single subcommand that drops into the Claude Code hook slot with no wrapper.
Benefits
- Zero per-team boilerplate for
sfw+ Claude Code adoption - One canonical implementation that stays current as new package managers are added
- Lower bar for security-minded teams to harden their agent setups
- Discoverable:
sfw --helpbecomes the entry point
Open questions
- Generalize to
sfw hook <agent>to support Cursor / Aider / Codex / Continue.dev? Hook payload shapes differ across agents. - Should the block message include the proposed
sfw-prefixed retry command verbatim? (Helps the agent auto-retry without a human round-trip.) - Should there be an env var or flag for "warn but don't block" mode for teams rolling this out gradually?
- Worth detecting nested invocations (
bash -c 'npm install foo', heredocs, etc.) inside the inner command?
Happy to submit a starter PR if there's interest in the direction.
- Dominant language
- No language data
- Stars
- 271
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SocketDev/sfw-free
-
Difficulty 1/5 Under an hour Newbie friendliness 87/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in SocketDev/sfw-free
Similar issues
-
manually bump balena-preload to ^19.0.6Possibly taken @shaunmulligan claimed this today. Open
Difficulty 1/5 1-3 hours Newbie friendliness 66/100
balena-io/balena-cli#3200 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
ranxianglei/billion-context#7858 ·
Maintainers usually reply within 1 day
-
Bash init calls `cygpath` unconditionally on Windows, which breaks non-Cygwin shells like `brush`Possibly taken @iliqiliev claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ajeetdsouza/zoxide#1381 ·
Maintainers usually reply within 5 days
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
MakazhanAlpamys/Soup#3415 ·
Maintainers usually reply within 1 day