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 / command-parsing

Command and tool-input parsing

Command and tool-input parsing turns untrusted tool requests into bounded command facts. It identifies shell input, selects one shell dialect, records nested execution sources, and carries context into the safety checks that consume the result. The command safety evaluation page describes the wider decision flow. Semantic command analysis and guards, decisions, explanations, and audit, and the programmatic safety API describe the related analysis and caller-facing results.

Parsing boundary

The parsing boundary separates command execution requests from other tool actions. Command routes produce shell-aware command facts. Other routes produce path, search, or patch facts for their own safety checks.

Tool input routes

The tool route is chosen from the tool name. Names are matched without case, spaces, hyphens, or underscores so equivalent tool names use the same route. A command route also carries the shell kind: POSIX, PowerShell, or automatic selection. A non-command route identifies patch, path, grep, glob, or unknown input.

For a command route, the parser reads a non-empty string from the input object's direct command field. It does not treat arbitrary nested text as a shell command. For non-command routes, the parser instead finds path-like values or patch targets for the relevant guard.

References: src/…/invocation.ts• L1-29 src/…/tool-input.ts• L4-26 src/…/tool-input.ts• L81-109 src/…/common.ts• L124-130

Recursive input traversal

Path and patch extraction can inspect nested arrays and plain objects because tool schemas vary between integrations. The traversal reads only enumerable data properties. It rejects proxies, accessors, unexpected prototypes, cycles, and oversized input rather than invoking behavior supplied by the input.

The traversal has limits for depth, node count, key count, and string size. A limit failure becomes a tool-input failure at the guard boundary. This keeps malformed or hostile tool input from becoming an unbounded source of safety facts.

References: src/…/tool-input.ts• L50-72 src/…/tool-input.ts• L111-143 src/…/tool-input.ts• L145-229 src/…/guard.ts• L252-266

Command structures

A command parser produces a CommandProgram. This structure holds a shell dialect, parse status, issues, source span, and ordered nodes. It gives safety analysis separate views of executable commands, connectors, groups, functions, redirections, and nested programs.

The main command path follows this shape from raw input to analysis facts:

flowchart LR
  A[Tool command string] --> B[Dialect selection]
  B --> C[CommandProgram]
  C --> D[Command views]
  C --> E[Nested programs]
  D --> F[Shell syntax projection]
  D --> G[Command safety analysis]
  E --> G

Dialect selection

parseCommand accepts an explicit shell kind or uses auto. An explicit PowerShell route always uses the PowerShell parser. An explicit POSIX route uses the POSIX parser. Automatic selection first looks for bounded PowerShell signals such as recognized command heads, PowerShell path forms, parameters, environment variables, or block comments. It then parses the candidate with the PowerShell parser and selects that dialect only when the parsed commands or comment state confirm a PowerShell form. POSIX heredoc syntax prevents a false PowerShell choice.

Automatic selection examines nested commands and ignores quoted or commented text while it builds its selector view. Shared names such as cat, cp, mv, and rm count as PowerShell signals only when their arguments show PowerShell paths or parameters. This avoids selecting PowerShell merely because a name exists in both shells.

This single choice matters because the same characters can have different meaning across shells. The parser never runs both dialects and merges their results. It creates one program whose dialect stays attached to every command view.

References: src/…/parse.ts• L12-24 src/…/powershell.ts• L36-110 src/…/powershell.ts• L113-145 src/…/powershell.ts• L628-710

POSIX command structure

The POSIX parser groups words into commands and separates commands with shell connectors such as sequencing, pipelines, and conditional operators. It also treats comments, line continuations, quotes, and redirections as shell syntax instead of ordinary word text.

Words retain their decoded text, raw source, span, quoting state, and provenance. Provenance marks values that come from variables, command or arithmetic substitution, or glob syntax. Nested programs represent command substitutions, arithmetic substitutions, process substitutions, and backtick substitutions. Groups and function definitions keep their bodies as programs so later analysis can distinguish a definition from a call. Function substitutions that run in the current shell are marked unsupported rather than treated as ordinary nested commands.

The parser also recognizes literal brace alternatives in command position within bounded expansion limits. It understands standard wrapper prefixes such as command, env, and sudo when it decides which word is the executable position. This keeps finite literal alternatives visible while avoiding expansion of dynamic or uncertain words.

