Skip to main content
Available via: the Zespan hooks (TypeScript and Python). This is for agents you build and run with the Claude Agent SDK library. It is not a plugin for the Claude Code application.
The Claude Agent SDK runs hooks around every tool use. Zespan’s hooks turn each tool use into one Zespan tool span with its name, arguments, result and error status, so the tool-level checks of the domain packs can read it. The hooks only observe. They return an empty output, so permissions and tool results are never changed, and nothing in them throws into your agent.
Your own hooks keep running first; Zespan’s are added after them and your hook object is not changed. Setting storeToolIO: false (store_tool_io=False) drops arguments and results and keeps the tool name and status. Set ZESPAN_CLAUDE_AGENT=off to stop the hooks without a code change.

Record the answer with traceClaudeQuery

The hooks see tool uses, not the agent’s final reply. Wrap the message stream of query(...) with traceClaudeQuery (TypeScript) or trace_claude_query (Python) to add one answer span to the same trace as the tool spans. Every message is passed through unchanged. On the result message Zespan sends one llm span with: Tool spans and the answer span share the session’s trace and sit under one session root. A Task tool span (a subagent) is named after the subagent. Pass the same hooks object to both claudeAgentHooks and traceClaudeQuery so tool spans and the answer share a trace.
traceClaudeQuery returns a plain async generator, not the library’s Query object, so keep the original query(...) object for control calls such as interrupt() and setPermissionMode(). In Python, if the library’s aclose() raises when a stream ends early, the error is swallowed so it cannot replace your own. Needs the new TypeScript and Python SDK releases. ZESPAN_CLAUDE_AGENT=off also stops the answer span.