Introducing a new way to review your PRs.

Read the announcement

kenryu42 / cc-safety-net

A pre-execution guard for AI coding agents. It blocks destructive Git and file system commands, plus common attempts to access sensitive files, before a tool call runs. Supports Amp Code, Antigravity CLI, Claude Code, Codex, Cursor, DeepSeek Harness, Devin CLI, GitHub Copilot CLI, Grok Build, Hermes Agent, Kimi Code, OpenClaw, OpenCode, and Pi.

View on GitHub

20 documents · Updated Nov 23, 2026

docs / diagnostics-and-audit-interfaces

Diagnostics and audit interfaces

CC Safety Net gives operators four command-line views of protection: status shows what is active now, doctor checks the health of the setup, explain shows why a command would be allowed or blocked, and logs shows recorded decisions. Together they connect integration health, policy state, safety decisions, and past activity without running the command under review. See Operator interfaces for the parent view, CLI command workflows for command use, and Browser GUI for the related browser interface.

Operator views

The interfaces answer different questions, so an operator can move from a quick check to a full diagnosis and then to a past event. The usual path is:

flowchart LR
    A[Need a quick answer] --> B[status]
    B -->|Something is not active| C[doctor]
    A -->|Question about one command| D[explain]
    A -->|Question about past activity| E[logs]
    C --> F[Integration and policy repair]
    D --> G[Safety decision trace]
    E --> H[Recorded decision history]

status is the smallest view and reports the current policy snapshot. doctor adds checks of integrations, configuration, the guard engine, protected storage, recent activity, and system information. explain evaluates one command without executing it. logs reads the local audit trail and helps find the event that caused a block.

Decision visibility

The interfaces expose three related but distinct states. Runtime state says whether the loaded policy is ready or degraded. Predicted decision says what the guard would do for a supplied command. Recorded activity says what an integration actually reported during prior hook calls. A degraded runtime may still enforce a fallback policy, while a log entry preserves the context of the decision made at that time.

References: src/…/status.ts• L12-20 src/…/explain.ts• L42-127 src/…/audit-log.ts• L138-198 src/…/audit.ts• L22-44

Status capability

The status command is a fast, informational view of the policy that the runtime currently enforces. It reads one policy snapshot and presents a ready or degraded verdict with the main protection facts beside it.

The facts show whether destructive-command protection and secret protection are active, the effective safety level, the active custom-rule count, and the policy path. Worktree relaxations appear only when they are active. When something is not active, the output lists each reason and points the operator to doctor for the full report.

The Claude Code plugin check is shown as an integration-specific warning. It does not replace the overall snapshot verdict because the other integrations can remain active. The command is informational and returns exit code 0 for both ready and degraded states.

Status output

The terminal view uses short fact rows and bounded issue bullets so an operator can scan it in a narrow terminal. It uses plain ASCII when output is not a color terminal or NO_COLOR is set. status does not provide a JSON mode; use doctor --json for a structured health report.

References: src/…/status.ts• L3-14 src/…/status.ts• L21-91 src/…/cc-safety-net.ts• L68-73

Doctor capability

The doctor command is the full health check for the local installation and its coding-agent integrations. It collects one report so an operator can tell the difference between an integration that is missing, one that is not configured, a policy that is invalid, and a runtime that is enforcing a fallback. When an operator supplies a working directory, the integration checks and system probes use that same directory, so project-local integration state is diagnosed in the intended project.

The report covers these areas:

AreaOperator question
Hook integrationsWhich supported integrations are detected, configured, and verified?
Guard engineDoes the shared safety engine pass its synthetic self-check?
ConfigurationWhich user and project rule sources exist, are valid, and contribute effective rules?
EnvironmentWhich safety-related environment settings are set, including legacy settings and the user-scope home override?
Effective safetyWhich preset, capabilities, and rule customizations are in force?
Storage postureAre policy, configuration, and audit directories safe to use?
FindingsWhat needs attention, at what severity, and with which repair hint?
Recent activityHow many commands were blocked in the last seven days, what are the newest examples, and were any log sources unreadable?
System and updatesWhich tool versions are visible and is a newer CC Safety Net version available?

The configuration view checks user and project sources separately, then shows the rules that the loaded policy makes effective. It preserves the source of each effective rule so an operator can relate the active policy to its scope. Findings turn the collected facts into operator actions. They can identify missing or failed integrations, invalid rule files, fallback enforcement, old rulebook leftovers, legacy inline rule configs that are no longer loaded, invalid audit-scope settings, unsafe protected directories, and rule overrides that weaken a selected preset. Findings are ordered by severity, with errors before warnings and informational findings.

