DEV Community

Bruno Borges
Bruno Borges

Posted on

Copilot SDK for Java 1.0.7: Session Lifecycle Hooks and Enhanced Observability

I'm excited to announce the release of Copilot SDK for Java v1.0.7, bringing powerful new capabilities for session lifecycle management, improved observability, and comprehensive documentation. This release represents a significant step forward in feature parity with the official .NET SDK, with 54 commits adding over 5,200 lines of new functionality and tests.

What's New in 1.0.7

Session Lifecycle Hooks

The most significant addition in this release is the extended hooks system. While v1.0.6 introduced pre-tool and post-tool hooks, v1.0.7 adds three new lifecycle hooks that give you fine-grained control over session behavior:

onSessionStart

Called when a session starts (whether new or resumed), this hook lets you perform initialization, logging, or validation before the session begins processing:

var config = new SessionConfig()
    .setOnSessionStart((input, invocation) -> {
        System.out.println("Session started: " + input.getSessionId());
        // Initialize session-specific resources
        return CompletableFuture.completedFuture(
            new SessionStartHookOutput()
        );
    });
Enter fullscreen mode Exit fullscreen mode

onSessionEnd

Called when a session ends, enabling cleanup operations, metrics collection, or audit logging:

.setOnSessionEnd((input, invocation) -> {
    Duration sessionDuration = calculateDuration(input);
    metricsCollector.recordSessionDuration(sessionDuration);
    return CompletableFuture.completedFuture(
        new SessionEndHookOutput()
    );
})
Enter fullscreen mode Exit fullscreen mode

onUserPromptSubmitted

Called when the user submits a prompt, allowing you to enrich, validate, or transform prompts before they're processed:

.setOnUserPromptSubmitted((input, invocation) -> {
    String enrichedPrompt = addProjectContext(input.getPrompt());
    return CompletableFuture.completedFuture(
        new UserPromptSubmittedHookOutput()
            .setUpdatedPrompt(enrichedPrompt)
    );
})
Enter fullscreen mode Exit fullscreen mode

These hooks open up powerful use cases including:

  • Security gates: Validate tool calls against allowlists before execution
  • Audit logging: Record all tool invocations for compliance
  • Result enrichment: Add metadata or transform tool outputs
  • Session analytics: Track session patterns and user behavior

Client-Level Lifecycle Events

Beyond session-scoped hooks, v1.0.7 introduces client-level lifecycle event subscriptions. This is particularly useful for applications managing multiple concurrent sessions:

// Subscribe to all lifecycle events
client.onLifecycle(event -> {
    System.out.println("Session " + event.getSessionId() + 
        " status: " + event.getType());
});

// Subscribe to specific event types
client.onLifecycle(SessionLifecycleEventTypes.CREATED, event -> {
    initializeSessionResources(event.getSessionId());
});

client.onLifecycle(SessionLifecycleEventTypes.DELETED, event -> {
    cleanupSessionResources(event.getSessionId());
});
Enter fullscreen mode Exit fullscreen mode

Available event types include:

  • CREATED — A new session was created
  • DELETED — A session was deleted
  • UPDATED — Session state was updated
  • FOREGROUND — Session moved to foreground (TUI mode)
  • BACKGROUND — Session moved to background (TUI mode)

Foreground Session Control

For applications running in TUI+Server mode (copilot --ui-server), v1.0.7 adds APIs to control which session is displayed in the terminal UI:

// Get the currently displayed session
String currentSession = client.getForegroundSessionId();

// Switch the TUI to display a different session
client.setForegroundSessionId(anotherSessionId);
Enter fullscreen mode Exit fullscreen mode

This enables building sophisticated multi-session orchestrators that can programmatically switch the TUI focus based on user activity or priority.

New Event Types

Two new event types enhance observability:

SessionShutdownEvent — Emitted when a session is shutting down, includes the reason and exit code:

session.on(SessionShutdownEvent.class, event -> {
    System.out.println("Session shutting down: " + 
        event.getData().getReason());
});
Enter fullscreen mode Exit fullscreen mode

SkillInvokedEvent — Emitted when a skill is invoked, includes the skill name and invocation context:

session.on(SkillInvokedEvent.class, event -> {
    System.out.println("Skill invoked: " + 
        event.getData().getSkillName());
});
Enter fullscreen mode Exit fullscreen mode

Extended Event Data

Several existing events now include additional fields:

Event New Fields
AssistantMessageEvent id, isLastReply, thinkingContent
AssistantUsageEvent outputReasoningTokens
SessionCompactionCompleteEvent success, messagesRemoved, tokensRemoved
SessionErrorEvent Extended error context

JaCoCo Test Coverage

This release integrates JaCoCo 0.8.14 for test coverage reporting. Coverage reports are now:

  • Generated automatically during builds at target/site/jacoco-coverage/
  • Summarized in GitHub Actions workflow summaries
  • Uploaded as CI artifacts for detailed analysis

Documentation Improvements

We've significantly expanded the documentation:

Breaking Changes

  • Copilot CLI: Minimum required version updated from 0.0.400 to 0.0.404

Getting Started

Add the dependency to your pom.xml:

<dependency>
    <groupId>com.github.copilot-community-sdk</groupId>
    <artifactId>copilot-sdk-java</artifactId>
    <version>1.0.7</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Or try it instantly with JBang:

jbang https://github.com/copilot-community-sdk/copilot-sdk-java/blob/main/jbang-example.java
Enter fullscreen mode Exit fullscreen mode

What's Next

We continue to track the official .NET SDK and port new features as they become available. Upcoming priorities include:

  • Additional MCP server integrations
  • Enhanced error recovery patterns
  • Performance optimizations for high-throughput scenarios

Contributing

The Copilot SDK for Java is a community-driven project. We welcome contributions! Check out our GitHub repository and the contributing guidelines.


Links:

Published: February 5, 2026

Top comments (0)