Mode and debug flags use
CC_SAFETY_NET_* environment variables. Older SAFETY_NET_* names (without the CC_ prefix) are still accepted for strict, paranoid, and worktree toggles.Default Mode
No environment variables are required to get started. In default mode, CC Safety Net protects against all built-in destructive git and filesystem patterns. If a command cannot be parsed — due to invalid JSON, unterminated quotes, or a malformed shell wrapper — it is allowed through (fail-open). This is the recommended starting point for most users.Strict Mode (CC_SAFETY_NET_STRICT=1)
When strict mode is enabled, CC Safety Net switches to fail-closed behavior on unparseable commands. Any command input that cannot be safely analyzed is blocked rather than allowed.
This covers situations such as:
- Invalid JSON in the hook input
- Unterminated quotes in shell arguments
- Malformed
bash -cwrappers that cannot be recursively unwrapped
Paranoid Mode (CC_SAFETY_NET_PARANOID=1)
Paranoid mode enables additional safety checks that go beyond the defaults. These checks may be disruptive to some normal workflows, so they are opt-in. You can enable all paranoid checks at once, or activate individual checks selectively.
rm check (CC_SAFETY_NET_PARANOID_RM=1)
By default, rm -rf within the current working directory is allowed — the assumption is that deleting files inside your own project root is intentional. With the paranoid rm check enabled, all non-temp rm -rf commands are blocked, including those targeting paths inside the cwd.
Interpreter one-liners (CC_SAFETY_NET_PARANOID_INTERPRETERS=1)
Interpreter one-liners can hide destructive commands inside strings that are hard to inspect statically. With this check enabled, the following forms are blocked entirely:
python -c '...'node -e '...'ruby -e '...'perl -e '...'
CC_SAFETY_NET_PARANOID=1 is equivalent to enabling both CC_SAFETY_NET_PARANOID_RM=1 and CC_SAFETY_NET_PARANOID_INTERPRETERS=1 simultaneously.
Worktree Mode (CC_SAFETY_NET_WORKTREE=1)
Linked git worktrees are designed as disposable, isolated workspaces. Discarding changes inside one does not risk the main working tree, making the usual local-discard restrictions unnecessarily strict in that context. Worktree mode relaxes those rules — but only when CC Safety Net can positively confirm that the current working directory is inside a linked worktree.
How to enable:
What’s allowed inside a linked worktree
When worktree mode is active and the cwd is confirmed to be a linked worktree, the following commands are permitted:git restore <file>andgit restore --worktree <file>git checkout -- <file>,git checkout <ref> -- <file>, and ambiguous multi-positional checkout formsgit reset --hardandgit reset --mergegit clean -f(and combined short flags like-fd)git switch --discard-changesandgit switch -f / --force
What remains blocked even in worktrees
These commands affect shared refs or other worktrees and are never relaxed, regardless of worktree mode:git push --force— affects the remotegit branch -D— force-deletes a branch that is shared across worktreesgit stash drop/git stash clear— the stash is shared across worktreesgit worktree remove --force— could delete another worktree
Detection and fail-closed behavior
Worktree detection is fail-closed: if CC Safety Net cannot positively identify the cwd as a linked worktree, the stricter default rules remain in effect. Specifically:- A linked worktree is identified by a
.gitfile (not a directory) whose resolved git directory contains acommondirfile. Main worktrees and submodules are not relaxed. - The cwd walk uses
realpathso symlinked paths resolve correctly. git -C <path>arguments are honored; unresolved targets keep the command blocked.- Relaxation is disabled if
--git-dir/--work-treeis passed, or ifGIT_DIR/GIT_WORK_TREE/GIT_COMMON_DIRis set in the environment.
Summary
| Variable | Effect |
|---|---|
CC_SAFETY_NET_STRICT=1 | Fail-closed on unparseable commands |
CC_SAFETY_NET_PARANOID=1 | All paranoid checks (rm + interpreters) |
CC_SAFETY_NET_PARANOID_RM=1 | Block rm -rf even within cwd |
CC_SAFETY_NET_PARANOID_INTERPRETERS=1 | Block interpreter one-liners |
CC_SAFETY_NET_WORKTREE=1 | Relax local-discard rules in linked worktrees |
