feat(claude-sdk): Notification + StopFailure hooks for SDK telemetry - #128
Merged
Conversation
7 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds two observational Claude Agent SDK hook handlers to improve telemetry during SDK query sessions by surfacing previously silent lifecycle events and abnormal stop failures in the agent logs.
Changes:
- Added a
Notificationhook to log SDK notifications like context compaction, model switching, and rate-limit advisories. - Added a
StopFailurehook to log abnormal SDK loop exits includingerror_detailspayload. - Extended
buildSdkOptionstests to assert hook registration and defensivecontinue: truebehavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/backend/claude-sdk/options.ts | Introduces and registers Notification and StopFailure hooks in the SDK options builder, logging events for telemetry. |
| src/tests/claude-sdk-options.test.ts | Adds tests validating hook registration and that both hooks are defensive and always return { continue: true }. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dylanneve1
enabled auto-merge (squash)
May 13, 2026 13:10
…metry Register two new SDK hook handlers in options.ts: - **Notification**: logs SDK-generated notifications (context compaction, model switches, rate-limit advisories) that were previously silently dropped. Makes the lifecycle of a session visible in talon.log — previously the only evidence of compaction was a spike in cache-write tokens in the post-turn accounting line. - **StopFailure**: logs SDK stop-failure events with their full `error_details` payload. Without this hook, abnormal session exits were swallowed and only the downstream `catch` block in handler.ts saw them (as a thrown error), losing the raw API context. Both hooks are purely observational (`continue: true`). No behaviour changes — existing PostToolBatch turn-terminator hook is unchanged. Tests: 8 new assertions in claude-sdk-options.test.ts covering hook registration, correct continue:true return, optional fields (title on Notification, missing error_details on StopFailure), and defensive no-op for wrong hook_event_name. 17/17 passing. typecheck ✅ · format:check ✅ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
dylanneve1
force-pushed
the
feat/sdk-notification-hooks
branch
from
May 13, 2026 13:13
47b0cb6 to
e89962e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Registers two new SDK hook handlers that surface previously-invisible events from the Claude Agent SDK loop:
Notificationhook: logs SDK notifications (context compaction, model switches, rate-limit advisories). Previously these fired and were silently dropped — the only evidence of a compaction was a spike in cache-write tokens in the post-turn accounting line. Now you'll see[NOTIFICATION] type=compaction: Compacting context...in talon.log.StopFailurehook: logs abnormal session exit events with their fullerror_detailspayload. Without this hook, stop failures were only visible as a generic thrown error in handler.ts, losing the raw API response context.Both hooks are purely observational — they return
{ continue: true }and don't modify SDK behaviour. The existingPostToolBatchturn-terminator hook is unchanged.What changes
src/backend/claude-sdk/options.ts: 2 new hook functions + registered inhooksconfig. ImportsNotificationHookInput,StopFailureHookInputfrom SDK,logErrorfrom util/log.src/__tests__/claude-sdk-options.test.ts: 8 new assertions (hook registration, correctcontinue:true, optional fields, defensive no-op for wronghook_event_name). 17/17 tests pass.Test plan
typecheck✅ ·format:check✅ (verified locally)[NOTIFICATION]appears in talon.log on compaction🤖 Generated with Claude Code