Skip to content

Claude Code hook ​

aithorized-hook is a Claude Code PreToolUse hook. Before a tool runs, Claude Code hands it the call; the hook checks your policy, waits for a signed approval when a rule says so, and answers allow or deny. It never runs the tool itself.

Install ​

In the project (no global permissions needed), once published (private beta):

bash
npm install -D @aithorized/hook

The command is then npx --no-install aithorized-hook claude-code (--no-install never downloads anything at run time). Installed globally (npm install -g @aithorized/hook), it is aithorized-hook claude-code.

Configure ​

Add the hook to your Claude Code settings (.claude/settings.json in a project, or your user settings):

json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash|mcp__.*",
        "hooks": [{ "type": "command", "command": "npx --no-install aithorized-hook claude-code", "timeout": 3660 }]
      }
    ]
  },
  "permissions": {
    "deny": ["Edit(.claude/settings*.json)", "Write(.claude/settings*.json)", "Bash(*settings*.json*)"]
  }
}
  • matcher chooses which tools go through aithorized. Bash|mcp__.* (balanced) guards execution and external tools without asking you about every file edit; Bash|Write|Edit|mcp__.* (strict) adds edits, best once your policy auto-approves the routine calls. Keep Bash in either.
  • timeout (seconds) must be above the longest approval wait your policy allows (ttlSeconds, at most 3600). Claude Code cancels a hook at its timeout and then runs the call.
  • permissions.deny stops the agent from editing the hook away. For more, make the file read-only (chmod 444 .claude/settings.json).

The hook reads the same environment as the MCP proxy: AITHORIZED_AGENT_KEY, AITHORIZED_AGENT_ID, AITHORIZED_TENANT_ID, AITHORIZED_POLICY_KEY, and optionally AITHORIZED_BASE_URL, AITHORIZED_ENVIRONMENT, AITHORIZED_SESSION_ID and AITHORIZED_TOOLS_JSON. Set them in the environment Claude Code starts in. Copy them from Agents → Connect an agent in the dashboard.

Tool names in your policy ​

The hook uses Claude Code's tool name as the action: Bash, Write, Edit, WebFetch, or mcp__<server>__<tool> for MCP tools. Policy rules can look at the tool's input too:

yaml
rules:
  - id: no-force-push
    match:
      tool: Bash
      args:
        command: { regex: "git\\s+push\\s+.*--force" }
    effect: DENY
  - id: shell
    match: { tool: Bash }
    effect: REQUIRE_APPROVAL
    riskLevel: MEDIUM

What Claude Code gets back ​

OutcomeHook answer
Allowed by policy, or approvedpermissionDecision: "allow" (Claude Code does not ask its own question for this call).
Approved with editsallow with updatedInput: Claude Code runs the edited input.
Rejecteddeny, with the reviewer's feedback in permissionDecisionReason, which Claude reads.
Anything else (expired, killed, frozen, suspended, denied by policy, failed verification, phone or API unreachable)deny with a fixed reason.
The hook itself fails (missing or invalid environment, unreadable payload, a crash)Exit code 2, the reason on stderr: Claude Code blocks the call.

The hook fails closed: no path through it lets a covered call run without a verified decision, as long as the timeout above covers the wait.

Because an approved call is allowed without Claude Code's own prompt, keep the matcher to the tools you want aithorized to decide on.

The policy engine, MCP proxy, SDK and hook are MIT-licensed.