Socket Patch CLI
Apply security patches to npm and Python dependencies without waiting for upstream fixes.
Installation
One-line install (recommended)
|
Detects your platform (macOS/Linux, x64/ARM64), downloads the latest binary, and installs to /usr/local/bin or ~/.local/bin. Use sudo sh instead of sh if /usr/local/bin requires root.
Download a prebuilt binary from the latest release:
# macOS (Apple Silicon)
|
# macOS (Intel)
|
# Linux (x86_64)
|
# Linux (ARM64)
|
Then move the binary onto your PATH:
npm
Or install globally:
pip
Cargo
By default this builds with npm and PyPI support. For additional ecosystems:
Quick Start
You can pass a patch UUID directly to socket-patch as a shortcut:
# equivalent to: socket-patch get 550e8400-e29b-41d4-a716-446655440000
Commands
All commands support --json for structured JSON output and --cwd <dir> to set the working directory (default: .). Every JSON response includes a "status" field ("success", "error", "no_manifest", etc.) for reliable programmatic consumption.
get
Get security patches from Socket API and apply them. Accepts a UUID, CVE ID, GHSA ID, PURL, or package name. The identifier type is auto-detected but can be forced with a flag.
Alias: download
Usage:
Options:
| Flag | Description |
|---|---|
--org <slug> |
Organization slug (required when using SOCKET_API_TOKEN) |
--id |
Force identifier to be treated as a UUID |
--cve |
Force identifier to be treated as a CVE ID |
--ghsa |
Force identifier to be treated as a GHSA ID |
-p, --package |
Force identifier to be treated as a package name |
-y, --yes |
Skip confirmation prompt for multiple patches |
--save-only |
Download patch without applying it (alias: --no-apply) |
--one-off |
Apply patch immediately without saving to .socket folder |
-g, --global |
Apply to globally installed packages |
--global-prefix <path> |
Custom path to global node_modules |
--json |
Output results as JSON |
--api-token <token> |
Socket API token (overrides SOCKET_API_TOKEN) |
--api-url <url> |
Socket API URL (overrides SOCKET_API_URL) |
--cwd <dir> |
Working directory (default: .) |
Examples:
# Get patch by UUID
# Get patch by CVE
# Get patch by GHSA
# Get patch by package name (fuzzy matches installed packages)
# Download only, don't apply
# Apply to global packages
# JSON output for scripting
scan
Scan installed packages for available security patches. Since v3.0 scan --sync is the single command bots need for full auto-update: it discovers patches, applies them, and garbage-collects orphan blob files plus manifest entries for uninstalled packages — all in one invocation.
Usage:
Options:
| Flag | Description |
|---|---|
--apply |
Download and apply selected patches in JSON mode (non-interactive). Without it, scan --json is read-only. |
--prune |
Garbage-collect after the scan: remove manifest entries for uninstalled packages and orphan blob/diff/package-archive files. Off by default. |
--sync |
Sugar for --apply --prune. The canonical bot-mode flag. |
-d, --dry-run |
Preview what --apply/--prune/--sync would do without mutating disk. |
--org <slug> |
Organization slug |
--json |
Output results as JSON |
-y, --yes |
Skip confirmation prompts |
--ecosystems <list> |
Restrict to specific ecosystems (comma-separated, e.g. npm,pypi) |
-g, --global |
Scan globally installed packages |
--global-prefix <path> |
Custom path to global node_modules |
--batch-size <n> |
Packages per API request (default: 100) |
--download-mode <mode> |
diff (default), package, or file |
--api-token <token> |
Socket API token (overrides SOCKET_API_TOKEN) |
--api-url <url> |
Socket API URL (overrides SOCKET_API_URL) |
--cwd <dir> |
Working directory (default: .) |
Examples:
# Scan local project (interactive prompt to apply)
# Scan with JSON output (discover + updates, no mutation)
# Bot mode: discover, apply, prune, sweep — all in one
# Apply without pruning manifest entries (default)
# Apply + prune explicitly (equivalent to --sync)
# Preview a full sync without mutating disk
# Scan only npm packages
# Scan global packages
apply
Apply security patches from the local manifest.
Usage:
Options:
| Flag | Description |
|---|---|
-d, --dry-run |
Verify patches without modifying files |
-s, --silent |
Only output errors |
-f, --force |
Skip pre-application hash verification (apply even if package version differs) |
-m, --manifest-path <path> |
Path to manifest (default: .socket/manifest.json) |
--offline |
Do not download missing blobs; fail if any are missing |
-g, --global |
Apply to globally installed packages |
--global-prefix <path> |
Custom path to global node_modules |
--ecosystems <list> |
Restrict to specific ecosystems (comma-separated, e.g. npm,pypi) |
--json |
Output results as JSON |
-v, --verbose |
Show detailed per-file verification information |
--cwd <dir> |
Working directory (default: .) |
Examples:
# Apply patches
# Dry run
# Apply only npm patches
# Apply in offline mode
# JSON output for CI/CD
rollback
Rollback patches to restore original files. If no identifier is given, all patches are rolled back.
Usage:
Options:
| Flag | Description |
|---|---|
-d, --dry-run |
Verify rollback without modifying files |
-s, --silent |
Only output errors |
-m, --manifest-path <path> |
Path to manifest (default: .socket/manifest.json) |
--offline |
Do not download missing blobs; fail if any are missing |
-g, --global |
Rollback globally installed packages |
--global-prefix <path> |
Custom path to global node_modules |
--one-off |
Rollback by fetching original files from API (no manifest required) |
--ecosystems <list> |
Restrict to specific ecosystems (comma-separated) |
--json |
Output results as JSON |
-v, --verbose |
Show detailed per-file verification information |
--org <slug> |
Organization slug |
--api-token <token> |
Socket API token (overrides SOCKET_API_TOKEN) |
--api-url <url> |
Socket API URL (overrides SOCKET_API_URL) |
--cwd <dir> |
Working directory (default: .) |
Examples:
# Rollback all patches
# Rollback a specific package
# Rollback by UUID
# Dry run
# JSON output
list
List all patches in the local manifest.
Usage:
Options:
| Flag | Description |
|---|---|
--json |
Output as JSON |
-m, --manifest-path <path> |
Path to manifest (default: .socket/manifest.json) |
--cwd <dir> |
Working directory (default: .) |
Examples:
# List patches
# JSON output
Sample Output:
Found 2 patch(es):
Package: pkg:npm/lodash@4.17.20
UUID: 550e8400-e29b-41d4-a716-446655440000
Tier: free
License: MIT
Vulnerabilities (1):
- GHSA-xxxx-yyyy-zzzz (CVE-2024-12345)
Severity: high
Summary: Prototype pollution in lodash
Files patched (1):
- lodash.js
remove
Remove a patch from the manifest (rolls back files first by default).
Usage:
Arguments:
identifier- Package PURL (e.g.,pkg:npm/package@version) or patch UUID
Options:
| Flag | Description |
|---|---|
--skip-rollback |
Only update manifest, do not restore original files |
-g, --global |
Remove from globally installed packages |
--global-prefix <path> |
Custom path to global node_modules |
--json |
Output results as JSON |
-m, --manifest-path <path> |
Path to manifest (default: .socket/manifest.json) |
--cwd <dir> |
Working directory (default: .) |
Examples:
# Remove by PURL
# Remove by UUID
# Remove without rolling back files
# JSON output
repair
Download missing blobs and clean up unused blobs.
Alias: gc
repair cleans up the .socket/ directory without running a scan — useful when you've manually adjusted the manifest, recovered from a partial-failure state, or just want to free space. For the combined workflow (discover + apply + GC in one pass), use scan --sync --json --yes instead.
Usage:
Options:
| Flag | Description |
|---|---|
-d, --dry-run |
Show what would be done without doing it |
--offline |
Skip network operations (cleanup only) |
--download-only |
Only download missing blobs, do not clean up |
--json |
Output results as JSON |
-m, --manifest-path <path> |
Path to manifest (default: .socket/manifest.json) |
--cwd <dir> |
Working directory (default: .) |
--download-mode <mode> |
file (default), diff, or package |
Examples:
# Full repair (download missing + clean up unused)
# Cleanup only, no downloads
# Download missing blobs only
# JSON output for scripting
setup
Configure package.json postinstall scripts to automatically apply patches after npm install.
Usage:
Options:
| Flag | Description |
|---|---|
-d, --dry-run |
Preview changes without modifying files |
-y, --yes |
Skip confirmation prompt |
--json |
Output results as JSON |
--cwd <dir> |
Working directory (default: .) |
Examples:
# Interactive setup
# Non-interactive
# Preview changes
# JSON output for scripting
Scripting & CI/CD
All commands support --json for machine-readable output. JSON responses always include a "status" field for easy error detection:
# Check for available patches in CI (read-only)
result=
patches=
# Auto-update bot mode: discover, apply, prune, sweep in one pass
|
# Pipe this into peter-evans/create-pull-request to open a PR with the changes.
# Apply patches and check result
|
# "success", "partial_failure", "no_manifest", or "error"
When stdin is not a TTY (e.g., in CI pipelines), interactive prompts auto-proceed instead of blocking. Progress indicators and ANSI colors are automatically suppressed when output is piped.
Environment Variables
| Variable | Description |
|---|---|
SOCKET_API_TOKEN |
API authentication token. Use the raw token (sktsec_<...>_api) shown when it was generated, not the SHA-512 hash (sha512-...) that the dashboard may also display for identification. |
SOCKET_ORG_SLUG |
Default organization slug |
SOCKET_API_URL |
API base URL (default: https://api.socket.dev) |
Manifest Format
Downloaded patches are stored in .socket/manifest.json:
Patched file contents are in .socket/blob/ (named by git SHA256 hash).
Supported Platforms
| Platform | Architecture |
|---|---|
| macOS | ARM64 (Apple Silicon), x86_64 (Intel) |
| Linux | x86_64, ARM64, ARMv7, i686 |
| Windows | x86_64, ARM64, i686 |
| Android | ARM64 |