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 / semantic-command-analysis-and-guards

Semantic command analysis and guards

The semantic analysis layer turns a tool call into facts about what it may run, which paths it may reach, and which execution context gives those paths meaning. Command analysis uses these facts to detect dangerous behavior. Path guards use the same facts to protect secrets, policy files, Git metadata, and other protected paths. See Command safety evaluation, Command and tool-input parsing, Safety decisions, explanations, and audit trail, and Programmatic safety API.

Analysis model

The analyzer views a command as a structured program rather than as plain text. It combines shell structure, word source, process state, and policy rules to decide what the invocation can do.

Analysis inputs

Analysis starts with a tool invocation and a fixed safety policy. The invocation supplies the route, shell type, command text when present, configuration directory, and execution directory. A command route uses its declared shell. An unknown route uses PowerShell on Windows and POSIX elsewhere so fallback checks keep the host path syntax.

The semantic fact store keeps one shared interpretation for later guards and analysis:

  • A command route can expose both an input command and a declared command. One parsed fact records both uses when they share a source.
  • A non-command route provides direct path facts from tool fields. Patch input also provides file targets found in patch text.
  • Each command fact contains a parsed program and a shell-syntax view. The store reuses these facts for the same source and shell dialect.

These facts let every guard inspect command routes, direct path tools, and unknown routes without creating a second interpretation.

References: src/…/semantic-facts.ts• L63-114 src/…/semantic-facts.ts• L129-173 src/…/facts.ts• L5-28 src/…/invocation.ts• L1-40 src/…/analysis.ts• L13-63

Behavior facts

The analyzer finds the command that can run after it removes leading assignments and supported wrappers. It then checks focused rules for destructive Git actions, recursive removal, synchronization deletes, command interpreters, device changes, network exposure, namespace creation, and other dangerous forms. The rule set passes the effective directory, environment values, temporary-directory trust, Git context, and nested-command handlers to each focused check.

The analyzer keeps word provenance. Provenance records whether text came from a literal, variable, command substitution, arithmetic expansion, glob, or unknown source. This distinction shows when an option or target is known and when expansion can change the result. A dynamic executable or guarded option can therefore produce a stop result instead of a fixed-command result.

Interpreter code is checked both as a nested command and as a safety backstop for dangerous text. Native recursive deletion of a root or home location remains dangerous at every code-text level, including when the matching call appears inside a string or executed code. Standard mode does not relax this root-or-home protection.

The analyzer also records paths that the command writes or downloads. If a later interpreter runs one of those paths, the analyzer does not treat the file as trusted local content. A command that creates a directory can also affect later path resolution when the directory is proven to exist.

Each rule match carries a stable rule ID, a user-facing reason, and an intent. The intent tells the caller whether to stop, ask for manual action, or use an alternative. Parsing and bounded-analysis failures use stable analysis rule IDs as well, so dangerous matches and fail-closed outcomes have one diagnostic identity. Selected analysis-cap breaches are converted at the analyzer boundary into a stop-and-explain denial with trace evidence rather than allowing partial derived work to pass.

When structure cannot be followed, a raw-text backstop checks known destructive patterns and downloads piped to a shell. This backstop protects opaque text. It does not replace structured shell analysis.

References: src/…/analyze-command.ts• L122-213 src/…/analyze-command.ts• L770-961 src/…/analyze-command.ts• L1056-1135 src/…/index.ts• L16-21 src/…/index.ts• L58-96 src/…/segment.ts• L210-249 src/…/segment.ts• L630-783 src/…/rule.ts• L47-75

Container execution

The analyzer treats a standard-mode container run as isolated only when it can prove that the payload cannot reach host state. It recognizes Docker, Podman, and nerdctl run forms and checks mounts, host-control options, and expansion uncertainty before it skips host-path fallback matches.

Isolation is narrow. Writable or ambiguous mounts, host access options, and uncertain options keep full scanning. A proven isolated payload still remains subject to rules for effects outside the container, such as network access, Git pushes, interpreter execution, and matching custom policy rules. Strict mode and paranoid rules also keep full scanning. An unrelated custom rule does not remove this narrow isolation treatment.

References: src/…/container-run.ts• L23-68 src/…/segment.ts• L777-829

Nested execution

Nested execution stays inside the parent analysis so a dangerous action cannot hide in a wrapper or a command-producing tool. Literal shell -c and eval sources, interpreter code, awk system calls, shell input, heredocs, find -exec, xargs, and parallel can return child commands to analysis.

