Skip to content

v0.26.0

Choose a tag to compare

@ya-luotao ya-luotao released this 31 Jul 06:46
· 566 commits to main since this release

Added

  • ClaudeAgentOptions#callback_wrapper (#47 phase 2): optional middleware wrapped around every user-callback dispatch — message blocks, observers, hooks, permission callbacks, SDK MCP handlers. A callable receiving a zero-arg invocation that it must call and return. The wrapper runs on the same execution context as the callback: inside the worker thread in the default :thread mode, in place on the reactor fiber in :inline mode. Exceptions propagate through it unchanged; a user's break in a message block reaches the wrapper as a clean return, never as an exception. Also settable per SDK MCP server for direct calls (server.callback_wrapper=); session dispatches carry the session's wrapper through the same fiber-storage scope as callback_scheduling, resolved atomically with the mode — concurrent sessions with different wrappers sharing one server stay fully isolated.

Usage

# Rails, staying on the default :thread mode: return AR connections after
# every callback — no more stranded connections on worker threads.
ClaudeAgentSDK.configure do |config|
  config.default_options = {
    callback_wrapper: ->(inv) { Rails.application.executor.wrap { inv.call } }
  }
end

Also a generic hook for APM / logging context propagation. See "Rails executor around callbacks" in docs/rails.md.

What's changed

  • #49 callback_wrapper middleware around every user-callback dispatch (#47 phase 2) — @ya-luotao

Full Changelog: v0.25.0...v0.26.0


gem install claude-agent-sdk -v 0.26.0