References: src/…/posix.ts• L61-110 src/…/posix.ts• L192-312 src/…/posix.ts• L314-470 src/…/posix.ts• L502-642 src/…/posix.ts• L644-815 src/…/posix.ts• L1032-1162 src/…/posix.ts• L1424-1555 src/…/command.ts• L18-40

PowerShell command structure

The PowerShell parser uses whitespace, line breaks, PowerShell operators, comments, and script blocks to form commands. It keeps quoted separators inside one word and records command subexpressions as nested PowerShell programs. Automatic shell selection uses the same parsed structure to inspect command heads and nested commands.

PowerShell words preserve variable and subexpression provenance. Backtick escapes and quoted strings are decoded into word text while their source spans remain available. Script blocks become grouped bodies, which lets downstream analysis inspect commands inside a block without treating block markers as command arguments. Redirections remain attached to the command with their target words.

The parser handles line comments and nested block comments as syntax. An unclosed block comment is invalid. An unclosed quote, command subexpression, or trailing escape leaves a partial program. Nested script blocks and command subexpressions remain bounded by the shared depth and word limits.

References: src/…/powershell.ts• L113-319 src/…/powershell.ts• L321-460 src/…/powershell.ts• L462-549 src/…/powershell.ts• L654-710

Parse status and limits

Every program reports one of four statuses: complete, partial, invalid, or limited. Partial status means the parser found a usable structure with a syntax issue such as an unclosed quote. Invalid status marks forms whose meaning is not safe to infer, such as an unclosed PowerShell block comment or an ambiguous heredoc delimiter. Limited status means the input crossed a size, word, or nesting bound.

The default command limits are 131,072 input code units, 16,384 words, and 64 levels of nesting. The POSIX parser also bounds literal brace expansion by the shared word, depth, and input limits. These limits apply to direct structure and derived nested structure. Downstream code can therefore treat a limited program as a hard boundary instead of guessing what was outside the parsed area.

References: src/…/model.ts• L5-16 src/…/model.ts• L143-163 src/…/parse.ts• L12-24 src/…/posix.ts• L73-110 src/…/posix.ts• L1281-1301 src/…/posix.ts• L1506-1555 src/…/powershell.ts• L113-145 src/…/powershell.ts• L703-710

Nested input

Shell input can contain more commands than its top-level text suggests. Substitutions, process substitutions, groups, function calls, interpreters, dynamic-input tools, and command wrappers create nested execution paths. Parsing records these paths so analysis can inspect them without executing substitutions or expanding the real environment.

Command views

walkCommandViews traverses command nodes in source order and enters nested programs. projectCommandViews materializes that traversal for consumers that need a flat list of command views. Each view carries words, redirections, source text, spans, and nested programs.

The traversal does not turn a POSIX function definition into an executed command. A definition remains structural until a later call-aware projection or analysis step finds a direct call. parseSimpleWords provides a narrower result for places that need one plain command. It returns no argument list when nesting, redirection, substitution output, or incomplete syntax makes the result uncertain. During command analysis, literal PowerShell evaluation sources are parsed as bounded nested programs when their form is clear.

References: src/…/traversal.ts• L4-35 src/…/traversal.ts• L38-45 src/…/command.ts• L59-69 src/…/command.ts• L124-151 src/…/analyze-command.ts• L555-613 src/…/analyze-command.ts• L615-642

Heredoc bodies

A heredoc is shell input declared by << or <<- and terminated by a delimiter line. The parser removes supported quoting and escaping from the delimiter, records whether it was quoted, consumes bodies in declaration order, and attaches the body and its source spans to the redirection.

The body is data in the command structure. It is not automatically split into top-level command views. A quoted delimiter also tells downstream logic that shell expansion is disabled in the body. An unquoted, missing, ambiguous, or unterminated delimiter produces an issue because the parser cannot safely know where shell input ends.

A body sent to an interpreter may itself be a program. A body in a backtick substitution, process substitution, group, or function context is not treated as a safely supported heredoc form. During safety analysis, a literal body can also become a tracked local file when a supported command writes it to a persistent path. Later shell source or startup-file reads can then re-enter that body as a bounded nested program.

