Block Compromised NPM/PyPI Packages Automatically with attach-guard

Block Compromised NPM/PyPI Packages Automatically with attach-guard

A new Claude Code plugin uses PreToolUse hooks to automatically block compromised packages like the recent axios hijack before they install.

GAla Smith & AI Research Desk·4h ago·4 min read·5 views·AI-Generated
Share:
Source: dev.tovia devto_claudecodeSingle Source
Block Compromised NPM/PyPI Packages Automatically with attach-guard

The Problem: AI Agents Install Without Asking

When you tell Claude Code to add a dependency, it runs npm install or pip install immediately. There's no safety check. Last week, axios@1.14.1 was hijacked on npm. Days before, litellm@1.82.8 on PyPI. Both were compromised versions published through hijacked maintainer accounts.

Claude Code would have installed both without hesitation. By the time you notice, the malicious code has already executed.

The Solution: attach-guard Plugin

attach-guard is an open-source Claude Code plugin that intercepts every package install command before execution. It evaluates packages against Socket.dev's supply chain risk data and blocks them if they fail security policies.

Cover image for I built a Claude Code plugin that blocks compromised packages before installation

Critical distinction: This uses Claude Code's PreToolUse hooks, not skills or MCP servers. Hooks run automatically on every matching tool call—Claude cannot skip or override them. This is enforcement, not advice.

How It Works

When Claude runs npm install axios, attach-guard:

  1. Intercepts the command before it executes
  2. Scores the package via Socket.dev's API (malware detection, maintainer history, code changes)
  3. Blocks if it fails policy (malware, score below 50, published <48 hours ago)
  4. Rewrites to safe version when possible, doesn't just say "no"

Real examples from the developer:

  • npm install axios → latest (1.14.1) scores 40/100 → blocked → rewrites to axios@1.14.0 (71/100)
  • pip install litellm==1.82.8 → compromised → denied

What it catches:

  • Known malware and compromised packages
  • Packages published less than 48 hours ago (too new to trust)
  • Low supply chain scores (below 50 = denied, 50-70 = flagged)
  • Supports npm, pip, Go, and Cargo

Install in 2 Commands

claude plugin marketplace add attach-dev/attach-guard
claude plugin install attach-guard@attach-dev

During setup, it prompts for a Socket.dev API token (free tier available). The plugin is MIT licensed with no data collection.

Why This Matters Now

Supply chain attacks are increasing. AI coding agents like Claude Code execute commands autonomously, creating new attack surfaces. This follows Claude Code's recent Computer Use feature launch (March 30, 2026), which expanded app-level permissioning and potential attack vectors.

Without tools like attach-guard, you're trusting every package registry to be perfectly secure—which recent history proves isn't true.

Configuration Tips

After installation, you can customize policies in your Claude Code configuration:

  • Adjust score thresholds (default: deny <50, flag 50-70)
  • Change the "new package" window from 48 hours
  • Enable/disable specific package managers

The plugin works silently in the background. You'll only see output when it blocks or flags something, keeping your workflow clean.

gentic.news Analysis

This plugin represents a critical security layer for Claude Code's autonomous execution model. It directly addresses the risk highlighted in our March 30 coverage of Claude Code's Computer Use feature, which expanded attack surfaces by granting app-level permissions.

The use of PreToolUse hooks is significant—it ensures enforcement rather than advisory protection. This aligns with the broader trend of Model Context Protocol (MCP) integration (mentioned in 77 prior articles), where Claude Code's architecture connects to various security and tooling backends.

Interestingly, this security-focused development comes amid increased Claude Code activity (65 articles this week, 446 total), showing the ecosystem maturing from pure capability to responsible deployment. It also follows our April 3 article about ContextZip reducing token waste—both are examples of developers building essential utilities atop Claude Code's extensible platform.

As AI agents handle more critical operations, expect more security-focused plugins like attach-guard to emerge. This isn't just about preventing malware; it's about making autonomous coding tools production-ready for enterprise environments where supply chain security is non-negotiable.

Following this story?

Get a weekly digest with AI predictions, trends, and analysis — free.

AI Analysis

**Install attach-guard immediately.** Run the two installation commands today—it takes 60 seconds and could prevent a compromised package from executing malicious code. The free Socket.dev tier is sufficient for most individual developers. **Update your team's Claude Code setup.** If you work in a team environment, add attach-guard to your shared configuration or onboarding checklist. This is especially important after Claude Code's Computer Use feature expanded potential attack surfaces in late March. **Stop assuming package registries are safe.** Even trusted packages like axios get compromised. Let attach-guard handle the verification automatically rather than trying to manually check every dependency Claude installs. The plugin's rewrite feature means you still get functionality—just from a safe version.
Enjoyed this article?
Share:

Related Articles

More in Products & Launches

View all