Skip to main content
A Node.js host that runs commands itself, such as an agent, a task runner, a CI harness, or a plugin host with a shell tool, can call checkCommand instead of installing an agent integration. The function checks one shell command against the current policy and returns allow or deny. It never runs the command.

Library API or installed integration

Both run the same analysis engine. They differ in who owns the call. If your users run one of the supported agents, give them the install command. See Integration models. If your program runs the commands, call the function.

Install and import

It requires Node.js 22 or later and ESM. There is no CommonJS build, so require() cannot load it. Import from cc-safety-net/api, because the package root export is the OpenCode plugin, not checkCommand.

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 every kind of deny, see Blocked commands.

Errors

checkCommand validates its input at runtime and throws TypeError with one of these messages: A known guard failure returns a fail-closed deny instead of throwing. checkCommand throws any other error to the caller.
If checkCommand throws, do not execute the command. A throw is not an allow.

Unusable working directory

cwd must be an existing directory that is readable and searchable. Otherwise the call returns a deny with ruleId cwd.requested-unusable instead of analyzing the wrong project. The reason is:

Which policy a call reads

A call reads the same user and project files as a hook. The project files come from <cwd>/.cc-safety-net/ exactly. The call does not search parent directories, so pass the repository root as cwd, or the committed project policy does not load. Policy covers how the two scopes merge. Because cwd selects the project, a host that manages several checkouts gets the right policy for each one by passing its directory. To see what your host will decide, run status, doctor, or explain in the directory you pass as cwd.

Stability across versions

These hold across minor versions:
  • The input shape { command, cwd }, and the two result kinds, allow, and deny with reason and ruleId.
  • A deny or a throw means do not run the command.
  • Relative command targets and the project configuration resolve against the cwd you pass, never process.cwd().
  • A call writes no audit record and makes no network request. See What one call checks.
The rule catalog can change in any minor version. A new release can deny a command an older one allowed, and reason wording changes. Branch on kind, keep reason for people and logs, and pin the version in your lockfile.

Example: a plugin host

A host with a plugin system usually has a pre-execution hook that can veto a tool call. The plugin maps the host’s event to { command, cwd }, calls checkCommand, and turns a deny into the host’s veto:
  • The plugin sends only shell tool calls to checkCommand. It checks shell command text, not the host’s read, write, or search tools.
  • cwd is the absolute project root. It selects the project policy, and checkCommand resolves relative paths in the command, such as .env, against it.
  • A throw blocks the call. If the handler let an error fall through to execution, a broken check would become an allow.
  • A malformed event blocks, because there is nothing to analyze.
If your host vetoes by throwing, throw the denial message instead of returning it.

What one call checks

The call detects the shell dialect automatically and uses cwd as both the project and the execution directory. It checks the command in full, including any secret-file access the command performs. It does not check the host’s own non-shell file tools, such as read, write, edit, and search. A call never runs the command, changes configuration, or makes a network request. It writes no audit record, so the logs command and the dashboard never show it. If your host does not log a denial, nothing records it.

Environment

Every call reads the CC_SAFETY_NET_* settings from the process environment, so changing them changes later decisions. The call ignores an invalid CC_SAFETY_NET_LEVEL and reports it on stderr:
The message JSON-quotes the value and truncates it to its first 40 characters. See Environment variables for the full list.
Last modified on October 27, 2026