References: src/…/heredoc.ts• L3-17 src/…/heredoc.ts• L19-70 src/…/heredoc.ts• L73-113 src/…/posix.ts• L314-429 src/…/posix.ts• L817-852 src/…/posix.ts• L1763-1779 src/…/command.ts• L42-57 src/…/analyze-command.ts• L697-892 src/…/analyze-command.ts• L945-993

Nested heredoc contexts

Heredoc handling depends on where the body goes. Ordinary supported data sinks can keep a quoted body as inert data. A body sent to an interpreter may itself be a program. A body in a backtick substitution, process substitution, group, or function context is not treated as a safely supported heredoc form.

The shell syntax projection masks quoted bodies only for known inert data sinks such as cat, tee, and message commands. It keeps bodies that can execute, reach a pipe, use an output process substitution, or name files visible to scanners. For nested heredocs, the projection re-parses body text with its own bounded context so commands inside executable text remain reachable without allowing recursion to grow without limit.

References: src/…/entry-projection.ts• L47-80 src/…/entry-projection.ts• L207-301 src/…/entry-projection.ts• L559-624 src/…/posix.ts• L395-415 src/…/posix.ts• L778-852 src/…/analyze-command.ts• L1141-1327

Function and group traversal

Groups represent nested shell bodies that execute as part of the surrounding structure. POSIX function definitions represent named bodies that are inert until a direct call. During analysis, calls enter the stored function body while the definition stays out of the execution stream.

Function expansion has both depth and total-expansion bounds. This matters for recursive or branching definitions because a short source can produce a large derived command stream. When a bound is reached, analysis returns a structural-limit result instead of producing an incomplete stream that safety analysis might trust. Conditional branches retain alternative states when && or || can choose different paths. Subshells, pipelines, and background work keep their file-system effects isolated from the parent state. Literal POSIX for items can create bounded alternative states, while PowerShell brace blocks are isolated according to their surrounding command.

References: src/…/posix.ts• L197-245 src/…/posix.ts• L276-312 src/…/entry-projection.ts• L22-25 src/…/entry-projection.ts• L96-161 src/…/entry-projection.ts• L580-586 src/…/analyze-command.ts• L195-455 src/…/analyze-command.ts• L1369-1472

Command wrapper sources

Command wrappers carry a second command stream inside an argument or input channel. The analyzer extracts a literal source when its wrapper syntax makes the source clear, then sends that source through the same nested analysis path with the active shell and context.

The Windows cmd wrapper reads the body after /c or /k. It keeps connector-separated child commands visible and checks recursive rmdir, rd, del, and erase forms before it falls back to nested analysis. Escaped quotes, Windows namespace paths, variables, wildcards, or directory-changing text can make the body unverifiable, so the source remains dynamic instead of being trusted.

PowerShell and pwsh wrappers accept a literal script after recognized setup switches and -Command or -c. The recognized setup switches are limited to profile, interactivity, logo, and execution-policy options. A literal script is sent to nested PowerShell analysis. -EncodedCommand, --%, expansion-bearing words, and other unreadable sources remain dynamic. An unreadable recursive delete produces an explicit recursive-delete result rather than an assumed-safe result.

References: src/…/cmd.ts• L18-130 src/…/powershell-wrapper.ts• L7-65 src/…/rule.ts• L69-105 src/…/segment.ts• L278-395

Dynamic-input producers

Dynamic-input producers create child commands from data that is not fully written in the command template. xargs and GNU Parallel keep their child template, replacement markers, possible jobs, and input mode separate so downstream analysis can test the commands that the input can create.

Each child candidate carries provenance for its working directory, environment assignments, wrappers, remote execution, and dynamic input. The analyzer uses this provenance to detect when input can change the executable, shell source, delete options, or protected Git operation. Parallel command streams, unsupported replacement forms, remote jobs, and derived job groups stay bounded. Unsupported command forms remain untrusted instead of becoming a complete command list.

References: src/…/child-command.ts• L10-57 src/…/child-command.ts• L76-183 src/…/dynamic-input.ts• L6-33 src/…/xargs.ts• L57-140 src/…/parallel.ts• L126-255 src/…/parallel.ts• L378-463 src/…/parallel.ts• L878-1067

Safety-analysis handoff

Parsing supplies two related views to the safety system. The command program preserves shell structure for command analysis. The shell syntax projection turns that structure into a flat stream of words, operators, and redirections for path and syntax scanners.

Semantic fact store