Shell wrapper scripts are also checked for remote fetches in outer substitutions. If a command such as bash -c "$(curl ...)" obtains the whole -c script from a remote fetch, the source is dynamic and the analyzer stops rather than treating it as a local generator. The check follows nested command spans inside the script word and transparent wrappers such as sudo, env, command, and builtin; a substitution in another argument or inside a literal single-quoted script does not match this specific condition.

PowerShell -Command and literal evaluation sources are analyzed as child programs when their source is readable. Encoded commands and sources with unknown expansion are dynamic. Recursive deletion inside such a source is blocked because the analyzer cannot verify its target. The same fail-closed approach applies when command quoting, connectors, variables, or wildcard expansion prevent a cmd delete target from being verified. For cmd /c and /k, the analyzer separates connector-delimited command pieces, inspects recursive rmdir, rd, del, and erase actions, and treats escaped quotes or Windows namespace paths as unsafe forms.

The analyzer treats heredoc input by role. Supported literal data can be modeled as file output or message input. Literal code sent to an interpreter is analyzed as code. Unsupported or unquoted forms are uncertain and can stop the command in strict mode. Supported persistent heredoc output can also become a tracked script file for later shell execution. A tracked path is resolved against the effective directory and existing path components when possible. Pseudo-filesystem paths under /dev, /proc, and /sys are not treated as persistent script files. A later write invalidates that tracked file, so stale script content cannot affect a new decision.

The analyzer also tracks files written or downloaded during the command. A later interpreter cannot treat a file downloaded earlier in the same command as a known safe local program. A script that the command may overwrite is not read as trusted disk content. This keeps later execution tied to the command's full data flow rather than to an outdated file view.

Shell state also affects nested behavior. Functions become active only after a same-shell call. Child shells do not inherit parent functions. Pipelines, subshells, and background commands keep separate file-system outcomes. Conditional branches retain each possible state when later commands depend on success or failure. Small, bounded literal loops can also produce separate states so later commands are checked for each known value.

Recursion, derived-command, control-flow, wrapper, script-read, and parallel work have limits. An unresolved command source or a limit crossing produces a dynamic or stop-and-explain result instead of an unverified allow.

References: src/…/analyze-command.ts• L247-470 src/…/analyze-command.ts• L620-677 src/…/analyze-command.ts• L990-1081 src/…/analyze-command.ts• L1612-1762 src/…/heredoc-files.ts• L6-27 src/…/segment.ts• L251-429 src/…/segment.ts• L482-612 src/…/segment.ts• L1053-1157

Execution context

The effective execution context follows a command through wrappers and segments. It includes the current directory, environment assignments, temporary-directory trust, Git context, function definitions, literal files created by supported heredocs, and directories created by supported mkdir forms. Guards use this state when a relative path or command changes meaning after cd, env, or a Git context option.

The current directory becomes unknown after an unresolved directory change or wrapper option. The analyzer then removes context-based relaxations instead of guessing. Shell assignments persist only where shell rules allow them. The state tracks temporary-directory, word-splitting, Git, and SSH variables because later segments can change path trust or Git behavior. Isolated branches copy state. Control flow merges possible outcomes.

Derived commands inherit the parent directory, environment assignments, policy, worktree mode, and remaining work budget. Literal heredoc outputs and known new directories can also affect later path checks when the analyzer can prove them. Files written or fetched earlier in the command affect later script decisions as well. This prevents a child command from gaining a relaxation that its parent could not prove.

When a wrapper changes directory, the analyzer does not bind a script operand's $PWD to that wrapper target unless the path is otherwise proven. The unresolved operand remains dynamic, so a wrapper cannot turn an unknown script location into a trusted local source.

References: src/…/analyze-command.ts• L190-213 src/…/analyze-command.ts• L780-820 src/…/analyze-command.ts• L963-1010 src/…/analyze-command.ts• L1249-1305 src/…/heredoc-files.ts• L6-23 src/…/segment.ts• L116-208 src/…/segment.ts• L1201-1263

Wrapper context

Wrappers are removed before command-specific checks, but their effects remain in the execution context. Leading assignments become known environment values. env can change variables or the directory. sudo can change the directory or make it unknown. command and builtin expose the command that will run.

The prelude scan also handles TMPDIR+= and Git context assignments. env -S can split a safe, inert option string into command words for a later pass. If that string contains shell syntax or cannot be bounded, the command stays uncertain. Wrapper peeling is policy-controlled and bounded. Repeated or circular wrapping becomes an analysis-limit result.

