Goal
Let AgentKeys participate in the LLM host's lifecycle via the host's native hook system — without modifying the host. Targets the Phase 3 / M3 multi-runtime story (Hermes, OpenClaw, Doubao, Claude Code, Codex/ChatGPT all invoke the same AgentKeys MCP tools under their own runtime control).
This is the complement to the MCP tools we shipped in Phase 1 (memory.get, permission.check, audit.append, …). Tools are LLM-invoked on demand; hooks are runtime-invoked at lifecycle events. Both directions matter:
| Direction |
Trigger |
AgentKeys role |
| Host → AgentKeys (most useful) |
Host's lifecycle hook fires (pre-tool, post-tool, stop, session-end) |
AgentKeys tool gets called as the hook body |
| AgentKeys → Host (later) |
permission.check denies, cap.revoke fires |
Hook fires in the host to update its UI / refuse the user / clear context |
Why this matters
Today the LLM has to decide to call our tools. That works for memory queries but is wrong for guardrails — the LLM shouldn't be free to skip a permission.check before a payment, and shouldn't be free to skip audit.append after sensitive tool use. Hooks move those guarantees out of LLM discretion and into the runtime.
Concrete patterns this unlocks:
- Pre-payment gate. Claude Code
PreToolUse hook for any tool whose name matches *pay*|*order*|*purchase* → call agentkeys.permission.check → block the tool call if verdict=deny. The LLM physically cannot bypass.
- Auto-audit.
PostToolUse hook → agentkeys.audit.append with the tool name, params hash, and result. Every tool use lands in the off-chain audit feed without LLM cooperation.
- Session summary.
Stop hook → agentkeys.memory.put(namespace=profile, content=…) to roll up what the user agreed to / learned / changed during the session.
- Cross-runtime parity. Same hook contract exposed for Codex/ChatGPT, Cursor, future agents. The runtime's lifecycle vocabulary differs, but the AgentKeys tool surface is the same.
Phase 3 scope (proposed)
Out of scope (defer to M4)
- Full delegation-chain hooks (parent-agent → child-agent lifecycle binding)
- Real-time UI push when a hook denies (parent app notification)
- Cross-host hook portability spec (a vendor-neutral hook standard)
References
Goal
Let AgentKeys participate in the LLM host's lifecycle via the host's native hook system — without modifying the host. Targets the Phase 3 / M3 multi-runtime story (Hermes, OpenClaw, Doubao, Claude Code, Codex/ChatGPT all invoke the same AgentKeys MCP tools under their own runtime control).
This is the complement to the MCP tools we shipped in Phase 1 (
memory.get,permission.check,audit.append, …). Tools are LLM-invoked on demand; hooks are runtime-invoked at lifecycle events. Both directions matter:permission.checkdenies,cap.revokefiresWhy this matters
Today the LLM has to decide to call our tools. That works for memory queries but is wrong for guardrails — the LLM shouldn't be free to skip a
permission.checkbefore a payment, and shouldn't be free to skipaudit.appendafter sensitive tool use. Hooks move those guarantees out of LLM discretion and into the runtime.Concrete patterns this unlocks:
PreToolUsehook for any tool whose name matches*pay*|*order*|*purchase*→ callagentkeys.permission.check→ block the tool call if verdict=deny. The LLM physically cannot bypass.PostToolUsehook →agentkeys.audit.appendwith the tool name, params hash, and result. Every tool use lands in the off-chain audit feed without LLM cooperation.Stophook →agentkeys.memory.put(namespace=profile, content=…)to roll up what the user agreed to / learned / changed during the session.Phase 3 scope (proposed)
docs/wiki/showing PreToolUse / PostToolUse / Stop wired to AgentKeys MCP tools. Operator copies into their~/.claude/settings.json(Claude Code) or equivalent.agentkeys hook checkCLI helper — wraps the host's hook stdin/stdout JSON convention. Operator just writescommand: 'agentkeys hook check --scope payment.spend'in their settings; we handle the JSON parsing + MCP call + return the right block/allow shape.Out of scope (defer to M4)
References
claude --help→ settings → hooks (PreToolUse, PostToolUse, Stop, etc.)docs/spec/plans/milestones-roadmap.md§M3 — multi-runtime parity is the umbrella goal