Agent-readable docs index: /llms.txt. Full docs in one file: /llms-full.txt. Download /docs.zip to grep all markdown files locally.

Protecting Coding-Agent Hooks (dmint hook)

Modern AI coding agents execute their highest-impact operations—such as Bash / run_commands, file edits (Write, Edit, apply_patch, pre_write_code), file reads (Read, read_files, pre_read_code), and subagent delegation—through built-in native tools in addition to external MCP servers.
dmint hook places Dmint's deterministic policy evaluator and single-use Ed25519 human approval engine directly into the official pre-execution hook lifecycle of each coding harness, provisioning a dedicated policy file per harness (.dmint/policies/<harness>.policy.json) tailored to that harness's complete built-in tool inventory.
┌─────────────────────────────────────────────────────────────────────────┐ │ AI Coding Harness (Local / Container) │ │ (Claude Code · OpenAI Codex CLI · OpenCode · Cursor · Windsurf · Cline)│ └───────────────────────────────────┬─────────────────────────────────────┘ │ │ 1. Official Pre-Tool Hook Event ▼ ┌─────────────────────────────────────────────────────────────────────────┐ │ dmint hook run │ │ • Unpacks harness-specific envelope & de-stringifies JSON params │ │ • Inspects all batch items (multi-file apply_patch / run_commands) │ │ • Evaluates .dmint/policies/<harness>.policy.json (native + canonical) │ │ • Enforces strict precedence: DENY > APPROVAL_REQUIRED > ALLOW │ └───────────┬───────────────────────┼───────────────────────┬─────────────┘ │ │ │ ▼ ▼ ▼ [ ALLOW ] [ APPROVAL_REQUIRED ] [ DENY ] │ │ │ Exit 0 ("allow") Persists PENDING apr_... Exit 2 ("deny") Tool executes or consumes APPROVED Tool blocked assertion once

1. Supported Harnesses, Official Hook Files & Dedicated Policies

Run dmint init --harness all (or dmint hook install --harness <name>) to configure any or all supported harnesses. Each harness is wired to its own dedicated policy file in .dmint/policies/<harness>.policy.json:
HarnessFlag ValueGenerated Hook Configuration File(s)Dedicated Policy FileOfficial Hook Mechanism & Output Schema
Claude Codeclaude-code.claude/settings.json.dmint/policies/claude-code.policy.jsonhooks.PreToolUse (matcher: "*") returning hookSpecificOutput.permissionDecision ("allow" | "deny" | "ask")
OpenAI Codex CLIcodex.codex/hooks.json & .codex/dmint-hook.sh.dmint/policies/codex.policy.jsonhooks.PreToolUse (matcher: "Bash|apply_patch|mcp__.*") returning hookSpecificOutput.permissionDecision ("allow" | "deny") + exit 2 on block
OpenCodeopencode.opencode/plugins/dmint-guard.ts & .opencode/plugin/dmint-guard.ts.dmint/policies/opencode.policy.jsonNative TypeScript plugin hooking tool.execute.before (input.tool, output.args)
Cursorcursor.cursor/hooks.json ("version": 1).dmint/policies/cursor.policy.jsonpreToolUse, beforeShellExecution, beforeReadFile, beforeMCPExecution, subagentStart (failClosed: true) returning {"permission": "allow" | "deny"}
Windsurf Cascadewindsurf.windsurf/hooks.json.dmint/policies/windsurf.policy.jsonpre_run_command, pre_read_code, pre_write_code, pre_mcp_tool_use (show_output: true), blocking via exit code 2
Cline / Roo Codecline.clinerules/hooks/PreToolUse, .cline/hooks/PreToolUse.sh, .clinerules/hooks.json.dmint/policies/cline.policy.jsonExecutable PreToolUse scripts returning {"cancel": false} on allow and {"cancel": true, "errorMessage": "..."} on block

2. Per-Harness Built-In Tool Inventory