The semantic fact store caches each command and dialect pair and keeps its shell projection beside the parsed program. It may hold both an input command found in tool data and a command declared by a command route. When both sources contain the same text, the store records both uses rather than parsing the text twice.

This shared fact set lets policy, path, secret, and command checks inspect the same source interpretation. A limited program receives an empty structural shell stream with a structural-limit status. Callers cannot mistake missing entries for proof that the input is safe.

References: src/…/semantic-facts.ts• L41-54 src/…/semantic-facts.ts• L56-104 src/…/semantic-facts.ts• L121-164 src/…/semantic-facts.ts• L24-44

Shell syntax projection

The shell syntax projection exposes words, operators, and redirections in the form used by path and shell scanners. It removes shell quoting from word text, normalizes variable spellings, preserves dynamic markers, and marks redirections by role such as file read, file write, or here-data.

The projection keeps uncertainty visible. Unclosed quotes, invalid structure, and structural limits produce an empty or bounded result with a status rather than a partial stream that appears complete. It also preserves assignment fallbacks because an expansion can create a path or command value at use time. Newline and heredoc terminator boundaries remain explicit so text from a body cannot join the command that follows it.

References: src/…/entry-projection.ts• L47-93 src/…/entry-projection.ts• L164-205 src/…/entry-projection.ts• L207-301 src/…/entry-projection.ts• L303-557 src/…/semantic-facts.ts• L6-22

Redirection targets

Redirections remain structured facts with an operator, file descriptor, target word, and target provenance. This lets downstream safety checks inspect a write target even when the command head is not itself a destructive command.

The device checks use these facts to block literal writes to block-device paths. The same handoff also lets command analysis distinguish ordinary file input and output from here-data, device writes, and other forms that need a separate safety rule.

References: src/…/analyze-command.ts• L741-752 src/…/device.ts• L60-63 src/…/device.ts• L106-140 src/…/command.ts• L42-57

Executable source extraction

Shell wrappers and interpreter commands can carry a second command as a string, a script operand, standard input, a startup file, or a tracked local file. The analyzer classifies each source as absent, literal, or dynamic. It parses and analyzes a literal source as a nested command while keeping the parent context.

Literal positional shell parameters can be expanded when their values are known and the result stays within parser limits. The same bounded handling covers forms such as eval, shell wrappers that carry a command string, cmd /c, and PowerShell -Command. PowerShell iex and invoke-expression also re-enter analysis when they receive one clear literal source. A source that depends on dynamic arguments, pipeline input, shell parameters, environment values, encoded commands, or an unresolved execution carrier produces an explicit uncertainty result. A narrow local-generator form can be verified before its generated source is trusted. Remote fetchers and shell wrappers do not qualify. This prevents a source carrier from hiding work that the command structure does not show.

References: src/…/shell-execution.ts• L72-135 src/…/shell-execution.ts• L138-232 src/…/shell-execution.ts• L248-307 src/…/shell-execution.ts• L407-605 src/…/cmd.ts• L71-130 src/…/powershell-wrapper.ts• L21-65 src/…/analyze-command.ts• L555-642 src/…/segment.ts• L232-425

Execution context propagation

Nested command analysis keeps the context that changes command meaning. This context includes the effective working directory, environment assignments, wrapper effects, and whether input can change a command's structure.

Shell segments update tracked TMPDIR, IFS, and Git context values across assignments, export, append, and unset operations. They also track known working-directory changes from POSIX directory commands and PowerShell location commands. Literal pipeline input can supply a PowerShell location target. These values are carried into later segments and nested commands. The analyzer also carries literal heredoc files and known created directories so later reads and path checks use the state established by earlier commands. The analyzer uses the resulting context when it resolves aliases, interprets Git configuration, classifies delete targets, and decides whether a worktree or temporary-root relaxation is valid.

The segment analyzer treats location changes as unknown when the command, target, or path search cannot be proved static. POSIX CDPATH effects also make the directory unknown when a relative target cannot be resolved. Unknown or dynamic context disables context-based relaxations instead of treating inherited context as fixed.

References: src/…/segment.ts• L91-190 src/…/segment.ts• L559-677 src/…/segment.ts• L971-1134 src/…/analyze-command.ts• L145-161 src/…/analyze-command.ts• L869-1057 src/…/child-command.ts• L17-56 src/…/shell-git-env.ts• L33-187 src/…/shell-git-env.ts• L219-315 src/…/index.ts• L41-90