The rule-management surface provides the main repair paths named by these findings: rule verify checks rule configuration, rule sync handles deprecated lock and cache migration, and rule migrate handles legacy inline rules. Cleanup remains an explicit operator choice through rule migrate --cleanup.

An error exit code means the setup has a concrete health failure such as no configured integration, a failed hook inspection, a failed engine self-test, an invalid existing configuration, or an unsafe protected directory. Warnings and informational findings can still leave the command successful.

Doctor formats

The default report is designed for a human operator. It presents integration, engine, configuration, environment, safety, findings, activity, system, and update sections with terminal-safe tables and repair text. The integration table separates discovery, configuration, and inspection, so a detected host that has no active setup is distinct from a host whose inspection failed.

The environment section shows whether each supported safety setting is set, identifies set legacy names, and includes the CC_SAFETY_NET_HOME user-scope directory override. The safety section shows the selected preset, effective level, capability sources, project policy weakenings, and rule customization counts. Findings and recent command text are rendered for safe terminal display, and long activity commands are shortened for scanning.

doctor --json returns the complete report as machine-readable JSON for support tools or scripts. The update check can be skipped with --skip-update-check, which keeps the report focused on local state.

References: src/…/config.ts• L19-23 src/…/config.ts• L62-90 src/…/environment.ts• L5-79 src/…/findings.ts• L36-207 src/…/index.ts• L68-142 src/…/index.ts• L144-173 src/…/format.ts• L50-114 src/…/format.ts• L153-186 src/…/format.ts• L188-264 src/…/format.ts• L266-299 src/…/format.ts• L301-384 src/…/doctor-types.ts• L158-181

Explain capability

The explain command answers why one command would be allowed or blocked under the policy for a chosen working directory. It performs analysis only; it does not execute the command or create a new safety decision in the integration path.

The result includes the command input, shell segments, ordered analysis steps, the final result, and the reason and rule when the result is blocked. It also shows the policy source, configuration validity, selected safety preset, effective capabilities, customizations, and any rule activation state that matters to the command. A multi-command input keeps separate segment traces, including segments skipped after an earlier block. Diagnostic text is sanitized before it reaches the operator so decision details stay safe to display.

The human trace makes global errors explicit, separates each shell segment, marks recursive analysis, and shows the final result with its policy context. It can also show command normalization and safety checks such as environment stripping, wrapper detection, rule matching, worktree relaxation, and strict-mode rejection. An empty or otherwise invalid analysis can therefore be seen as a diagnostic result rather than mistaken for a command run. The JSON view preserves the same result data without the terminal layout.

Explain inputs

The command accepts a command string and optional --cwd and --shell values. --cwd selects an existing working-directory path. --shell selects auto, posix, or powershell, with auto as the default, so the analysis can use the intended command dialect. Multiple trailing arguments are joined into one shell-safe command; use -- when the command itself starts with a dash. --json returns the same trace and result as structured data.

The trace can show parsing, global checks, per-segment checks, recursion, and the final result. A blocked result identifies the matched rule or protection reason. An allowed result means that the analyzed input produced no matching block under the selected context; it is not a request to run the command.

The human formatter gives an analysis error its own ERROR section and still reports the resulting status and configuration path. For a normal trace, it shows the input before the segment steps, marks a segment skipped after an earlier block, and ends with the result and policy context. This keeps an invalid analysis distinct from an allowed command with no matching rules.

References: src/…/explain.ts• L3-33 src/…/flags.ts• L5-59 src/…/run.ts• L22-63 src/…/explain.ts• L72-203 src/…/format-helpers.ts• L23-93 src/…/format-helpers.ts• L100-255 src/…/format.ts• L12-35 src/…/format.ts• L37-147 src/…/format.ts• L149-196 src/…/format.ts• L199-201

Audit-log capability

The logs command is the operator interface to the local audit trail. Integrations record command decisions with time, integration identity, session and project context, the command segment, the reason, and the policy information needed to interpret the decision later.

Audit records describe decisions rather than command results. They do not contain command output or prompts. The trail can include allowed command decisions when the audit scope permits them, while the normal log view shows denials unless --all is used.

Audit history

The default query shows recent retained denials, up to 20 entries from the last 30 days or the shorter configured retention period. Operators can narrow the view by agent, rule, session, project, or time window. A 16-character entry id provides a direct lookup of one retained record. --suspect narrows the view to denials that may need review because analysis failed or the same command signature was denied more than once in one session.

