Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
target
examples-test/
.merge-env
blog-copilotsdk/
17 changes: 17 additions & 0 deletions src/site/markdown/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This guide covers common use cases for the Copilot SDK for Java. For complete AP
- [Message Delivery Mode](#Message_Delivery_Mode)
- [Session Management](#Session_Management)
- [SessionConfig Reference](#SessionConfig_Reference)
- [Cloning SessionConfig](#Cloning_SessionConfig)

---

Expand Down Expand Up @@ -167,6 +168,7 @@ The SDK supports event types organized by category. All events extend `AbstractS
| `SessionUsageInfoEvent` | `session.usage_info` | Token usage information |
| `SessionCompactionStartEvent` | `session.compaction_start` | Context compaction started (infinite sessions) |
| `SessionCompactionCompleteEvent` | `session.compaction_complete` | Context compaction completed |
| `SessionContextChangedEvent` | `session.context_changed` | Working directory context changed |

### Assistant Events

Expand Down Expand Up @@ -645,6 +647,21 @@ Complete list of all `SessionConfig` options for `createSession()`:
| `disabledSkills` | List<String> | Skills to disable by name | [Skills](advanced.html#Skills_Configuration) |
| `configDir` | String | Custom configuration directory | [Config Dir](advanced.html#Custom_Configuration_Directory) |

### Cloning SessionConfig

Use `clone()` to copy a base configuration before making per-session changes:

```java
var base = new SessionConfig()
.setModel("gpt-4.1")
.setStreaming(true);

var derived = base.clone()
.setWorkingDirectory("/repo-a");
```

`clone()` creates a shallow copy. Collection fields are copied into new collection instances, while nested objects/handlers are shared references.

See [SessionConfig](apidocs/com/github/copilot/sdk/json/SessionConfig.html) Javadoc for full details.

---
Expand Down
25 changes: 21 additions & 4 deletions src/site/markdown/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Session hooks allow you to intercept and modify tool execution, user prompts, an
| [User Prompt Submitted](#User_Prompt_Submitted_Hook) | When user sends a message | Nothing (observation only) |
| [Session Start](#Session_Start_Hook) | When session begins | Nothing (observation only) |
| [Session End](#Session_End_Hook) | When session ends | Nothing (observation only) |
| [Checking Whether Hooks Are Registered](#Checking_Whether_Hooks_Are_Registered) | Before session creation | Whether any handlers are configured |

---

Expand Down Expand Up @@ -133,7 +134,7 @@ Called **after** a tool executes. Use this to:
|-------|------|-------------|
| `getToolName()` | `String` | Name of the tool that was called |
| `getToolArgs()` | `JsonNode` | Arguments that were passed |
| `getToolResult()` | `String` | Result from the tool |
| `getToolResult()` | `JsonNode` | Result from the tool |
| `getCwd()` | `String` | Current working directory |
| `getTimestamp()` | `long` | Timestamp in milliseconds |

Expand Down Expand Up @@ -188,7 +189,7 @@ Called when the user submits a prompt, before the LLM processes it. This is an o

| Field | Type | Description |
|-------|------|-------------|
| `getPrompt()` | `String` | The user's prompt text |
| `prompt()` | `String` | The user's prompt text |
| `getTimestamp()` | `long` | Timestamp in milliseconds |

### Output
Expand Down Expand Up @@ -222,7 +223,7 @@ Called when a session starts (either new or resumed).

| Field | Type | Description |
|-------|------|-------------|
| `getSource()` | `String` | `"new"` or `"resumed"` |
| `source()` | `String` | `"startup"`, `"resume"`, or `"new"` |
| `getTimestamp()` | `long` | Timestamp in milliseconds |

### Output
Expand Down Expand Up @@ -254,7 +255,7 @@ Called when a session ends.

| Field | Type | Description |
|-------|------|-------------|
| `getReason()` | `String` | Why the session ended |
| `reason()` | `String` | Why the session ended |
| `getTimestamp()` | `long` | Timestamp in milliseconds |

### Output
Expand Down Expand Up @@ -358,6 +359,22 @@ All hook handlers receive a `HookInvocation` object as the second parameter:

This allows you to correlate hooks with specific sessions when managing multiple concurrent sessions.

## Checking Whether Hooks Are Registered

Use `hasHooks()` to quickly verify that at least one hook handler is configured:

```java
var hooks = new SessionHooks()
.setOnPreToolUse((input, invocation) ->
CompletableFuture.completedFuture(PreToolUseHookOutput.allow()));

if (hooks.hasHooks()) {
var session = client.createSession(
new SessionConfig().setHooks(hooks)
).get();
}
```

---

## Error Handling
Expand Down
Loading