Transparent wrappers

Transparent wrappers change how a command starts without changing the command that safety rules must inspect. The analyzer removes standard wrappers and policy-approved execution wrappers, then re-runs the same command analysis on each possible child position.

Wrapper handling preserves alternative child positions when the wrapper syntax leaves more than one protectable interpretation. It limits repeated peeling so a long wrapper chain cannot create unbounded derived work. The same normalized child path is used for built-in rules, shell sources, custom rules, and dynamic-input provenance.

References: src/…/transparent-wrappers.ts• L8-48 src/…/transparent-wrappers.ts• L51-101 src/…/segment.ts• L152-229 src/…/segment.ts• L527-591 src/…/segment.ts• L929-934

Destructive target interpretation

Delete commands are handed target facts that combine word provenance with the active shell and path context. The analyzer distinguishes literal, dynamic, temporary, current-directory, outside-directory, root or home, and Git metadata targets before it applies a safety rule.

The same target model supports POSIX rm, find delete actions, Windows cmd recursive delete forms, and PowerShell Remove-Item. PowerShell aliases, abbreviated parameter forms, -WhatIf, and pipeline input are mapped to the same high-level questions. find -exec commands are analyzed as child commands, so a delete hidden in a found path or wrapper remains visible. Shell-specific expansion, pipeline input, and Windows command-body quoting remain visible as uncertainty. This lets downstream safety analysis treat an unverified target as unsafe without losing the source shell or command context.

References: src/…/recursive-delete-targets.ts• L24-107 src/…/recursive-delete-targets.ts• L109-301 src/…/rm.ts• L57-177 src/…/find.ts• L108-155 src/…/find.ts• L160-213 src/…/cmd.ts• L31-160 src/…/remove-item.ts• L103-219

Rule dispatch

After wrapper and environment normalization, the analyzer maps a command head to a focused rule family. The rule family receives the same command words, shell context, child-analysis callbacks, and shared budget that the surrounding traversal uses.

The dispatch covers destructive deletion, device operations and device-target redirections, Windows cmd, PowerShell wrappers and deletion, Git operations, find, xargs, and GNU Parallel. It also scans unknown commands for embedded protected commands and applies custom policy rules. This relationship lets a nested command reach the same safety rule as a top-level command without treating every unknown word as a complete command.

References: src/…/rule.ts• L39-139 src/…/segment.ts• L559-677 src/…/segment.ts• L905-933 src/…/device.ts• L65-140

Guard handoff

The guard builds semantic facts before it runs policy, secret, and command checks. It passes the declared parsed program and the shared fact store into command analysis so later work uses the same parse. The gate analyzer keeps one analysis budget for derived commands, wrapper normalization, heredoc files, and control-flow work.

Command analysis walks program nodes and follows nested programs, conditional states, function calls, and isolated shell contexts. Segment analysis normalizes wrappers, follows executable source carriers, propagates working-directory and environment context, and dispatches dynamic-input children with their provenance. A limit in derived commands, tracked heredoc files, control-flow states, or wrapper peeling becomes a whole-command denial with an analysis error code. In strict mode, partial or unsupported syntax stops with an explanation. In standard mode, some uncertain forms fall back to dangerous-text checks. This creates a clear boundary: parsers describe what can be known. Guards decide what to do when it cannot be known safely.

References: src/…/guard.ts• L102-140 src/…/guard.ts• L209-240 src/…/index.ts• L16-94 src/…/analyze-command.ts• L76-160 src/…/analyze-command.ts• L195-405 src/…/segment.ts• L81-227 src/…/rule.ts• L61-147

