trading_agent.backends.claude_tool_allowlist_hook
¶
A PreToolUse hook that lets Claude Code run only trading-agent's own tools.
Claude Code's built-in tools are already switched off with tools=[]. This hook is a second lock: if a later Claude Code version, a plugin or a setting ever offered another tool, the call would still be refused. Claude Code's own Bash in particular would bypass the bwrap sandbox and the risk engine.
Typical usage example:
hook = ClaudeToolAllowlistHook(['mcp__trading_agent__get_time']) hooks = {'PreToolUse': [claude_agent_sdk.HookMatcher(hooks=[hook])]}
ClaudeToolAllowlistHook
¶
Refuses every tool call whose name is not on the allow list.
Creates the hook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allowed_tool_names
|
Sequence[str]
|
The tool names Claude may call, as Claude Code names them. |
required |
Source code in src/trading_agent/backends/claude_tool_allowlist_hook.py
__call__
async
¶
Decides whether one tool call may run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook_input
|
dict[str, Any]
|
The hook's input from Claude Code, including tool_name. |
required |
tool_use_id
|
str | None
|
The call's identifier, unused. |
required |
context
|
Any
|
The hook context, unused. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
An empty dict to allow the call, or a PreToolUse deny decision. |