The wrapper scan only unwraps commands that can carry a protected or analyzed child. It stops at display-only commands and preserves alternative child positions when wrapper syntax leaves more than one valid interpretation. This avoids both hiding a dangerous child and treating ordinary wrapper arguments as commands.

References: src/…/segment.ts• L123-249 src/…/segment.ts• L663-696 src/…/wrapper-prelude.ts• L32-152 src/…/wrapper-prelude.ts• L177-244 src/…/wrapper-prelude.ts• L249-369 src/…/transparent-wrappers.ts• L15-109

Device behavior

Device analysis blocks commands that can erase or overwrite raw devices. It covers dd writes to device paths, file-system formatting, disk table or erase actions, output redirection to block devices, and any shred target. These actions require manual confirmation because an ordinary path check cannot make them safe.

Read-only forms of disk tools remain outside the device-erase match when their options prove that they only inspect state. A write or erase form receives a stable device rule and a manual-execution reason.

References: src/…/device.ts• L5-63 src/…/device.ts• L65-140 src/…/segment.ts• L630-661 src/…/analyze-command.ts• L846-858

Network and namespace behavior

Network and namespace rules cover high-impact actions that do not fit normal file or delete checks. They block requests to cloud metadata endpoints because those endpoints can return instance credentials. They also block remote uploads that can send local data off the host, except when the destination is loopback or the request is local-only.

The network check understands common request clients and their data, upload, URL, source, and local-socket options. It also follows command launchers such as xargs and find when they carry a request client. A user namespace created by unshare is blocked because it can grant root inside the namespace and support privilege escalation.

References: src/…/network.ts• L7-18 src/…/network.ts• L123-216 src/…/namespace.ts• L4-59 src/…/segment.ts• L630-661

PowerShell wrapper behavior

PowerShell wrapper analysis reads only a restricted set of wrapper options before -Command. It analyzes a command source when its words are literal or contain no outer expansion. Encoded commands and sources with unknown expansion are dynamic. If an unreadable source contains a recursive delete pattern, the analyzer blocks it rather than treating it as harmless.

PowerShell removal analysis recognizes Remove-Item and its common aliases. It reads path parameters, recursion, force, pipeline input, and -WhatIf. -WhatIf is protective. Pipeline input with no verifiable targets remains unsafe for recursive removal. Home forms are normalized before root, home, Git metadata, and recursive-target checks.

References: src/…/powershell-wrapper.ts• L7-77 src/…/remove-item.ts• L102-217 src/…/remove-item.ts• L220-352 src/…/segment.ts• L824-843

Git behavior

Git analysis separates local discard from shared repository state. Local discard affects a working tree or local repository state. Shared state includes remote history, refs, tags, stashes, and other state that can affect other users. This distinction controls which narrow protections can apply.

The Git rules cover destructive forms of checkout, switch, restore, reset, clean, remove, push, branch, stash, worktree, rebase, merge, tag, and reflog. They also check SSH command overrides for network operations. Dry-run and other non-destructive forms remain available where Git semantics support them.

Two narrow relaxations apply only after the context is verified:

  • A linked-worktree relaxation applies to a known linked worktree. Dynamic arguments, recursive submodules, config includes, forced branch resets, and repeated clean force flags keep the block.
  • A temporary-root relaxation applies to a disposable repository that is trusted as a temporary path, separate from the original workspace, and not selected through explicit Git context.

These relaxations change the result only for the proven local case. Git context overrides, aliases, dynamic arguments, and operations that can reach shared state keep the original rule match.

References: src/…/index.ts• L34-131 src/…/rules.ts• L93-217 src/…/worktree-relaxation.ts• L15-85 src/…/temp-root-relaxation.ts• L16-109 src/…/segment.ts• L710-721

Recursive deletion

Recursive deletion receives a semantic target class before the analyzer decides whether it is safe. The class distinguishes root or home targets, Git metadata, trusted temporary paths, dynamic targets, the current directory, paths inside the original working directory, and paths outside that boundary.

The result depends on the command form and the trust context. rm -rf, cmd recursive removal, find deletion actions, rsync --delete, and PowerShell Remove-Item -Recurse -Force can be allowed only for verified targets inside trusted temporary or configured allow roots, or within the permitted working-directory scope. Root, home, Git metadata, and unsafe outside-directory targets remain blocked.