Because each coding agent ships with its own internal tools for session planning, user questions, code intelligence, and task completion, sharing a single generic policy across harnesses can accidentally default-deny harmless session tools (such as TodoWrite in Claude Code, update_plan in Codex, todowrite in OpenCode, or attempt_completion in Cline).
Dmint ships a dedicated built-in policy template (src/dmint/templates/data/<harness>.json) for every harness:
HarnessAllowed Safe Built-In Tools (ALLOW)Approval-Gated Tools (APPROVAL_REQUIRED)Strictly Blocked Targets (DENY)
Claude CodeRead, NotebookRead (workspace), Glob, Grep, LS, LSP, Agent, Task, AskUserQuestion, EnterPlanMode, ExitPlanMode, ExitWorktree, TaskCreate, TaskGet, TaskList, TaskUpdate, TaskStop, TodoRead, TodoWrite, ToolSearch, WaitForMcpServers, ListMcpResourcesTool, ReadMcpResourceTool, ListAgents, ReportFindings, SubagentHandback, SendFeedback, PushNotification, CronCreate, CronList, CronDelete, ScheduleWakeup, WebSearch, safe Bash/PowerShell (git status, pytest, npm test, ls)Edit, MultiEdit, Write, NotebookEdit (workspace), Skill, SlashCommand, Workflow, EnterWorktree, WebFetch, Artifact, ShareOnboardingGuide, RemoteTrigger, SendMessage, SendUserFile, mutating Bash (git push *, docker *, npm install *, pip install *, curl *)Destructive Bash (rm -rf /, sudo *, mkfs *, * | sh, * *.env*), reading or writing .env*, *.key, *.pem, .dmint/**, .claude/**, /etc/**
OpenAI Codex CLIread_file, Read, view_image (workspace), list_dir, grep_files, search_files, update_plan, web_search, wait, close_agent, safe Bash/exec_command/shellapply_patch, Edit, Write, write_file (workspace), spawn_agent, send_input, mutating Bash/exec_commandDestructive Bash/exec_command, reading or patching .env*, *.key, *.pem, .dmint/**, .codex/**, /etc/**
OpenCoderead (workspace), grep, glob, list, lsp, todowrite, todoread, question, websearch, safe bashedit, write, apply_patch, patch (workspace), skill, task, webfetch, mutating bashDestructive bash, reading or editing .env*, *.key, *.pem, .dmint/**, .opencode/**, /etc/**
CursorRead, beforeReadFile, beforeTabFileRead, read_file (workspace), Grep, Glob, LS, codebase_search, grep_search, file_search, list_dir, Task/subagentStart (explore, generalPurpose), safe Shell/beforeShellExecutionWrite, Edit, MultiEdit, Delete, edit_file, write_file, delete_file, search_replace (workspace), subagentStart (shell), beforeMCPExecution, mutating Shell/beforeShellExecutionDestructive Shell/beforeShellExecution, reading or writing .env*, *.key, *.pem, .dmint/**, .cursor/**, /etc/**
Windsurf Cascadepre_read_code, read_file, view_file, view_code_item (workspace), grep_search, find_by_name, list_dir, pre_user_prompt, safe pre_run_commandpre_write_code, write_to_file, replace_file_content, multi_replace_file_content (workspace), pre_mcp_tool_use, mutating pre_run_commandDestructive pre_run_command, reading or writing .env*, *.key, *.pem, .dmint/**, .windsurf/**, .devin/**, /etc/**
Cline / Roo Coderead_files, read_file (workspace), search_files, list_files, list_code_definition_names, ask_followup_question, attempt_completion, load_mcp_documentation, access_mcp_resource, safe run_commands/execute_commandeditor, write_to_file, replace_in_file, apply_patch, apply_diff, insert_content (workspace), new_task, switch_mode, browser_action, use_mcp_tool, web_fetch, web_search, mutating run_commands/execute_commandDestructive run_commands/execute_command, reading or modifying .clineignore, .clinerules/**, .cline/**, .env*, *.key, *.pem, .dmint/**, /etc/**

3. Multi-Resource & Batch Smuggling Protection

Several harnesses allow an agent to batch multiple file edits or shell commands inside a single tool call:
  • Unified Patches (apply_patch): Codex CLI, OpenCode (output.args.patchText), and Cline embed multiple file headers (*** Add File: ..., *** Update File: ..., *** Delete File: ..., *** Move to: ...) in one patch body.
  • Batch File Reads (read_files): Cline accepts {"files": [{"path": "src/app.py"}, {"path": ".env"}]}.
  • Batch Commands (run_commands): Cline accepts {"commands": ["git status", "rm -rf /"]}.
dmint hook run extracts every target file path or command in the batch, evaluates each against the harness's dedicated policy (checking both the native tool name and the normalized capability), and enforces the strictest decision (DENY > APPROVAL_REQUIRED > ALLOW). A denied file or command cannot be smuggled inside an otherwise benign batch call.

4. Single-Use Human Approvals in Hooks

When a coding agent calls a tool that matches an approval_required rule (for example, git push origin main or editing src/main.py):
  1. First Call Pauses:
    • dmint hook run creates a tamper-evident PENDING record (apr_...) in .dmint/approvals.sqlite3.
    • If Slack, Discord, or Microsoft Teams webhooks are configured (DMINT_SLACK_WEBHOOK_URL, etc.), a real-time alert is dispatched.
    • The hook outputs a clear message telling the user/agent how to approve:
      Dmint APPROVAL_REQUIRED [apr_8k9P...]: shell.execute on 'git push origin main' requires human sign-off. To approve, run: `dmint approve apr_8k9P...` (or use `dmint dashboard`), then retry.
  2. Human Approves:
    dmint approve apr_8k9P... --by alice@company.com
  3. Agent Retries the Exact Tool Call:
    • When the agent re-runs git push origin main, dmint hook run computes the RFC 8785 request fingerprint, finds the matching APPROVED assertion in .dmint/approvals.sqlite3, verifies the Ed25519 signature, atomically transitions the record from APPROVED $\to$ CONSUMED, and returns ALLOW.
    • Tamper Resistance: If the agent alters the command to git push origin main --force, the fingerprint does not match apr_8k9P... and execution is blocked.
    • Replay Protection: If the agent tries to run git push origin main a second time, the consumed assertion cannot be reused.