FIELD GUIDE / 02

Readable policies.
Explicit tradeoffs.

Explore 30 shipped rules, understand every selector, and adapt a policy you can explain. No hidden scoring or opaque rule ordering.

SCHEMA / VERSION 1

A small policy, end to end.

These examples and policy files follow v0.3.0, with seven native adapters. Historical v0.2.0 accepts Claude Code, Codex, Hermes and Gemini CLI; it does not accept the newcursor, copilot or cowork selectors. Use the policy files bundled with your release. Earlier v0.1.0 downloads also lack gemini.

Every file has one version: 1 and a rules list. Rules are strict: unknown fields, duplicate IDs, invalid regexes, and selector-free entries are errors.

Example · direct file-tool policy
version: 1
rules:
  - id: protect-env-files
    description: Check direct file tools targeting .env files.
    agents: [claude, codex, hermes, gemini, cursor, copilot, cowork]
    tool_pattern: '^(Read|Write|Edit|read_file|write_file|replace|view|create|edit|str_replace_editor)$'
    path_pattern: '(?i)(^|/)\.env(\.[^/]*)?$'
    action: block

This example requires both a listed agent and a matching tool and path. A direct Read of /work/.env.local matches; /work/env.example does not. A shell command needs a separate shell-scoped content rule. Gemini usesread_file, write_file, replace, and run_shell_command in the relevant selectors. Direct path rules cover the file tools' native file_patharguments. They do not interpret or expand read_many_filesinclude globs; that tool is outside this direct-file coverage.

Rule fields
FieldUseMeaning
idRequiredUnique stable identifier recorded in matched_rules. Use a nonempty identifier of at most 64 ASCII letters, digits, underscores, periods, colons, or hyphens; no sensitive text.
descriptionOptionalHuman-readable explanation, up to 2,048 bytes.
agentsSelectorv0.3.0: nonempty list of claude, codex, hermes, gemini, cursor, copilot, or cowork. Historical v0.2.0 accepts the first four. Entries within the list are alternatives.
eventsSelectorNonempty list of exact native event names, such as PreToolUse, preToolUse, pre_tool_call, or BeforeTool. Names are case-sensitive.
tool_patternSelectorRust regex over the native tool name. Anchor it when you intend an exact tool match.
path_patternSelectorRust regex over recognized native path fields, after lexical normalization. It does not parse embedded shell/patch text into paths.
content_patternSelectorRust regex over original callback JSON and string values, before redaction. It works even when content capture is off.
actionRequiredblock or audit. There is no allow action, approval action, or first-match priority.

At least one selector is required. An absent selector adds no restriction. Present selectors combine with AND; entries inside agents or events are alternatives. A path match and a content match need not refer to the same nested value.

DECISIONS / NO ALLOW OVERRIDE

A match is only half the story.

allow

No block match

No rules match, or only audit rules match. Audit IDs remain in the event; the agent's own permissions still apply.

block

Supported pre-tool event

A block rule matches an enforceable callback. AI Lens returns the vendor's denial response.

would_block

Observational callback

A block rule matches a post-tool or other observe-only event. The event is recorded; no action is reversed.

Every matching rule contributes its ID. Any block match wins over audit, regardless of list order. Keep events absent to observe the same rule before and after tools; use exact event names when restricting its scope.

Claude/Codex support preventive PreToolUse and PermissionRequest in this project; Hermes supports pre_tool_call. Gemini CLI supports only BeforeTool; its other eight registered events return neutral responses. Cursor and Copilot CLI enforce onlypreToolUse, and Cowork only PreToolUse. Copilot command timeouts fail open; Cowork Desktop execution remains unvalidated. OTLP and provider audit ingestion never evaluate these rules. Unknown hook events are rejected. A known event name alone does not guarantee that your installed client invokes or honors it.

CATALOG / 30 RULES · 6 POLICY FILES

Choose the questions you want to ask.

Five rules live in the default policy. The other 25 are optional recipes. Selecting a pack does not automatically load the default or other packs.

Default policy · 5 rules

The essentials

View YAML

Direct .env and credential paths, shell references, a demo marker, and shell auditing.

  • protect-env-files
  • protect-shell-env
  • protect-credential-files
  • demo-marker
  • audit-shell-tools