The rm analyzer expands bounded literal brace forms before it classifies targets. It also records whether a target is literal and whether a $TMPDIR expansion is protected from word splitting. This prevents a safe-looking shorthand from receiving a temporary-path exception when expansion can produce unknown targets. Non-recursive rm still checks Git metadata because metadata protection does not depend on recursive deletion.

The cmd analyzer checks /c and /k bodies after it separates command connectors. It normalizes Windows and PowerShell-style home forms, maps final-segment wildcards to a broad target, and blocks unresolved variables, expansion, directory changes, unsafe quoting, and namespace paths when recursive deletion cannot be verified.

PowerShell Remove-Item checks root and home targets and Git metadata before it applies the recursive-force scope rules. It treats missing targets, dynamic targets, and pipeline input as unverifiable when the active rule requires a proven target. find -delete and find -exec are deletion behavior rather than harmless search. The analyzer checks whether an execution action can remove discovered paths and whether filters exclude protected metadata. File-reading forms such as -files0-from remain visible to path protection.

The scoped-delete check uses the original workspace as an anchor. A command that changes into a trusted temporary directory can use a proven child path there, but it cannot use that change to treat the original workspace as temporary. Unquoted or unsafe $TMPDIR expansion, parent-directory traversal, broad roots, and brace expansion beyond the analysis bound do not receive a scoped allow.

References: src/…/recursive-delete-targets.ts• L79-188 src/…/recursive-delete-targets.ts• L226-364 src/…/recursive-delete-targets.ts• L505-597 src/…/recursive-delete-targets.ts• L805-878 src/…/analyze-command.ts• L824-839

Rsync deletion

Rsync analysis treats --delete as destructive because it removes destination entries that are absent from the source. It separates remote source or destination operands from local deletion targets, then applies the same root, home, Git metadata, temporary-path, working-directory, and allow-root facts used by recursive removal.

A verified destination inside an allowed scope can proceed. Root or home targets and Git metadata always stop. An unverified destination receives the rsync deletion rule rather than an implicit allow.

References: src/…/rsync.ts• L15-19 src/…/rsync.ts• L81-143 src/…/rule.ts• L128-133

Path and protection facts

Path protection uses a shared shell-syntax scan and path identity model. It finds likely reads and writes from operands, redirections, assignments, pipelines, command substitutions, interpreter code, and direct tool fields. It then expands and canonicalizes candidates before comparing them with protected identities.

Path extraction

The path scan separates file targets from data. It treats ordinary command operands as possible paths unless the command is known to consume them only as text. It also checks shell assignments, export values, Git global option values, search roots and actions, interpreter inputs, awk, xargs, and pipeline carriers.

The scan treats file-upload options as reads. It recognizes separate, attached, equals-joined, and supported clustered curl forms. Literal data options and stdin markers do not become local path candidates. Remote URLs are not local files. file: URLs become local paths before protection checks.

PowerShell parameter values attached with : are rescanned as space-separated values, so the command-specific reader decides whether the value is a path. Authentication-file values for ssh, scp, and sftp are marked by their option position so standard-mode secret checks can distinguish key use from file reads. Direct routes use path-like input fields. Grep and glob routes add their route-specific pattern and path fields. Unknown routes combine command-derived paths with direct path fields because their contract is not known well enough to choose one source. Patch input adds file targets from patch text.

Inline interpreter code is classified by the role of each readable literal. A literal used as data or as a known write target can receive a narrower standard-mode treatment. Code that calls a shell, evaluates code, reads files, or uses an unclear language form keeps broader path candidates. The scan also follows command substitutions and decodes path-shaped base64 output when a command substitution can feed a reader.

References: src/…/guard-walk.ts• L142-187 src/…/guard-walk.ts• L190-282 src/…/guard-walk.ts• L293-367 src/…/secret-protection.ts• L509-685 src/…/secret-protection.ts• L717-975 src/…/secret-protection.ts• L1032-1105 src/…/secret-protection.ts• L1363-1407 src/…/secret-protection.ts• L1561-1709 src/…/secret-protection.ts• L2085-2155

Path identity

Path identity gives each guard one answer to whether two path spellings name the same local object. It expands supported environment forms, resolves home paths and file URLs, normalizes platform path forms, and follows existing path components through the supplied resolver.

The identity process keeps lexical and resolved views when the literal location matters. Work limits bound expansion depth, path resolution, and candidate size. A limit is a safety error. It is not permission to continue with a partial identity.

