Use native CLI hooks
Run your code when a CLI starts, calls a tool or finishes.
Attach a callback to your CLI’s lifecycle to inspect or control its actions. Start with a configured agent. The Outpost loop has separate hooks.
Refuse a tool call
Section titled “Refuse a tool call”This Claude hook refuses Bash calls and asks the agent to use file-reading tools. Pass harness to createAgent({ harness }), then dispatch the agent.
The callback runs on the host. It receives the native event, a borrowed sandbox and an abort signal. Returning nothing leaves the action unchanged; returning a decision applies that CLI’s rules.
Native event inventory
Section titled “Native event inventory”Each CLI has its own factory, event names and decisions. The API lists all 85 exposed events and links to their native documentation.
| CLI | Declare a hook | Available events |
|---|---|---|
| Claude Code | defineClaudeHook | ClaudeHookPhase |
| Codex | defineCodexHook | CodexHookPhase |
| Copilot CLI | defineCopilotHook | CopilotHookPhase |
| Kimi Code | defineKimiHook | KimiHookPhase |
| Antigravity | defineAntigravityHook | AntigravityHookPhase |
Execution and configuration
Section titled “Execution and configuration”- Callbacks need Node.js and a sandbox with
liveInput. An invalid decision or callback error fails the turn. Honorsignalfor host work. - Use
command: { executable: "node", arguments: ["scripts/check-hook.mjs"] }instead ofrunfor an existing script. It receives native JSON on stdin and follows the CLI’s stdout and exit-code rules. - Outpost installs and removes its hook declarations around each CLI process. Ordering and matching remain native; existing hooks are preserved.
To share these hooks, declare them in defineAgentProfile({ hooks }). The harness selects its profile section before appending local hooks.
Run the example
Section titled “Run the example”After building the package, run node examples/74-lifecycle-hooks/index.ts claude from the repository. The complete example supports all five CLIs and explains the required account login and Docker image.

