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
cc-safety-net/api subpath alongside its root export:
"type": "module" and there is no CommonJS build, so require() cannot resolve the subpath.
checkCommand
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, and treat ruleId as diagnostic data only. 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.
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 the fail-closed reason instead of analyzing the wrong project:
Example
What one call does
The function builds a command tool invocation namedlibrary-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 theCC_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:
Related pages
- Environment variables documents every setting a call reads.
- Blocked commands lists what a deny can be.
- Integration architecture covers the agent integrations this function replaces when the host runs its own commands.