References: src/…/secret-protection.ts• L2302-2333 src/…/secret-protection.ts• L3046-3173 src/…/canonicalization.ts• L42-262

Secret protection

Secret protection asks whether a candidate path could expose sensitive material. Command routes use command-derived candidates. Path, grep, glob, and patch routes use direct path facts. Unknown routes use both sources. The default posture treats unrecognized command operands as possible paths so a new file-reading tool cannot silently bypass the guard.

The rules cover sensitive home directories, common secret names and variants, sensitive extensions, and configuration or credential files used by supported coding tools. User deny paths are checked first. User allow paths can suppress ordinary pattern matches for files the user manages, but they cannot suppress coding-tool credential rules or an explicit deny. Recursive allow entries need a non-home folder before **/ and an exact file name.

Standard mode can avoid a block for metadata-only commands such as listing, stat checks, and read-only searches when no file content is accessed. It also recognizes some known non-read roles. Identity-file values for ssh, scp, and sftp are treated as authentication inputs, and the sole argument of a recognized string predicate in readable inline code is treated as data when the code shape supports that conclusion. These refinements do not apply to strict command mode. Explicit deny paths still apply. A write to a new secret-looking name is not harmless when the target is dynamic.

Inline interpreter code is scanned for file access and process calls. Literal values are treated as data only when the code shape supports that conclusion. Unreadable or opaque code keeps a broad set of path literals under protection. Shell calls such as spawn and popen remain execution sinks.

References: src/…/secret-protection.ts• L274-350 src/…/secret-protection.ts• L352-418 src/…/secret-protection.ts• L1561-1709 src/…/secret-protection.ts• L1787-1903 src/…/secret-protection.ts• L2401-2498 src/…/secret-protection.ts• L3026-3110

Policy file protection

Policy protection prevents a command or write-capable tool from changing the user or project policy configuration that controls the safety net. It resolves policy files and relevant parent directories into path identities. The project policy is protected from both the execution and configuration directories because either location can select the policy used by evaluation.

The guard permits read-only access. It checks redirections, direct path candidates, recursive removal, deletion through find, and moves of a policy file or its containing directory. Structural limits and incomplete command text become conservative denials.

References: src/…/policy-protection.ts• L61-143 src/…/policy-protection.ts• L146-217 src/…/guard-walk.ts• L139-258

Policy application protection

Policy application protection blocks an agent from applying a policy proposal because that action rewrites the configuration used by later safety checks. It recognizes the safety-net policy apply subcommand in direct invocations and supported runner or runtime forms. policy check remains available for showing a proposed change without applying it.

The guard blocks broadly so runner options and version or tag forms cannot hide the target command. Secret protection uses the same recognizer with stricter matching for explain, because only a known safety-net invocation may treat its command argument as analysis data.

References: src/…/policy-apply-protection.ts• L15-49 src/…/safety-net-invocation.ts• L15-79

Git metadata protection

Git metadata protection keeps the repository control plane intact. The guard discovers the .git entry from execution and configuration contexts. It protects the directory, linked-worktree targets, marker files, hooks directories, and lexical or canonical aliases.

The guard applies to write-capable path tools and command mutations. It protects direct metadata writes, redirections, moves, recursive deletes, and hook selection. A metadata match is a hard stop and is not disabled by ordinary command-rule overrides.

When another check considers relaxing a Git metadata block based on names inside the metadata tree, the guard scans every reachable protected root. An unreadable root, symlinked root, or scan-limit crossing counts as a possible match. Incomplete inspection cannot clear protection.

References: src/…/git-metadata-protection.ts• L21-205 src/…/recursive-delete-targets.ts• L276-289 src/…/pipeline.ts• L139-190

Guard evaluation order

The guard evaluates shared facts before it selects the normal command analyzer. This lets path protection stop a dangerous write even when the command is unfamiliar. Non-command tools can be allowed only after their path checks complete.

The evaluation sequence is:

  1. Read the command field safely and create semantic facts.
  2. Reject structural limits before a partial view can reach a protection decision.
  3. Resolve Git metadata and check policy-file mutations.
  4. Block agent invocations of policy apply.
  5. Check Git metadata mutations.
  6. Load the policy snapshot and apply secret protection.
  7. Allow a non-command route if no path guard matched.
  8. Analyze a command route with its shell, context, capabilities, and pre-parsed program.

