Skip to content

feat(claude-sdk): Notification + StopFailure hooks for SDK telemetry - #128

Merged
dylanneve1 merged 1 commit into
mainfrom
feat/sdk-notification-hooks
May 13, 2026
Merged

feat(claude-sdk): Notification + StopFailure hooks for SDK telemetry#128
dylanneve1 merged 1 commit into
mainfrom
feat/sdk-notification-hooks

Conversation

@claudiusthebot

Copy link
Copy Markdown
Collaborator

Summary

Registers two new SDK hook handlers that surface previously-invisible events from the Claude Agent SDK loop:

  • Notification hook: 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.

  • StopFailure hook: logs abnormal session exit events with their full error_details payload. 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 existing PostToolBatch turn-terminator hook is unchanged.

What changes

  • src/backend/claude-sdk/options.ts: 2 new hook functions + registered in hooks config. Imports NotificationHookInput, StopFailureHookInput from SDK, logError from util/log.
  • src/__tests__/claude-sdk-options.test.ts: 8 new assertions (hook registration, correct continue:true, optional fields, defensive no-op for wrong hook_event_name). 17/17 tests pass.

Test plan

  • All CI checks green
  • typecheck ✅ · format:check ✅ (verified locally)
  • After merge: trigger a context-length-heavy turn and confirm [NOTIFICATION] appears in talon.log on compaction

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Notification hook to log SDK notifications like context compaction, model switching, and rate-limit advisories.
  • Added a StopFailure hook to log abnormal SDK loop exits including error_details payload.
  • Extended buildSdkOptions tests to assert hook registration and defensive continue: true behavior.

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
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
dylanneve1 force-pushed the feat/sdk-notification-hooks branch from 47b0cb6 to e89962e Compare May 13, 2026 13:13
@dylanneve1
dylanneve1 merged commit 63c9cb8 into main May 13, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants