socket-patch CLI

Apply Socket Certified Patches from the command line

socket-patch applies Socket Certified Patches to the dependency versions your project already uses. It is a standalone binary, separate from the Socket CLI. For a step-by-step walkthrough, start with Patch what you can't upgrade.

Install

curl -fsSL https://install.socket.dev/patch | sh       # macOS and Linux
npm install -g @socketsecurity/socket-patch            # any platform, including Windows
cargo install socket-patch-cli                         # from crates.io

The installer verifies the release checksums and puts the binary in /usr/local/bin or ~/.local/bin. Windows archives are also on the GitHub releases page. socket-patch --update updates a standalone install.

Quick start

Run these from the root of a project with a supported lockfile. Dependencies don't need to be installed.

socket-patch scan --dry-run     # preview the patches and the files that would change
socket-patch scan               # apply them; this never prompts
socket-patch list               # show what is patched

Commit the files the scan reports, then install with your normal package manager.

Patch modes

ModeHow to choose itWhat gets committedWhat installs need
HostedThe default for a new projectThe lockfile, and for some package managers one registry settingNetwork access to patch.socket.dev
Vendored--mode vendored, or socket-patch vendor.socket/vendor/ and the lockfileNothing from Socket
Agent--mode agent.socket/manifest.json and .socket/blobs/socket-patch apply after every install

A project keeps the mode it already uses until you pass --mode. Hosted and vendored modes cover every ecosystem except Deno, which supports agent mode only. The support matrix lists each package manager.

Commands

Find and apply patches:

Inspect and prove:

Vendor:

Undo:

Agent mode:

Options every command accepts

OptionEnvironment variableWhat it does
--dry-runSOCKET_DRY_RUNPreview without changing anything
-j, --jsonSOCKET_JSONPrint a machine-readable result
--cwd <DIR>SOCKET_CWDRun in another directory
-e, --ecosystems <LIST>SOCKET_ECOSYSTEMSLimit the run to npm, pypi, cargo, gem, golang, maven, composer, nuget or deno
--api-token <TOKEN>SOCKET_API_TOKENUse this API token. Without one, only free patches are available
-o, --org <SLUG>SOCKET_ORG_SLUGChoose the organization. It is worked out from the token when you leave it off
--offlineSOCKET_OFFLINENever use the network, and fail if something has to be downloaded. scan and get can't run offline
-y, --yesSOCKET_YESSkip confirmation prompts
-v, --verboseShow more detail
-s, --silentPrint errors only
--no-telemetrySOCKET_TELEMETRY_DISABLEDDon't send usage telemetry

Authentication

  • Free patches need no token. The CLI reads them from the public patch service at patches-api.socket.dev.
  • Paid patches need an API token for an organization with Socket Patches. Set SOCKET_API_TOKEN, or run socket login with the Socket CLI, which socket-patch picks up. Any organization-wide token works, and no particular scope is needed. A token limited to certain repositories is refused.

Output and exit status

With --json, every command prints one object with command, status, dryRun, events and summary. Check the exit status before you read it: an argument error exits with status 2 and prints no JSON.

The CLI reports each command's outcome to Socket as usage telemetry: the command, the CLI version, the operating system, counts such as patches applied and, for get, the patch UUID. It sends no package names, file paths or file contents, apart from what an error message quotes. --no-telemetry, SOCKET_TELEMETRY_DISABLED=1 or DO_NOT_TRACK=1 turns it off.

socket patch in the Socket CLI

The socket patch command that ships with the Socket CLI runs an earlier release of this tool. It has no hosted or vendored mode, and its options and JSON output differ. Use the standalone socket-patch binary for the commands in this section.

More


Did this page help you?