The command can return human-readable rows or JSON entries. If a directory, file, or record cannot be read or validated, it warns that the result is incomplete instead of treating the readable remainder as the full history. This distinction matters when an operator is checking whether an event occurred.

References: src/…/logs.ts• L3-80 src/…/audit-log.ts• L35-198 src/…/audit-log.ts• L281-323 src/…/audit-scan.ts• L8-95 src/…/audit.ts• L22-44

Audit retention

Audit history is local and time-limited. The configured retention window controls which records remain available, and cleanup runs during normal audit writes and reads. A record older than that window may no longer be available for id lookup.

Legacy root-level log files have a separate explicit cleanup path. --prune-legacy --dry-run previews the files and bytes that would be removed. Running the same command without --dry-run permanently deletes those legacy files and leaves nested current-format logs unchanged. This cleanup is separate from normal retention and should be treated as destructive operator action.

References: src/…/audit.ts• L55-149 src/…/audit-retention.ts• L31-95 src/…/audit-log.ts• L201-269

Diagnostic relationships

These views share the same policy and audit concepts but serve different points in an investigation. Start with status when the question is whether protection is active. Use doctor when the answer includes installation, integration, configuration, or storage health. Use explain for a command that has not run yet. Use logs when the command already ran through an integration and its decision needs review.

Operator questionPrimary interfaceResult
Is protection active now?statusCurrent verdict and inactive items
Why is an integration or setup not healthy?doctorChecks, findings, and repair hints
What would happen to this command?explainNon-executing analysis trace
What happened in a prior hook call?logsRetained decision records

The interfaces also expose degraded states consistently. status names snapshot diagnostics, doctor reports the fallback and its cause, explain shows whether its analysis used valid configuration, and audit records can mark that a fallback policy was in force when the decision was made.

Investigation flow

When an operator sees a block or a missing protection signal, the investigation moves from present state to cause and then to history:

  1. Run cc-safety-net status to confirm the current runtime verdict and see immediate inactive items.
  2. Run cc-safety-net doctor to inspect integration links, policy sources, safety settings, and findings.
  3. Run cc-safety-net explain "<command>" with the relevant working directory and shell mode when needed to inspect a predicted decision.
  4. Run cc-safety-net logs with filters or an entry id to review the recorded event.

References: src/…/status.ts• L21-91 src/…/index.ts• L39-65 src/…/run.ts• L22-51 src/…/audit-log.ts• L138-204

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the command registry, command help text, top-level dispatch, and each command's parser aligned. A command can appear in help but fail at dispatch if one surface changes alone.
  • Keep doctor source checks, environment facts, effective-rule provenance, report fields, finding rules, terminal sections, and JSON output aligned. A new health fact needs a clear severity and operator action when it can affect the exit code.
  • Keep the doctor finding order and exit contract aligned. An error finding must not render as a warning or allow the command to exit successfully.
  • Keep doctor repair hints aligned with the available rule subcommands. A hint for a removed, renamed, or deprecated repair path can leave an operator unable to resolve a finding.
  • Keep the doctor working directory consistent across system information, host detection, and project configuration checks. A probe that uses the process directory can report the wrong project state.
  • Keep audit entry fields consistent between integration projection, on-disk records, log filters, doctor activity summaries, and JSON output.
  • Preserve the distinction between the whole policy snapshot verdict and an integration-specific status item. A single plugin state must not change the verdict for unrelated integrations.
  • Preserve retention limits when changing log query defaults. Direct id lookup and filtered history must use the same retained set.
  • Keep audit scan validation and skip counts aligned with every reader. A newly required field or a newly unreadable source must still produce an incomplete-history warning.
  • Keep audit failure stages and error codes bounded and safe for operator output. They are the link between fail-closed events and later diagnosis.
  • Keep the explain flag parser, command help, examples, and analysis input contract aligned when changing shell modes, working-directory handling, or multi-argument command assembly.
  • Keep the explain trace projection and terminal formatter aligned. New global or segment steps must remain visible in the correct part of both human and JSON output.
  • Keep explain error handling aligned with the normal trace layout. An analysis error must retain its status and configuration context without being presented as a command execution.
  • Keep bounded analysis failures consistent across human and JSON output. A recognized parser, input, or work-limit failure must return a clear message and a non-zero status without being mistaken for a safety decision.
  • Keep doctor terminal escaping and truncation rules aligned with every new user-controlled finding or activity field. Unsafe text must not become terminal control input or make the report hard to scan.