Read the shipped policy
default.yaml
# Educational examples, not comprehensive security controls.
# No raw content is logged unless start --capture-content is explicitly used.
version: 1
rules:
  - id: protect-env-files
    description: Demonstrate protection of direct file-tool access to .env files.
    agents: [claude, codex, hermes, gemini, cursor, copilot, cowork]
    tool_pattern: '^(Read|Write|Edit|MultiEdit|read_file|write_file|replace|apply_patch|patch|view|create|edit|str_replace_editor)$'
    path_pattern: '(?i)(^|/)\.env(\.[^/]*)?$'
    action: block

  - id: protect-shell-env
    description: Best-effort detection of a literal .env name in shell input.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[^A-Za-z0-9_])\.env([^A-Za-z0-9_]|$)'
    action: block

  - id: protect-credential-files
    description: Demonstrate direct file-tool checks for common credential paths.
    tool_pattern: '^(Read|Write|Edit|MultiEdit|read_file|write_file|replace|apply_patch|patch|view|create|edit|str_replace_editor)$'
    path_pattern: '(?i)(^|/)(\.aws/credentials|id_rsa|id_ed25519)$'
    action: block

  - id: demo-marker
    description: Harmless sentinel for synthetic block demonstrations.
    content_pattern: 'AGENT_LENS_BLOCK_DEMO'
    action: block

  - id: audit-shell-tools
    description: Record shell-tool rule matches while allowing the tool call.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    action: audit
Optional pack · 5 rules

Credential stores

View YAML

Common cloud, Kubernetes, registry, Git, and SSH credential paths.

  • cred-cloud-stores
  • cred-kube-config
  • cred-package-vcs-stores
  • cred-ssh-private-keys
  • cred-shell-store-references
Read the shipped policy
credential-stores.yaml
# OPTIONAL: direct credential-store checks plus shell-reference visibility.
# Legitimate authenticated workflows can match. Review before enabling blocks.
version: 1
rules:
  - id: cred-cloud-stores
    description: Direct file-tool access to common AWS, Azure, and gcloud auth stores.
    tool_pattern: '(?i)^(read|write|edit|multiedit|read_file|write_file|edit_file|replace|apply_patch|patch|view|create|str_replace_editor)$'
    path_pattern: '(?i)(^|/)(\.aws/(credentials|config)|\.azure/(accessTokens\.json|msal_token_cache\.(json|bin))|gcloud/(application_default_credentials\.json|credentials\.db|access_tokens\.db))$'
    action: block

  - id: cred-kube-config
    description: Direct file-tool access to the default Kubernetes client configuration.
    tool_pattern: '(?i)^(read|write|edit|multiedit|read_file|write_file|edit_file|replace|apply_patch|patch|view|create|str_replace_editor)$'
    path_pattern: '(?i)(^|/)\.kube/config$'
    action: block

  - id: cred-package-vcs-stores
    description: Direct file-tool access to common package, registry, and Git auth files.
    tool_pattern: '(?i)^(read|write|edit|multiedit|read_file|write_file|edit_file|replace|apply_patch|patch|view|create|str_replace_editor)$'
    path_pattern: '(?i)(^|/)(\.docker/config\.json|\.npmrc|\.pypirc|\.git-credentials|\.netrc|_netrc|gh/hosts\.ya?ml)$'
    action: block

  - id: cred-ssh-private-keys
    description: Direct file-tool access to default SSH private-key filenames.
    tool_pattern: '(?i)^(read|write|edit|multiedit|read_file|write_file|edit_file|replace|apply_patch|patch|view|create|str_replace_editor)$'
    path_pattern: '(?i)(^|/)\.ssh/id_(rsa|dsa|ecdsa|ed25519)$'
    action: block

  - id: cred-shell-store-references
    description: Audit literal shell references to the illustrated credential stores.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[^A-Za-z0-9_])(\.aws[/\\](credentials|config)|\.azure[/\\](accessTokens\.json|msal_token_cache\.(json|bin))|gcloud[/\\](application_default_credentials\.json|credentials\.db|access_tokens\.db)|\.kube[/\\]config|\.docker[/\\]config\.json|\.npmrc|\.pypirc|\.git-credentials|\.netrc|_netrc|gh[/\\]hosts\.ya?ml|\.ssh[/\\]id_(rsa|dsa|ecdsa|ed25519))([^A-Za-z0-9_.-]|$)'
    action: audit
