Hook
agent_gate.hook
¶
The PreToolUse hook: read a payload, judge it, answer Claude Code.
Protocol: Claude Code writes one JSON object to stdin. The hook writes at
most one JSON object to stdout and always exits 0. A deny or ask
goes out as hookSpecificOutput.permissionDecision; a pass writes
nothing, which leaves the call to the normal permission flow. The gate never
writes allow.
The gate fails closed: any error while judging becomes a deny.
evaluate(payload, *, record=True, client=None)
¶
Judge one hook payload through every layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
the PreToolUse payload. |
required |
record
|
bool
|
append the verdict to the session ledger. |
True
|
client
|
Any
|
an Anthropic client for the model gate, for tests. |
None
|
Source code in src/agent_gate/hook.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
main(stdin=sys.stdin, stdout=sys.stdout)
¶
Run the hook once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stdin
|
TextIO
|
where the payload comes from. |
stdin
|
stdout
|
TextIO
|
where the decision goes. |
stdout
|
Returns:
| Type | Description |
|---|---|
int
|
the exit code, always 0. |
Source code in src/agent_gate/hook.py
67 68 69 70 71 72 73 74 75 76 77 78 79 | |
render(verdict)
¶
The hook's stdout for a verdict: a JSON object, or empty for pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verdict
|
Verdict
|
the verdict. |
required |
Source code in src/agent_gate/hook.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |