Skip to content

Permissions and Hooks

Permission System

Defined in agent-core, consumed by agent-sessions. Provides deterministic 3-step policy evaluation for tool calls.

Evaluation Algorithm

  1. Deny list — If any deny pattern matches, return deny
  2. Allow list — If any allow pattern matches, return auto (no prompt)
  3. Mode policy — Look up the tool in the mode matrix

Permission Modes

ModeReadWriteBash
planautodenydeny
defaultautoapprove (prompt)approve (prompt)
acceptEditsautoautoapprove (prompt)
bypassPermissionsautoautoauto

Pattern Syntax

Bash(pnpm *)        # Bash with command starting "pnpm "
Read(/src/**)        # Read for files under /src/
Write(*)             # Write with any argument
ToolName             # Match any invocation (no arg constraint)

Configuration

json
{
  "permissions": {
    "allow": ["Read(*)", "Glob(*)", "Grep(*)", "Bash(pnpm *)"],
    "deny": ["Bash(rm -rf *)"]
  }
}

Hook System

Shell command-based lifecycle hooks. Defined in agent-core, consumed by agent-sessions.

Events

EventTimingPurpose
PreToolUseBefore tool executionValidation, blocking
PostToolUseAfter tool executionLogging, auditing
PreCompactBefore context compactionValidation
PostCompactAfter context compactionNotification (includes summary)
SessionStartSession initializationSetup
StopSession terminationCleanup

Exit Code Protocol

CodeMeaning
0Allow / proceed
2Block / deny (stderr = reason)
otherProceed with warning

Hook Input

Hooks receive JSON via stdin:

json
{
  "session_id": "session_1234",
  "cwd": "/path/to/project",
  "hook_event_name": "PreToolUse",
  "tool_name": "Bash",
  "tool_input": { "command": "pnpm test" }
}

Configuration

json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{ "type": "command", "command": "bash .hooks/validate-bash.sh" }]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "",
        "hooks": [{ "type": "command", "command": "bash .hooks/log-tool-use.sh" }]
      }
    ]
  }
}

Hooks have a 10-second timeout. Empty matcher matches all tools.

Released under the MIT License.