This diagram shows how one shared fact set feeds protected-path guards and then the behavior analyzer.

flowchart TD
    A[Tool invocation] --> B[Semantic facts]
    B --> C{Structural limit?}
    C -->|yes| D[Deny and stop]
    C -->|no| E[Policy file guard]
    E -->|match| D
    E -->|clear| F[Policy apply guard]
    F -->|match| D
    F -->|clear| G[Git metadata guard]
    G -->|match| D
    G -->|clear| H[Secret path guard]
    H -->|match| D
    H -->|clear| I{Command route?}
    I -->|no| J[Allow non-command tool]
    I -->|yes| K[Semantic command analyzer]
    K --> L[Allow or deny with rule evidence]

The shared command program is passed to command analysis when it is already available. The shared fact store supplies the matching shell facts. Analysis-limit errors become stop-and-explain denials so an incomplete fact set never becomes an allow.

Change checklist

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

  • Parser changes to word provenance, redirections, nested programs, heredocs, or shell dialects must preserve both command behavior analysis and shell-syntax path extraction.
  • Unknown-route parsing must keep the host-platform dialect aligned with path projection, especially for native Windows paths and PowerShell checks.
  • New wrappers or wrapper-option changes must update command normalization, effective-directory tracking, environment propagation, and protected-path scanning together.
  • Container-run isolation changes must keep host-access options, mount modes, uncertain expansions, remote-effect rules, strict or paranoid modes, and custom-rule matching aligned.
  • Changes to PowerShell, cmd, or Remove-Item parsing must keep nested source analysis, aliases, dynamic-source behavior, pipeline input, and recursive-delete checks aligned.
  • Changes to semantic fact extraction or direct tool fields must keep command candidates, path candidates, patch targets, and read-only classification aligned.
  • Changes to recursive-delete target classes must preserve the order of root, home, Git metadata, temporary, dynamic, working-directory, and outside-boundary decisions.
  • Changes to brace expansion, $TMPDIR trust, word splitting, or configured allow roots must keep literal-target facts aligned with the temporary-path exception.
  • Changes to device rules must keep command-head recognition, redirection checks, stable rule IDs, and manual-confirmation reasons aligned.
  • Changes to network client option roles must keep metadata-endpoint detection, remote-upload detection, loopback exceptions, and command-launcher handling aligned.
  • Changes to namespace option parsing must keep value-taking options separate from user-namespace flags so a value is not treated as a privilege action.
  • Changes to assignment extraction, export, Git option values, interpreter code, curl uploads, or pipeline carriers must preserve secret-path matching.
  • Changes to PowerShell attached-parameter handling must keep colon-attached values aligned with space-separated values and command-specific path roles.
  • Changes to SSH, SCP, or SFTP option parsing must keep identity-file classification bounded before the destination and must not classify redirection targets as identity files.
  • Changes to inline-code role recognition must keep known data positions narrow while retaining shell and language execution sinks as path sources.
  • Changes to execution context must preserve shell scope, directory uncertainty, derived-child inheritance, and Git or temporary-path relaxations.
  • Changes to heredoc tracking, downloaded-file tracking, or shell script reads must keep path resolution, persistent-path filtering, file writes, invalidation, bounded reads, and nested script analysis aligned.
  • Changes to analyzer cap kinds or limit handling must keep derived work, trace errors, stable rule IDs, error codes, and stop-and-explain decisions aligned.
  • Changes to path expansion, file-URL handling, symlink resolution, or resolver limits must be checked against secret identities and protected path aliases.
  • Changes to coding-tool secret roots or user allow paths must preserve explicit denies, credential protection, home boundaries, and guard-configuration exclusion.
  • Changes to policy-file or Git metadata locations must preserve every protected identity and containing-directory check.
  • Changes to safety-net command forms must keep the strict explain exemption and broad policy apply block aligned through their shared recognizer.
  • Changes to rsync --delete parsing must keep remote-operand handling and recursive-delete target classification aligned with the standard delete rules.
  • Changes to shell -c source detection must keep remote-fetch substitutions scoped to the script word and preserve dynamic-source blocking through wrappers.
  • Changes to interpreter source parsing must keep syntax checks, downloaded programs, stdin programs, module sources, and dynamic source handling aligned.
  • Rule ID or activation changes must stay aligned with analyzer matches, policy filtering, decision evidence, and explanation output.

Important failure modes

