---
title: "Security Gates and Operator Deny Rules"
description: "How OrchestKit blocks dangerous commands, protects sensitive files, and auto-approves safe operations: the defense-in-depth hooks that run before every tool use."
canonical: "https://orchestkit.dev/docs/hooks/safety-hooks"
---

# Security Gates and Operator Deny Rules

How OrchestKit blocks dangerous commands, protects sensitive files, and auto-approves safe operations: the defense-in-depth hooks that run before every tool use.

import { Callout } from "fumadocs-ui/components/callout";
import { Tab, Tabs } from "fumadocs-ui/components/tabs";

## Defense in Depth

OrchestKit implements security at multiple layers. No single hook is responsible for all safety; instead, hooks compose to form a defense-in-depth chain:

```
PermissionRequest  -->  PreToolUse  -->  Tool Executes  -->  PostToolUse
      |                     |                                     |
  auto-approve        operator deny rules                    secret-handler
  safe commands       (enforced by Claude Code)              redact-secrets
  project writes      sync-bash-dispatcher                   failure-handler
                                                             (on tool errors)
                      sync-write-edit-dispatcher
                      sync-task-dispatcher
```

If any hook in the chain returns `{ continue: false }`, the operation is blocked and Claude receives the `stopReason` explaining why.

## Destructive Commands: Operator Deny Rules

The old `pretool/bash/dangerous-command-blocker` hook was removed in #3841. Its patterns are now `permissions.deny` rules in your own settings scope (`~/.claude/settings.json` or `<project>/.claude/settings.json`). A plugin cannot ship enforcing permission rules, because Claude Code reads only `agent` and `subagentStatusLine` from a plugin settings file. Rules in your own scope are enforced by Claude Code itself, even under `--dangerously-skip-permissions`.

- **Written by** `/ork:setup` phase 3.6, which shows a dry run first and writes only after you say yes. The payload is `src/skills/setup/references/operator-permissions.json`, delivered by `src/skills/setup/scripts/write-operator-permissions.mjs`.
- **Audited by** `/ork:doctor` (`check-operator-permissions.sh`), which reports whether the rules are present.

### What the Rules Deny

| Rule (examples) | Category |
|-----------------|----------|
| `Bash(rm -rf /)`, `Bash(rm -rf ~)`, `Bash(rm -fr .)` | Filesystem destruction |
| `Bash(mv /* /dev/null)` | Filesystem destruction |
| `Bash(> /dev/sd*)`, `Bash(mkfs*)`, `Bash(dd if=*)` | Device wiping |
| `Bash(chmod 777 *)`, `Bash(chmod -R 777 *)` | Permission abuse |
| `Bash(find *-delete*)` | Bulk deletion |
| `Bash(git push --force origin main)` and its `-f` and `master` variants | Force push to main or master |
| `Read(~/.ssh/**)`, `Read(**/.env)`, `Edit(**/*.pem)` | Secret and credential files |

The JSON file holds the full list. It also names two admitted gaps: the SQL substrings the old hook matched (`drop database`, `drop schema`, `truncate table` inside a `psql -c` string) and the fork bomb cannot be written as `Bash()` rules, so no rule denies them.

### What Still Runs as a Hook

`pretool/bash/sync-bash-dispatcher` is the synchronous PreToolUse entry for Bash. Inside it, `pretool/bash/network-egress-guard` keeps a DENY tier for commands that execute fetched remote content, such as `curl url | bash`.

## Protected Files: Operator Deny Rules

The old `pretool/write-edit/file-guard` hook was removed in #3835 (wave 3). Its protected-file patterns are now `Read()` and `Edit()` deny rules in the same operator payload as the Bash rules above, so Claude Code refuses them itself:

| Rules | Files |
|-------|-------|
| `Read(**/.env)`, `Read(**/.env.local)`, `Read(**/.env.production)`, `Edit(**/.env)`, `Edit(**/.env.local)`, `Edit(**/.env.production)` | Environment files |
| `Edit(**/credentials.json)`, `Edit(**/secrets.json)` | Credential files |
| `Edit(**/*.pem)`, `Edit(**/private.key)`, `Edit(**/id_rsa)`, `Edit(**/id_ed25519)` | Private keys |
| `Read(~/.ssh/**)`, `Read(~/.gnupg/**)`, `Read(~/.aws/credentials)`, `Read(~/.netrc)`, `Read(~/.npmrc)` | Home-directory secrets |
| `Edit(**/.husky/**)` | Git hook scripts |

What went with the hook: the config-file warnings (`package.json`, `pyproject.toml`, `tsconfig.json`) and the file size gate. The `ORCHESTKIT_MAX_FILE_LINES` and `ORCHESTKIT_MAX_TEST_FILE_LINES` variables no longer do anything.

## Git Safety

The old `pretool/bash/git-validator` hook was removed in #3841. What it protected now lives in two places:

- **Force pushes to `main` or `master`** are denied by the operator rules (`Bash(git push --force origin main)` and its `-f` and `master` variants).
- **Direct pushes to a protected branch** are refused by the branch protection on the remote, not by a local hook.

Its branch-naming and commit-message checks were not carried over: a permission rule cannot read the current branch or a commit message.


## Permission Auto-Approve Hooks

OrchestKit includes three permission hooks that reduce friction for safe operations.

### Auto-Approve Safe Bash

**Hook:** `permission/auto-approve-safe-bash`
**Event:** PermissionRequest (Bash)

Auto-approves bash commands that are known to be read-only or safe:

| Category | Approved Patterns |
|----------|-------------------|
| **Git read ops** | `git status`, `git log`, `git diff`, `git branch`, `git show`, `git fetch`, `git pull`, `git checkout` |
| **Package managers** | `npm list`, `npm test`, `npm run`, `pnpm audit`, `yarn outdated`, `poetry show` |
| **Docker read ops** | `docker ps`, `docker images`, `docker logs`, `docker-compose ps` |
| **Shell basics** | `ls`, `pwd`, `echo`, `cat`, `head`, `tail`, `wc`, `find`, `which`, `env` |
| **GitHub CLI** | `gh issue list`, `gh pr view`, `gh repo status`, `gh milestone` |
| **Testing/linting** | `pytest`, `npm run test`, `npm run lint`, `ruff check`, `mypy` |

Commands not matching any safe pattern fall through to manual user approval; they are not denied, just not auto-approved.

### Auto-Approve Project Writes

**Hook:** `permission/auto-approve-project-writes`
**Event:** PermissionRequest (Write|Edit)

Auto-approves file writes that are within the project directory, with exclusions:

```typescript
// Path containment check (prevents prefix attacks)
const relativePath = relative(normalizedProject, normalizedFile);
const isInsideProject = !relativePath.startsWith('..') && !isAbsolute(relativePath);
```

**Excluded directories** (require manual approval even within project):
- `node_modules/`
- `.git/`
- `dist/`
- `build/`
- `__pycache__/`
- `.venv/` and `venv/`

<Callout type="info">
The path containment check uses `path.relative()` instead of string prefix matching. This prevents the attack where `/project-malicious/evil.js` would match a project at `/project` via naive `startsWith` comparison.
</Callout>

### Auto-Approve Read Operations

Read, Glob, and Grep operations have an empty hooks array in the `PermissionRequest` configuration, meaning Claude Code auto-approves them with zero overhead.

### Learning Tracker

**Hook:** `permission/learning-tracker`
**Event:** PermissionRequest (Bash)

Tracks which commands the user manually approves over time. This data feeds into pattern learning: if you consistently approve `docker build` commands, the system notes this for potential future auto-approval.

## Additional PreToolUse Safety Hooks

Beyond the operator deny rules and the sync Bash dispatcher, two dispatchers run more checks at the PreToolUse stage:

### Write and Edit

`pretool/write-edit/sync-write-edit-dispatcher` runs `content-secret-scanner`, `context-file-budget-guard`, `dependency-confusion-scanner` and `write-headers`, then `unified-quality-dispatcher`. That dispatcher calls `security-pattern-validator` first: it checks code being written for hardcoded secrets, SQL and command injection, `eval`/`exec`, `shell=True`, `innerHTML`, insecure random numbers and plain HTTP URLs, and adds a warning to Claude's context (it does not block). Then `architecture-change-detector` adds context when a write touches an architecturally significant file, reminding Claude about backwards compatibility and documentation.

### Agent spawns (Task hooks)

`pretool/task/sync-task-dispatcher` runs no agent safety check. Its last one, `security-command-audit`, was deleted on 2026-12-05: it acted only on Bash calls, while this dispatcher only sees Agent calls, so it never logged a line. The other four agent safety checks (`block-writes`, `migration-safety-check`, `ci-safety-check`, `deployment-safety-check`) were retired in #3835.

## PostToolUse Safety

### Secret Handler

**Hook:** `posttool/secret-handler`
**Event:** PostToolUse (Read, Bash, Grep, Glob)

Scans tool output for secrets. The `ORK_SECRET_HOOK` variable picks the mode: `AUDIT` (the default) logs would-be matches and leaves the output alone, `REDACT` replaces bounded patterns in place and withholds the whole output for critical ones, and `OFF` disables it.

### Redact Secrets

**Hook:** `skill/redact-secrets`
**Event:** PostToolUse (Bash, Write|Edit)

Scans the tool output for API key shapes (OpenAI, GitHub, GitLab, AWS, Slack, Tavily, Mem0) and quoted `password=` or `secret=` assignments. On a match it writes a `::warning::` line to stderr. It runs async, never blocks, and leaves the output unchanged; in-place redaction is `posttool/secret-handler` with `ORK_SECRET_HOOK=REDACT`.

### Failure Handler

**Hook:** `posttool/failure-handler`
**Event:** PostToolUseFailure

When a tool fails, adds context with likely causes and recovery suggestions.


## Customizing Safety Hooks

### Hook Overrides

You can disable specific hooks only at user scope via `~/.claude/hook-overrides.json` (project-level `.claude/hook-overrides.json` is not read; AF-12 / #4220):

```json
{
  "disabled": [
    "pretool/Write/docstring-enforcer"
  ],
  "timeouts": {
    "pretool/bash/license-compliance": 5
  }
}
```

<Callout type="warn">
Never disable security-critical hooks. Entries in `SECURITY_HOOKS` (including the Bash / Write-Edit dispatchers) ignore overrides and warn on stderr instead.
</Callout>

### Permission Mode: dontAsk

Claude Code 2.1.25 introduced `permissionMode: 'dontAsk'` for automated workflows. When this mode is active, quality gates emit warnings instead of blocking:

```typescript
import { isDontAskMode } from './lib/guards.js';

export function myQualityGate(input: HookInput): HookResult {
  if (isDontAskMode(input)) {
    // Warn instead of block in automated mode
    return outputWarning('Code quality issue detected');
  }
  return outputBlock('Code quality issue -- fix before proceeding');
}
```

Operator deny rules always block regardless of permission mode, because Claude Code enforces them itself.

## Audit Trail

All permission decisions are logged to `~/.claude/logs/ork/permission-feedback.log`:

```
2026-01-23T10:15:30.123Z | allow | Matches safe pattern: /^git status/ | tool=Bash | session=abc123
```

The log rotates automatically at 100 KB. General hook activity is logged to `hooks.log` with rotation at 200 KB.