Optional pack · 6 rules

Destructive operations

View YAML

Explicit root deletion, hard resets, forced cleans and pushes, and raw-disk writes.

  • destructive-root-delete
  • destructive-powershell-root-delete
  • destructive-git-hard-reset
  • destructive-git-clean-force
  • destructive-git-force-push
  • destructive-raw-disk-write
Read the shipped policy
destructive-operations.yaml
# OPTIONAL: narrow examples of destructive command forms, not a shell parser.
# Commands in comments/quoted strings can match; do not execute test examples.
version: 1
rules:
  - id: destructive-root-delete
    description: Block common recursive force-delete forms targeting root or home.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[;&|]\s*)(sudo\s+)?(/bin/)?rm\s+(-rf|-fr)\s+(/(\*)?|~)(\s|$)'
    action: block

  - id: destructive-powershell-root-delete
    description: Block explicit recursive forced removal of a Windows drive root.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[;&|]\s*)(Remove-Item|ri|del)\s+(-Recurse\s+-Force|-Force\s+-Recurse)\s+(-Path\s+|-LiteralPath\s+)?["'']?[A-Z]:[/\\]\*?["'']?(\s|$)'
    action: block

  - id: destructive-git-hard-reset
    description: Block the literal git reset --hard command form.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[;&|]\s*)git\s+reset\s+--hard(\s|$)'
    action: block

  - id: destructive-git-clean-force
    description: Block git clean with a force flag in the first option group.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[;&|]\s*)git\s+clean\s+(-[A-Za-z]*f[A-Za-z]*|--force)(\s|$)'
    action: block

  - id: destructive-git-force-push
    description: Block raw -f or --force git push flags, excluding --force-with-lease.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[;&|]\s*)git\s+push(\s+[^;\r\n ]+){0,4}\s+(-f|--force)(\s|$)'
    action: block

  - id: destructive-raw-disk-write
    description: Block literal dd outputs or mkfs targets on common Linux disk devices.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[;&|]\s*)(sudo\s+)?(dd\s+[^;\r\n]{0,192}\bof=["'']?/dev/(sd[a-z]|vd[a-z]|xvd[a-z]|nvme[0-9]+n[0-9]+|mmcblk[0-9]+)(p?[0-9]+)?(["'']|\s|$)|mkfs(\.[a-z0-9]+)?\s+(-[a-z0-9]+\s+){0,3}/dev/(sd[a-z]|vd[a-z]|xvd[a-z]|nvme[0-9]+n[0-9]+|mmcblk[0-9]+)(p?[0-9]+)?(\s|$))'
    action: block
Optional pack · 5 rules

Execution & network

View YAML

Download-to-shell pipelines, uploads, remote access, and permission changes.

  • exec-remote-pipe-shell
  • exec-outbound-upload
  • exec-ssh-scp
  • exec-privileged-command
  • exec-permission-changes
Read the shipped policy
execution-and-network.yaml
# OPTIONAL: block an explicit download-to-shell form; audit broader operations.
# These text matches neither inspect packages nor observe actual network traffic.
version: 1
rules:
  - id: exec-remote-pipe-shell
    description: Block a literal HTTP curl/wget download piped directly to a shell.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[;&|]\s*)(curl|wget)\s+[^;\r\n|]{0,96}https?://[^;\r\n|]{1,96}\|\s*(sudo\s+)?(sh|bash|zsh|pwsh|powershell)(\s|$)'
    action: block

  - id: exec-outbound-upload
    description: Audit curl upload/body flags and wget post-file references.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[;&|]\s*)(curl\s+[^;\r\n]{0,96}(-T|--upload-file|-F|--form|--data-binary|--data|-d)([=\s]|$)|wget\s+[^;\r\n]{0,96}--post-file([=\s]|$))'
    action: audit

  - id: exec-ssh-scp
    description: Audit common remote login, copy, and synchronization command names.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[;&|]\s*)(/usr/bin/)?(ssh|scp|sftp|rsync)\s+'
    action: audit

  - id: exec-privileged-command
    description: Audit sudo/doas/runas and an explicit PowerShell RunAs verb.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)((^|[;&|]\s*)(sudo|doas|runas)(\s|$)|(^|[;&|]\s*)Start-Process\s+[^;\r\n]{0,160}-Verb\s+RunAs(\s|$))'
    action: audit

  - id: exec-permission-changes
    description: Audit common filesystem permission and ownership command names.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[;&|]\s*)(sudo\s+)?(chmod|chown|chgrp|icacls|Set-Acl)(\s|$)'
    action: audit
