Skip to main content
A Node.js host that needs an allow or deny decision inside its own process can call checkCommand instead of installing an agent integration. The function checks one shell command against the current policy and returns the decision. It never runs the command. This is one function, not a plugin framework. See Integration architecture for the integrations it can replace.

Install and import

The package exports the cc-safety-net/api subpath alongside its root export:
It requires Node.js 18 or later and ESM. The package is "type": "module" and there is no CommonJS build, so require() cannot resolve the subpath.

checkCommand

The call is synchronous. It reads local policy files, filesystem facts, and CC_SAFETY_NET_* environment settings, then returns an allow or a deny.

Input

cwd is required and has no default. The API never falls back to process.cwd(), so the host decides which project a command belongs to.

Result

Read kind for the decision. A deny means the host must not execute the command. reason is display text. Do not parse or compare it. Every deny carries a ruleId. It is a built-in rule id such as git.reset-hard, a secret rule id, a custom. rule id, or one of the fixed denial ids, such as cwd.requested-unusable. You can branch on it to handle one kind of deny differently, for example to tell the user to fix the working directory. A deny blocks the command whatever its id. A later version can add ids, so treat an id you do not recognize as a plain deny. For what a deny can be, see Blocked commands.

Errors

The function re-validates its input, because an untyped caller can pass anything TypeScript would reject. checkCommand throws TypeError with one of these messages: checkCommand catches a known guard failure and returns its fail-closed deny instead, so that failure does not become a fail-open host mistake. Every other throw reaches the caller.
If checkCommand throws, do not execute the command. A throw is not an allow.

Unusable working directory

cwd is normalized with resolve(), then checked. The path must stat as a directory and be readable and searchable. There is deliberately no realpath step, so the OpenCode plugin and this function decide alike for one directory. When that check fails, the call returns a deny with ruleId cwd.requested-unusable instead of analyzing the wrong project. The reason is:

Example

What one call does

The function builds a command tool invocation named library-api, with the shell set to auto and both the config and execution working directories set to the resolved cwd. It then evaluates the guard directly. Because it calls the guard rather than an agent integration, it never executes the command, writes an audit record, changes configuration, or makes a network request. It checks commands in full, including any secret-file access a command performs. It does not check the host’s own non-shell file tools, such as read, write, edit, and search.

Environment

Every call reads the CC_SAFETY_NET_* settings from the process environment, so changing them changes later decisions. An invalid CC_SAFETY_NET_LEVEL is ignored and reported on stderr:
The reported value is JSON-quoted and truncated to its first 40 characters. See Environment variables for the full list.
Last modified on October 3, 2026