TriggerConsequenceGuard
A command or semantic fact reaches a structural or selected analyzer capThe invocation stops before an incomplete view can become an allowSelected budget kinds become analysis.derived-command-limit stop-and-explain denials and record trace errors.
A dynamic source supplies the executable, guarded option, or nested commandThe action is treated as unverifiable instead of as a fixed commandDynamic-source and dynamic-structure rules fail closed when active.
A standard-mode container run is assumed isolated despite a host-access option, writable or ambiguous mount, or uncertain option expansionA payload action can reach the host while the embedded scan is skippedContainer-run analysis keeps the full scan unless host isolation is proven.
An isolated container payload contains network, Git push, interpreter, or matching custom-rule behaviorAn effect that can leave the container could bypass the behavior checkThe embedded scan retains rules that reach beyond the container. Strict and paranoid modes also keep the full scan.
A custom policy command is compared with different normalization from rule matchingA matching rule can be hidden by the container isolation exceptionContainer analysis compares normalized command tokens before it applies the exception.
A shell -c script word contains an outer substitution that runs curl, wget, or another remote fetcherDownloaded text can become executable script content without a readable local sourceSpan-scoped substitution checks return the dynamic shell-source result.
An encoded or unreadable PowerShell source contains recursive deletionThe nested action is blocked because its target cannot be checkedPowerShell wrapper and removal analysis mark the source dynamic or unsafe.
A cmd body uses expansion, connectors, unsafe quoting, or a namespace path around recursive deletionThe delete target can differ from the visible text or reach a broad Windows locationcmd analysis returns an escaped-quote, dynamic-source, or unsafe result.
PowerShell removal has pipeline input, no target, or a dynamic recursive targetThe command can delete paths that the analyzer cannot namePipeline and dynamic-target rules require explicit verifiable paths.
A recursive-delete target uses an unsafe brace expansion or unprotected $TMPDIR word splitA temporary or working-directory exception can reach unknown pathsTarget facts reject limited expansion and unsafe temporary-variable use.
A wrapper or directory change leaves the effective directory unknownContext-based path and Git relaxations are removedExecution-context state records uncertainty and downstream checks stay conservative.
A device command writes, formats, erases, or redirects to a raw deviceA disk or partition can be destroyed outside ordinary delete controlsDevice-specific rules require manual execution.
A request reaches a cloud metadata endpointInstance credentials can be returned to the commandNetwork behavior rules block known metadata hosts for request-capable commands.
A request uploads data to a non-loopback hostLocal data or secrets can leave the machineUpload option roles and URL scope require manual execution for remote targets.
unshare creates a user namespaceThe command can gain root inside the namespace and support privilege escalationNamespace option analysis requires manual execution.
TMPDIR or a recursive-delete target is empty, split, dynamic, or unresolvedA temporary-path exception can reach an unknown set of pathsTemporary trust and target classification reject unsafe expansion.
Explicit Git context selects another repository or worktreeA local relaxation could affect state outside the proven workspaceGit context overrides disable worktree and temporary-root relaxations.
Git metadata or a policy path is written, moved, or removedThe repository control plane or safety policy can be changedProtected-path guards compare canonical identities before ordinary analysis.
A metadata-tree scan cannot inspect a root or exceeds its limitA possible protected entry is treated as presentGit metadata scans fail closed.
An unfamiliar route receives a secret-looking operand or hides one in an assignment or option valueSensitive content can be read or sent without a route-specific allowlistUnknown routes combine direct and command-derived path candidates.
A PowerShell path value is attached to a parameter with : and the dialect-specific split is lostA command can miss a sensitive path or block a value that the command only treats as dataPowerShell extraction rescans colon-attached values through the command-specific reader.
An SSH, SCP, or SFTP identity option is parsed past the destination or over a redirection targetA copied secret can receive an authentication-input exception or a real identity file can be treated as a readBounded option parsing marks only valid identity values and excludes redirection targets.
Inline code uses a string predicate or another data position that is not recognizedStandard mode can block harmless code or broad literal scanning can miss a later file readRole analysis recognizes supported data positions and retains access and execution sinks.
A curl upload uses an attached, equals-joined, or clustered file formA sensitive local file can leave the host without a separate path argumentUpload extraction identifies file-reading forms before secret matching.
Inline code cannot be safely delimited or models an execution sinkA literal may be a file path or command input even when it looks like dataSecret extraction keeps broad literals and follows shell execution calls.
Interpreter code contains a native recursive delete of a root or home locationA host-wide or user-wide delete can run through a string or nested code pathInterpreter safety scanning blocks the root-or-home match without a standard-mode relaxation.
A downloaded or overwritten script is executed later in the same commandThe analyzer could trust content that the command changed or fetchedWritten and downloaded path tracking keeps later script sources dynamic.
A tracked script path resolves under /dev, /proc, or /sysThe analyzer could read pseudo-filesystem content as trusted shell codePersistent-heredoc filtering excludes those roots from shell-script reads.
rsync --delete targets an unresolved, root, home, or Git metadata destinationDestination files can be removed outside a proven safe scopeRsync reuses recursive-delete classification and blocks unverified destinations.
An agent invokes policy apply through a runner or runtime formThe safety policy used by later checks can be rewrittenPolicy-apply protection blocks the broad recognized invocation.