Optional pack · 5 rules

Configuration integrity

View YAML

Illustrated agent settings, instructions, hook files, and AI Lens policy writes.

  • integrity-agent-config-write
  • integrity-instructions-write
  • integrity-policy-write
  • integrity-engine-binary-write
  • integrity-shell-config-references
Read the shipped policy
agent-config-integrity.yaml
# OPTIONAL: protect illustrated direct configuration writes; audit instructions.
# These files remain writable outside hooked tools; this is not tamper resistance.
version: 1
rules:
  - id: integrity-agent-config-write
    description: Block direct writes to illustrated agent settings, hooks, and plugins.
    tool_pattern: '(?i)^(write|edit|multiedit|write_file|edit_file|replace|apply_patch|patch|create|str_replace_editor)$'
    path_pattern: '(?i)(^|/)(\.claude/(settings(\.local)?\.json|hooks/.+)|\.codex/(config\.toml|hooks\.json|hooks/.+)|\.gemini/(settings\.json|hooks/.+)|\.cursor/hooks\.json|\.github/hooks/[^/]+\.json|\.copilot/(config\.json|hooks/[^/]+\.json)|\.hermes/(config\.ya?ml|hooks/.+|plugins/.+))$'
    action: block

  - id: integrity-instructions-write
    description: Audit direct edits to common agent instruction and personality files.
    tool_pattern: '(?i)^(write|edit|multiedit|write_file|edit_file|replace|apply_patch|patch|create|str_replace_editor)$'
    path_pattern: '(?i)(^|/)(AGENTS(\.override)?\.md|CLAUDE\.md|GEMINI\.md|SOUL\.md|\.claude/rules/.+\.md)$'
    action: audit

  - id: integrity-policy-write
    description: Block direct writes to default Lens state and illustrated policy paths.
    tool_pattern: '(?i)^(write|edit|multiedit|write_file|edit_file|replace|apply_patch|patch|create|str_replace_editor)$'
    path_pattern: '(?i)(^|/)(\.agent-lens/(config\.json|control\.lock)|examples/rules/[^/]+\.ya?ml|agent-lens(-rules|-policy)?\.ya?ml)$'
    action: block

  - id: integrity-engine-binary-write
    description: Block direct writes to the named Lens executable and engine library.
    tool_pattern: '(?i)^(write|edit|multiedit|write_file|edit_file|replace|apply_patch|patch|create|str_replace_editor)$'
    path_pattern: '(?i)(^|/)(agent-lens(\.exe)?|agent_lens_engine\.dll|libagent_lens_engine\.(so|dylib))$'
    action: block

  - id: integrity-shell-config-references
    description: Audit literal agent settings, instruction, and Lens policy shell references.
    tool_pattern: '(?i)^(bash|powershell|shell|terminal|exec_command|shell_command|run_command|run_shell_command)$'
    content_pattern: '(?i)(^|[^A-Za-z0-9_])(\.claude[/\\](settings(\.local)?\.json|hooks[/\\])|\.codex[/\\](config\.toml|hooks(\.json|[/\\]))|\.gemini[/\\](settings\.json|hooks[/\\])|\.cursor[/\\]hooks\.json|\.github[/\\]hooks[/\\]|\.copilot[/\\](config\.json|hooks[/\\])|\.hermes[/\\](config\.ya?ml|hooks[/\\]|plugins[/\\])|AGENTS(\.override)?\.md|CLAUDE\.md|GEMINI\.md|SOUL\.md|\.agent-lens[/\\](config\.json|control\.lock)|examples[/\\]rules[/\\]|agent-lens(-rules|-policy)?\.ya?ml)'
    action: audit
Optional pack · 4 rules

Named tool controls

View YAML

Selected MCP network, browser scripting, and delegation tool names.

  • restricted-mcp-network-tools
  • restricted-browser-tools
  • restricted-browser-script
  • restricted-delegation