Change checklist

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

  • Keep CommandProgram statuses and issue codes aligned with the guard's strict and standard handling. A new parser issue can silently change allow or deny behavior.
  • Keep word provenance and nested-program spans aligned with shell syntax projection. A mismatch can hide a dynamic executable or scan a nested command at the wrong source location.
  • Keep heredoc delimiter rules aligned with body projection, tracked-file state, and interpreter handling. Changes can turn data text into executable text or hide commands after a terminator.
  • Keep tool route names and input-key sets aligned with integration adapters and semantic fact extraction. A route that changes name normalization can bypass the intended path or patch scan.
  • Keep parser and tool-input limits aligned with the guard's failed-closed error mapping. A new limit must still produce a clear validation or analysis denial.
  • Keep dynamic-input provenance aligned with child-command normalization. A mismatch can miss an input-controlled executable, delete option, or shell source.
  • Keep shell source classification aligned across literal positional expansion, shell wrappers, cmd /c or /k, PowerShell -Command, stdin, startup files, tracked heredocs, and dynamic execution carriers. A source that changes from literal to dynamic must not remain trusted.
  • Keep Windows command-body splitting and PowerShell wrapper switch parsing aligned with nested-shell analysis. A new wrapper spelling must not skip its inner command or treat an encoded or expansion-bearing source as literal.
  • Keep redirection operators, file descriptors, target provenance, and block-device matching aligned. A change can make a device write look like an ordinary file redirect.
  • Keep environment and working-directory updates aligned across shell segments and nested commands. Changes to TMPDIR, IFS, Git context variables, CDPATH, or compound-body scope can change target trust and Git operation meaning.
  • Keep Git alias and config resolution aligned with worktree and temporary-root relaxation. Unknown aliases, config, dynamic arguments, linked worktrees, or workspace overlap must not receive a local-discard relaxation.
  • Keep delete-target classification aligned across POSIX, find, cmd, and PowerShell paths. Root, home, Git metadata, current-directory, temporary, and dynamic targets must reach the matching policy rule.
  • Keep rule-head dispatch aligned with wrapper stripping and child-command analysis. A recognized command must not be skipped when it arrives through a transparent wrapper or dynamic producer.
  • Keep POSIX CDPATH and PowerShell location-command handling aligned with effective-directory propagation. An unresolved location must not retain a prior directory that could enable a context-based relaxation.
  • Keep GNU Parallel parsing aligned with child expansion, remote and workdir context, stdin provenance, and derived-token limits. A new input mode must not create an unexamined command stream.

Important failure modes

TriggerConsequenceGuard
Command input exceeds length, word, or nesting limitsNo trusted complete structure is availableReturn a structural or command-analysis denial instead of guessing
Tool input contains a proxy, accessor, cycle, unexpected prototype, or too much dataRecursive extraction stops with a tool-input limit errorFail closed before policy or path facts are built
Quote, substitution, or script block is not closedProgram is partial and may not describe the shell's full executionReject in strict mode; use bounded fallback handling in standard mode
Heredoc delimiter is missing, ambiguous, or not terminatedBody boundaries cannot be trustedMark the program invalid and require strict verification or raw-text fallback
Unquoted or unsupported heredoc feeds an interpreter or unknown consumerText may be executable or may hide a commandScan the body conservatively or stop with a heredoc explanation
A literal heredoc file is overwritten or changed before a later source readA tracked source no longer represents the body that will runInvalidate the tracked file on writes and fail closed when the source is not known
Executable word comes from substitution or another dynamic valueThe command name cannot be resolved from literal wordsPreserve provenance and analyze nested programs without treating the dynamic name as known
Recursive or branching function calls exceed expansion workThe projected command stream is incompleteReturn a structural-limit result and do not treat omitted calls as safe
Conditional, pipeline, subshell, or background paths change state in different waysA later command may be analyzed with one path's context onlyCarry alternative states and isolate file-system effects where the shell does
Automatic shell selection sees a shared command name without a PowerShell path or parameter signalThe command can be parsed with the wrong shell rulesUse the bounded selector and keep POSIX as the default when no PowerShell form is clear
A literal redirect writes to a block-device pathThe command can overwrite a disk or partition outside ordinary file safety rulesMatch the structured redirection target and deny the device write
A device command formats, erases, repartitions, or shreds a device or targetData can be destroyed even when no recursive-delete pattern is presentApply the device command rule before allowing the command to proceed
cmd /c or /k contains escaped quotes, namespace paths, dynamic expansion, or recursive delete text with unclear boundariesThe inner Windows command may target a different path or hide another commandBlock escaped or unverifiable recursive deletes and keep the source dynamic
PowerShell wrapper uses -EncodedCommand, --%, expansion-bearing input, or another unreadable sourceThe nested script cannot be inspectedReturn a dynamic-shell-source result or the explicit unreadable-recursive-delete result
PowerShell Remove-Item -Recurse -Force receives pipeline input or dynamic targetsThe delete target cannot be verified from the command wordsRequire explicit literal targets and apply the pipeline or dynamic-target rule
xargs or GNU Parallel input can change the executable, shell source, or destructive optionsA safe-looking child template can create a different commandCarry dynamic-input provenance into child analysis and deny the matching dynamic-source rule
Parallel jobs, argument groups, remote mode, or derived tokens exceed analysis limitsThe child command set or its execution context is incompleteConvert the analyzer limit or unsupported mode into a whole-command denial
Shell -c, eval, source, interpreter, stdin, startup input, or positional expansion is dynamicExecutable source is not visible in the parsed commandStop with a dynamic-source explanation instead of treating the carrier as inert
A shell location command has a dynamic, unsupported, or unresolved targetLater path and Git checks cannot prove the active directoryKeep the effective directory unknown and do not apply context-based relaxations
Git aliases or config from command-line or environment input are malformed, executable, or too deepThe visible Git subcommand may not be the operation that runsBlock alias expansion or keep the operation unrelaxed
Git network operation uses GIT_SSH, GIT_SSH_COMMAND, or equivalent configGit can execute an unexpected command during network workBlock the SSH override before applying a destructive-command result
Shell environment assignments change tracked Git context or TMPDIR during traversalA later segment is analyzed with the wrong repository or path trustPropagate assignments, export, append, and unset effects before nested analysis
A local-discard Git rule has dynamic arguments, recursive submodules, or a forced branch resetA worktree-only relaxation can affect shared stateKeep the original Git match instead of applying the relaxation
A temporary-root Git target overlaps the workspace, is the temp root itself, or has an explicit Git contextThe operation can affect the protected workspace or a different repositoryRequire a verified disposable repository or worktree and refuse overlap
A recursive delete target resolves to root, home, Git metadata, cwd itself, or an unverified dynamic pathThe command can remove more data than its visible spelling suggestsClassify the target before applying the shell-specific delete rule
find -exec or find -delete reaches a root, home, metadata, or dynamic targetA path search can remove data outside the visible starting pointAnalyze starting points and child commands before applying a delete rule
POSIX CDPATH or PowerShell location input prevents a known directory resultA later command may inherit a false working directorySet the effective directory to unknown and disable directory-based relaxations