Key files

FileWhy to read it
src/…/semantic-facts.tsDefines shared command and direct-path facts, host-aware dialect selection, syntax status, path extraction, and parse caching.
src/…/analyze-command.tsShows program traversal, nested analysis, control-flow state, execution context, heredoc and file tracking, created-directory tracking, and fail-closed analysis results.
src/…/index.tsShows the public analyzer boundary and how selected derived-work limits become stop-and-explain decisions with stable evidence and error codes.
src/…/rule.tsShows how command heads receive shared context and how focused rules invoke nested command analysis.
src/…/segment.tsShows wrapper removal, command dispatch, interpreter recursion, script and dynamic-source checks, container isolation, tracked file handling, network and namespace checks, fallback scanning, and known directory changes.
src/…/heredoc-files.tsShows how tracked heredoc paths use the effective directory and how pseudo-filesystem paths are excluded from persistent script reads.
src/…/container-run.tsShows when Docker, Podman, and nerdctl payloads can be treated as isolated from host paths and when host reachability keeps the scan active.
src/…/cmd.tsShows how cmd /c and /k bodies are split, normalized, and classified before recursive-delete decisions.
src/…/rm.tsShows how rm targets and recursive options become literal, expanded, or dynamic target facts.
src/…/powershell-wrapper.tsShows how readable, encoded, and unreadable PowerShell command sources become nested or dynamic analysis.
src/…/remove-item.tsShows how PowerShell removal aliases, parameters, pipeline input, -WhatIf, and target scope become safety decisions.
src/…/recursive-delete-targets.tsDefines the target classes and trust boundaries used for recursive deletion, including temporary paths, allow roots, expansions, working-directory scope, and changed-directory handling.
src/…/wrapper-prelude.tsShows how assignments and sudo, env, command, and builtin wrappers change command words, environment values, and directory context.
src/…/transparent-wrappers.tsShows which wrappers expose a child command and which command types can be reached through them.
src/…/shell-execution.tsShows how shell execution sources, positional parameters, stdin, script operands, remote-fetch substitutions, and dynamic execution carriers are classified.
src/…/interpreters.tsShows interpreter source parsing and the safety backstop for dangerous code, including native root-or-home deletion.
src/…/parallel.tsShows how command templates, stdin, placeholders, remote jobs, and child commands are classified.
src/…/rsync.tsShows how destination deletion is mapped to recursive-delete trust and Git metadata protection.
src/…/device.tsShows the manual-confirmation rules for device writes, disk erase actions, formatting, redirection, and shredding.
src/…/network.tsShows how cloud metadata access and remote uploads are identified across request clients and launchers.
src/…/namespace.tsShows how user-namespace creation is identified without confusing option values with flags.
src/…/index.tsConnects Git rule matches, context checks, aliases, and local-discard relaxations.
src/…/worktree.tsShows how Git working context and repository redirection affect local relaxations.
src/…/guard-walk.tsShows how shell words, redirections, heredocs, scopes, assignments, directory changes, and PowerShell attached parameters become guard events.
src/…/secret-protection.tsShows how command and tool-input candidates become role-aware secret-protection decisions across paths, PowerShell values, authentication files, inline code, uploads, pipelines, and allow rules.
src/…/policy-protection.tsShows how writes to user and project policy files and their containing paths are identified.
src/…/policy-apply-protection.tsShows how agent attempts to apply policy changes are identified and blocked.
src/…/git-metadata-protection.tsShows Git metadata discovery, fail-closed tree scans, and protection of linked worktrees, hooks, and aliases.
src/…/pipeline.tsShows the order in which shared facts, protected-path guards, policy, and command analysis produce a decision.