Skip to main content
What’s New β†’ What’s new in 0.6.4: Built on Spring AI 2.0.0 GA and Spring Boot 4.0.7, with an OWASP CVE gate added to the build. The prior 0.6.3 release migrated onto the new Claude SDK and aligned on the Jackson 2.21.2 BOM. The hook-API architecture β€” core plus the Spring AI, Claude, and Gemini adapters β€” is unchanged. Every agent framework implements hooks differently. Claude Code has shell-based hooks. Strands has steering callbacks. Spring AI has advisors. Your safety policy, logging, and steering logic gets rewritten for each one. Agent Hooks is a portable Java API that lets you write hook logic once and run it on any runtime that has an adapter. The core module has zero dependencies β€” it defines the event model, decision types, and registry. Adapters (Spring AI, Claude Agent SDK, and Gemini CLI) wire the core into their runtime’s tool-call lifecycle. Your hooks move with you when your agent infrastructure changes.

Why Hooks

LLMs are probabilistic β€” prompt-based instructions drift under token pressure. Agents skip steps, forget constraints, and ignore guardrails. Hooks solve this by moving critical logic out of the prompt and into deterministic code that intercepts every tool call, the same way servlet filters intercept HTTP requests:
  • Safety β€” Block dangerous operations before they execute. A Block decision short-circuits immediately and cannot be overridden by later hooks.
  • Observability β€” Log every tool call, capture timing data, and feed traces into Agent Journal for behavioral analysis.
  • Steering β€” Modify tool inputs in flight. Subsequent hooks see the modified input, so transformations chain cleanly.

How It Works

Hooks intercept at two points in the tool-call lifecycle:
Register hooks with type-safe generics and optional tool-name filtering:

Decision Model

HookDecision is a sealed type with four variants: Multiple hooks execute in priority order (default: 100, lower = earlier). AfterToolCall hooks fire in reverse priority order for proper cleanup semantics.

Modules

Event Hierarchy

The event system is open (unsealed) β€” you can define custom events for your runtime:

Quick Start

Write Once, Run Anywhere

The same AgentHookProvider works on all three runtimes β€” this is the core value proposition.
Spring AI β€” register as a @Component bean, auto-configuration handles the rest:
Claude Agent SDK β€” bridge into the Claude HookRegistry:
The bridge registers callbacks for all six Claude hook events (PreToolUse, PostToolUse, UserPromptSubmit, Stop, SubagentStop, PreCompact). It converts Claude SDK types to core events, dispatches through your hooks, and maps decisions back to Claude’s HookOutput. Tool call duration is tracked via wall-clock timing across the pre/post hook boundary. Each Claude session gets its own HookContext for isolated state and history. Gemini CLI β€” stateless subprocess dispatcher reads JSON from stdin:
Gemini CLI spawns the hook process per event. The dispatcher maps all 11 Gemini events to core and Gemini-specific HookEvent records. HookContext is fresh per invocation β€” stateless hooks (security gates, audit logging) work out of the box. Note: Gemini BeforeTool can only allow or block β€” Modify is downgraded to allow with a warning.

Documentation

Source Code

Core API, Spring AI adapter, Claude adapter, and Gemini adapter

Design Notes

Architecture decisions, event hierarchy, dispatch semantics

Used By

  • Agent Workflow β€” hooks apply automatically to any workflow step that invokes tools
  • Agent Journal β€” hook provider that logs tool-call events to a journal Run