Key files

FileWhy to read it
src/…/parse.tsMain parser entry point and dialect selection
src/…/posix.tsPOSIX structure, words, substitutions, redirections, groups, functions, and bounded literal expansion
src/…/powershell.tsPowerShell selection, comments, script blocks, subexpressions, redirections, and words
src/…/heredoc.tsHeredoc delimiter and body boundaries
src/…/tool-input.tsSafe tool-input extraction and patch or path traversal
src/…/traversal.tsCommand-view traversal and simple-word projection
src/…/entry-projection.tsFlat shell syntax facts, function expansion, and inert-versus-executable heredoc handling
src/…/command.tsShared command-program, word, redirection, and node contract
src/…/semantic-facts.tsParser cache and handoff into policy and safety facts
src/…/guard.tsValidation decisions and parser-to-analysis boundary
src/…/index.tsPublic analyzer entry point and derived-work limit handling
src/…/analyze-command.tsProgram traversal, control-flow states, heredoc file tracking, device-redirection checks, and nested analysis
src/…/segment.tsMain segment traversal, wrapper handling, executable source extraction, working-directory effects, and rule dispatch
src/…/cmd.tsWindows cmd /c and /k body traversal and recursive-delete checks
src/…/powershell-wrapper.tsPowerShell wrapper source recognition and unreadable nested-command handling
src/…/device.tsDevice commands and block-device redirection rules
src/…/transparent-wrappers.tsStandard and policy-approved wrapper normalization
src/…/rule.tsMapping from normalized command heads to focused safety analyzers
src/…/find.tsfind delete actions and nested -exec command analysis
src/…/rm.tsPOSIX recursive-delete target interpretation
src/…/remove-item.tsPowerShell delete aliases, parameters, pipeline input, and target interpretation
src/…/parallel.tsGNU Parallel templates, jobs, stdin, remote context, and bounded child expansion
src/…/shell-execution.tsLiteral, positional, stdin, startup, and dynamic shell source extraction
src/…/recursive-delete-targets.tsShared target classification for recursive delete safety