Repository navigation
v0.26.0
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:threadmode, in place on the reactor fiber in:inlinemode. Exceptions propagate through it unchanged; a user'sbreakin 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 ascallback_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 } }
}
endAlso 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