Skip to main content
Hooks let you run shell commands automatically when specific agent events occur — for example, enforcing coding standards before a tool writes a file, or logging every completed turn. The system follows the same conventions as Claude Code hooks.

Configuration

Hooks are configured in JSON files at two levels:
ScopeFileManaged via
Global~/.bricks-project-desktop/hooks.jsonSettings > Agent > Hooks settings > Open
Project<project>/.bricks/hooks.jsonEdit directly
Both files are merged additively. Identical handlers (same event, matcher, and command) are deduplicated.

Config format

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "bash|write_file",
        "hooks": [
          {
            "type": "command",
            "command": "node check.js",
            "timeout": 30
          }
        ]
      }
    ]
  }
}
The top-level hooks wrapper is optional — you can place event keys at the root. Each event key maps to an array of rule objects. A rule has:
  • matcher — which tool or trigger to match (see Matchers)
  • hooks — an array of handler objects, each with:
    • type — always "command"
    • command — the shell command to run
    • timeout — per-handler timeout in seconds (default 60)

Matchers

Matchers follow Claude Code semantics:
PatternBehavior
Empty or *Matches everything
Word characters and | onlyExact pipe-separated list (e.g. bash|write_file)
Anything elseTreated as a regular expression

Events

EventMatcher valueCan blockDescription
SessionStartstartup | resumeNoFires when a session starts or resumes
UserPromptSubmitYesRuns before a user prompt is sent; can reject it
PreToolUsetool nameYesRuns before a tool call; can deny it
PostToolUsetool nameNoRuns after a tool call; can append feedback
StopNoFires when the agent finishes a turn
SubagentStartagent nameNoFires when a sub-agent spawns
SubagentStopagent nameNoFires when a sub-agent finishes
PreCompactmanual | autoNoFires before context compaction
PostCompactmanual | autoNoFires after context compaction
GoalUpdateset | evaluated | complete | cancelNoFires on goal lifecycle changes

Execution protocol

Each matching handler runs through the shell with cwd set to the project path. A JSON payload is passed on stdin containing:
  • session_id — the current session ID
  • cwd — the project path
  • hook_event_name — the event name
Plus per-event fields such as tool_name, tool_input, tool_response, prompt, trigger, agent_type, and goal. The following environment variables are set:
VariableValue
BRICKS_PROJECT_DIRProject path
BRICKS_SESSION_IDCurrent session ID
BRICKS_HOOK_EVENTEvent name

Exit codes

Exit codeBehavior
0Success — stdout may carry a JSON decision (see below)
2Block — stderr is used as the block reason
Any otherNon-blocking failure — logged and ignored
Timeouts are also treated as non-blocking failures.

Decision output

On exit code 0, stdout may contain a JSON object:
  • Block a tool call (PreToolUse): {"decision": "block", "reason": "..."}
  • Deny with reason (PreToolUse): {"hookSpecificOutput": {"permissionDecision": "deny", "permissionDecisionReason": "..."}}
  • Append feedback (PostToolUse): {"additionalContext": "..."}
All matching handlers run in parallel. If any handler blocks, the tool call or prompt is denied and all block reasons are joined.

Scope

Hooks apply across all agent contexts:
  • Main agent tool calls
  • Sub-agent tool calls (with agent_type in the payload)
  • GUI tool calls
  • ACP tool calls
UserPromptSubmit only gates user-typed prompts — goal continuations and internal session messages are not intercepted. Hook engine failures never propagate into the agent loop.

Examples

Require a linter check before file writes

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "write_file",
        "hooks": [
          {
            "type": "command",
            "command": "node scripts/lint-check.js"
          }
        ]
      }
    ]
  }
}

Log every completed turn

{
  "hooks": {
    "Stop": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "echo \"Turn completed\" >> /tmp/ctor-events.log"
          }
        ]
      }
    ]
  }
}

Data storage

DataLocation
Global hooks config~/.bricks-project-desktop/hooks.json
Project hooks config<project>/.bricks/hooks.json