Read the shipped policy
restricted-tools.yaml
# OPTIONAL: named-tool examples. Replace server/tool names with your registry.
# Tool names are callback data, not an authenticated capability boundary.
version: 1
rules:
  - id: restricted-mcp-network-tools
    description: Audit illustrated fetch/http/web MCP request and search tools.
    tool_pattern: '^(MCP:)?mcp_{1,2}(fetch|http|web)_{1,2}(fetch|fetch_url|get|post|request|search)$'
    action: audit

  - id: restricted-browser-tools
    description: Audit illustrated browser navigation, interaction, and script tools.
    tool_pattern: '^(MCP:)?(browser|browser_navigate|browser_click|mcp_{1,2}playwright_{1,2}browser_(navigate|click|fill_form|evaluate|run_code)|mcp_{1,2}puppeteer_{1,2}puppeteer_(navigate|click|evaluate))$'
    action: audit

  - id: restricted-browser-script
    description: Block named Playwright page evaluation and browser code tools.
    tool_pattern: '^(MCP:)?mcp_{1,2}playwright_{1,2}browser_(evaluate|run_code)$'
    action: block

  - id: restricted-delegation
    description: Audit illustrated task and subagent delegation tools.
    tool_pattern: '^(MCP:)?(Task|Agent|task|spawn_agent|delegate_task|mcp_{1,2}agents_{1,2}delegate)$'
    action: audit

The full catalog documents intended hits, nearby misses, and false-positive tradeoffs for every optional rule. Broad legitimate uploads, remote access, permission changes, and delegation mostly audit; selected explicit risky forms block. Configuration-integrity patterns include.gemini/settings.json, .gemini/hooks/, andGEMINI.md.

EXTEND / ONE FILE AT A TIME

Start with an audit question.

  1. Choose a supported tool and concrete input.

    Use a synthetic request. Never use real credentials as fixtures.

  2. Write one scoped rule with a unique ID.

    For command text, include a tool selector. Begin with action: audit and inspect matched IDs before promoting to block.

  3. Merge selected entries into one file.

    Copy chosen rules list items under a single version: 1 wrapper. There is no include feature, automatic pack loading, allow override, or implicit default merge.

  4. Validate, replay, and check the real client.

    Test a hit, a nearby miss, and a post-tool match. Pair any prevention check with an allowed positive control.

Shell · validate and select
# Validate your manually combined policy
./agent-lens rules-check --rules ./my-rules.yaml

# Select it explicitly for collection
./agent-lens --state "$PWD/lens-state" start \
  --output "$PWD/events.jsonl" --rules "$PWD/my-rules.yaml"

On Windows use .\agent-lens.exe and PowerShell path variables as shown in getting started. rules-check returns valid and parsed rule_ids; it does not activate collection.

LIMITS / KNOW THE BOUNDARY

Text matching is not a sandbox.

Regex, not shell syntax

Patterns use Rust regex syntax, not globs, lookaround, or backreferences. Matches are unanchored unless you add ^/$. Use single-quoted YAML strings for literal backslashes; (?i) enables case-insensitive matching.

Lexical paths, not filesystem identity

Windows separators become / and ./.. components collapse lexically. Recognized keys include file_path, path, paths, target_file, source/destination, cwd, and workdir. Symlinks, environment expansion, custom fields, and embedded patch syntax can evade path checks.

Bounded work, incomplete coverage

Limits: 128 rules, 256 KiB of YAML, 4,096 bytes per pattern, and bounded regex compilation. Hook stdin is limited to 1 MiB. Network example regexes scan bounded 96-character segments; long options and URLs can miss.

Context without a completeness claim

Content rules can match quoted examples or unrelated callback fields. Aliases, encoded input, later scripts, renamed tools, and unhooked activity can evade them. Default content omission does not disable matching; opt-in redaction is best effort.

Prove the layer you rely on.

The repository's replay tests exercise synthetic callbacks through the real executable/library. The v0.3.0 inventory is 30 rules × 7 adapters × 3 scenarios = 630 scenarios; an inventory is not a test result. Historical v0.2.0 evidence retains its four-adapter/360-scenario count, and v0.1.0 retains its original counts. These checks do not prove live vendor registration, prevention on every tool path, or tamper resistance. Keep independent approvals and OS isolation.