agentctl integrates with Claude Code through a PreToolUse hook. The recommended setup is agentctl attach claude-code, which bootstraps ~/.agentctl/ and updates ~/.claude/settings.json for you.
go install github.com/chocks/agentctl/cmd/agentctl@latest
agentctl attach claude-code
agentctl doctorattach does two things:
- Creates
~/.agentctl/and writes a defaultpolicy.yamlif needed. - Adds
agentctl hook claude-codeto Claude Code'sPreToolUsehooks.
The Claude Code hook adapter maps these tools into agentctl actions:
BashWriteEditMultiEditWebFetch
Before the tool call runs, Claude Code invokes agentctl hook claude-code with the hook event on stdin. agentctl evaluates policy, records a trace, and exits:
| Exit code | Meaning |
|---|---|
0 |
Allow |
2 |
Deny or escalate; Claude Code shows the reason |
If the global policy file exists but is malformed, the hook fails open and writes the error to stderr. This keeps a bad YAML edit from blocking every tool call.
Claude Code uses the same global policy file as every other integration:
~/.agentctl/policy.yaml
There is no repo-local override.
Recent traces and approvals live at:
~/.agentctl/traces.jsonl
~/.agentctl/approvals.jsonl
If you do not want to use attach, add this to ~/.claude/settings.json yourself:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash|Write|Edit|MultiEdit|WebFetch",
"hooks": [
{
"type": "command",
"command": "agentctl hook claude-code"
}
]
}
]
}
}agentctl trace list --last 20
agentctl trace search --session <session_id>
agentctl approval list --status pending
agentctl approval approve <approval_id> --by alice
agentctl uiHook (agentctl hook claude-code) |
MCP (agentctl mcp) |
|
|---|---|---|
| Intercepts | Native Claude Code tool calls automatically | Only explicit agentctl_* tool calls |
| Setup | attach claude-code or manual hook entry |
Manual mcpServers entry |
| Best for | Transparent enforcement | Opt-in gating from prompts or agent code |
See docs/mcp.md for MCP usage and Codex setup.