Important failure modes

TriggerConsequenceGuard
No supported integration is configuredHooks do not connect CC Safety Net to an agentdoctor reports an error and directs the operator to install and configure an integration
An integration inspection failsDoctor cannot verify that integration's configurationThe finding names the integration and directs the operator to correct its reported configuration error
A project-local integration is checked from the wrong working directoryDoctor can report the state of another projectDoctor passes its resolved working directory to host detection and system probes
An existing user or project configuration is invalidThe configured rules cannot be trusted as the active sourcedoctor reports the source as invalid and returns a failure exit code
The runtime rejects a policy candidateA fallback policy is enforced instead of the rejected candidatestatus and doctor show degraded diagnostics; audit entries can mark the fallback state
A legacy rulebook lock or cache remains after migrationEarlier-version files remain present but are no longer readdoctor reports an informational finding and directs the operator to run rule sync
A legacy inline rule config remainsIts rules enforce nothing because CC Safety Net no longer loads the filedoctor reports a warning and directs the operator to run rule migration
The audit-scope setting is invalidAllowed command decisions are not recordeddoctor reports a warning; set the scope to all or blocked and restart the integration
A policy, configuration, or audit directory is unsafeProtected state may be exposed to the wrong owner or write accessdoctor reports an error; use a real directory owned by the current user with no group or other write access
A rule override weakens the selected presetThe effective protection is weaker than the selected preset suggestsdoctor reports the affected override and directs the operator to remove it or turn it on
An audit directory, file, or record cannot be read or validatedLog queries and doctor activity summaries may be incompleteBoth interfaces count skipped sources and warn that the result is partial
An audit entry is older than retentionId lookup cannot find the recordThe query is limited to the configured retained history
--prune-legacy is run without --dry-runLegacy root-level audit files are permanently deletedPreview with --dry-run; current nested logs are not included
Claude Code's plugin is disabledClaude Code is not protected through that plugin while other integrations may remain activestatus adds a scoped inactive bullet without changing the global snapshot verdict
A command is empty or contains an analysis errorexplain cannot provide a normal decision traceThe result carries an explicit diagnostic step and does not execute the command
--cwd names a missing path or --shell names an unsupported dialectexplain stops before command analysisThe flag parser rejects the input, prints the usage, and returns a non-zero status
Command input exceeds a supported parse or analysis limitexplain cannot produce a complete traceThe runner returns a bounded error in human or JSON form and exits non-zero

Key files

FileWhy to read it
src/…/cc-safety-net.tsShows how the four operator commands are dispatched and how their exit codes reach the process.
src/…/rule.tsDefines the rule-management commands that provide repair paths for configuration and legacy-rule findings.
src/…/status.tsDefines the current-enforcement view and its distinction between snapshot state and integration diagnostics.
src/…/index.tsShows the health-report lifecycle from checks to findings, formatting, exit status, and working-directory selection.
src/…/config.tsShows how doctor compares user and project rule sources and identifies effective rules.
src/…/environment.tsDefines the safety environment settings and the user-scope home override that doctor reports.
src/…/findings.tsDefines the health conditions that become severity-ranked operator findings.
src/…/format.tsDefines the human-readable doctor sections, tables, findings, safe terminal rendering, and repair text.
src/…/activity.tsShows how recent blocked activity and unreadable audit sources become part of the health report.
src/…/doctor-types.tsDefines the high-level shape of the doctor report and its operator-facing concepts.
src/…/flags.tsDefines the explain command's accepted shell modes, working-directory validation, and command argument handling.
src/…/run.tsConnects explain parsing, non-executing analysis, output formats, bounded analysis errors, and exit status.
src/…/explain.tsDefines the analysis result that links a command trace to policy state, protection matches, and a final decision.
src/…/format.tsDefines the human trace layout and the JSON projection of an explain result.
src/…/format-helpers.tsDefines the human-readable trace view and its terminal-safe formatting choices.
src/…/audit-log.tsDefines audit history queries, filters, incomplete-read warnings, and legacy cleanup controls.
src/…/audit.tsShows how integration decisions become audit records.
src/…/audit-scan.tsDefines audit source discovery, record validation, and suspect-entry selection for diagnostic views.
src/…/audit.tsDefines the shared audit record fields used by writers and readers.
src/…/audit-retention.tsDefines the boundary between retained history and expired records.