@@ -15,6 +15,7 @@ Session hooks allow you to intercept and modify tool execution, user prompts, an
1515| [ User Prompt Submitted] ( #User_Prompt_Submitted_Hook ) | When user sends a message | Nothing (observation only) |
1616| [ Session Start] ( #Session_Start_Hook ) | When session begins | Nothing (observation only) |
1717| [ Session End] ( #Session_End_Hook ) | When session ends | Nothing (observation only) |
18+ | [ Checking Whether Hooks Are Registered] ( #Checking_Whether_Hooks_Are_Registered ) | Before session creation | Whether any handlers are configured |
1819
1920---
2021
@@ -133,7 +134,7 @@ Called **after** a tool executes. Use this to:
133134| -------| ------| -------------|
134135| ` getToolName() ` | ` String ` | Name of the tool that was called |
135136| ` getToolArgs() ` | ` JsonNode ` | Arguments that were passed |
136- | ` getToolResult() ` | ` String ` | Result from the tool |
137+ | ` getToolResult() ` | ` JsonNode ` | Result from the tool |
137138| ` getCwd() ` | ` String ` | Current working directory |
138139| ` getTimestamp() ` | ` long ` | Timestamp in milliseconds |
139140
@@ -188,7 +189,7 @@ Called when the user submits a prompt, before the LLM processes it. This is an o
188189
189190| Field | Type | Description |
190191| -------| ------| -------------|
191- | ` getPrompt ()` | ` String ` | The user's prompt text |
192+ | ` prompt ()` | ` String ` | The user's prompt text |
192193| ` getTimestamp() ` | ` long ` | Timestamp in milliseconds |
193194
194195### Output
@@ -222,7 +223,7 @@ Called when a session starts (either new or resumed).
222223
223224| Field | Type | Description |
224225| -------| ------| -------------|
225- | ` getSource ()` | ` String ` | ` "new" ` or ` "resumed " ` |
226+ | ` source ()` | ` String ` | ` "startup" ` , ` "resume" ` , or ` "new " ` |
226227| ` getTimestamp() ` | ` long ` | Timestamp in milliseconds |
227228
228229### Output
@@ -254,7 +255,7 @@ Called when a session ends.
254255
255256| Field | Type | Description |
256257| -------| ------| -------------|
257- | ` getReason ()` | ` String ` | Why the session ended |
258+ | ` reason ()` | ` String ` | Why the session ended |
258259| ` getTimestamp() ` | ` long ` | Timestamp in milliseconds |
259260
260261### Output
@@ -358,6 +359,22 @@ All hook handlers receive a `HookInvocation` object as the second parameter:
358359
359360This allows you to correlate hooks with specific sessions when managing multiple concurrent sessions.
360361
362+ ## Checking Whether Hooks Are Registered
363+
364+ Use ` hasHooks() ` to quickly verify that at least one hook handler is configured:
365+
366+ ``` java
367+ var hooks = new SessionHooks ()
368+ .setOnPreToolUse((input, invocation) - >
369+ CompletableFuture . completedFuture(PreToolUseHookOutput . allow()));
370+
371+ if (hooks. hasHooks()) {
372+ var session = client. createSession(
373+ new SessionConfig (). setHooks(hooks)
374+ ). get();
375+ }
376+ ```
377+
361378---
362379
363380## Error Handling
0 commit comments