Skip to main content
Requires: claude-agent-sdk v0.1.0+ and httpx as peer dependencies. Works with both query() (one-shot) and ClaudeSDKClient (multi-turn conversations).

What Gets Tracked Automatically

Sessions

Created on init, completed on result — with agent name, user ID, and metadata.

Tool Calls

Every tool execution (Bash, Read, Write, etc.) with input, output, and tool use ID.

Tokens & Cost

Prompt tokens, completion tokens, total tokens, and estimated cost in USD.

Conversation Threading

Group related sessions with convo_id — multi-turn conversations appear linked.

Errors

Failed sessions and generator exceptions — all recorded with failure reasons.

Duration

Wall-clock time from start to result, plus API-side duration when available.
Both wrap_claude_agent (for query()) and wrap_claude_client (for ClaudeSDKClient) require consuming the stream until the result message to record final tokens/cost/output. If you close the generator early, the session is marked failed with Session interrupted (generator closed early).

Installation

Quick Start

Wrap the query() function once, then use it exactly like normal.

Configuration Options

Fail-Safe by Default — If Sentrial is unreachable, all messages pass through unchanged. Your agent never breaks due to tracking failures.

Conversation Threading

Use convo_id to group related sessions into a conversation. Each call to tracked_query() creates a new session, but they appear linked in the dashboard.

Using with ClaudeSDKClient

If you use ClaudeSDKClient for multi-turn conversations (instead of query()), use wrap_claude_client:
Each query() + receive_response() cycle creates a separate Sentrial session. All sessions share the same convo_id so they appear linked in the dashboard.

How Tool Tracking Works

The wrapper observes the message stream to detect tool calls. When an AssistantMessage contains a ToolUseBlock, the wrapper captures the tool name and input. When the following UserMessage arrives with tool results, it matches them and records the tool call event. This approach is reliable across all SDK versions.
In the dashboard, each tool call appears as an event under the session timeline.

Error Handling

If the agent errors, the generator throws, or the consumer closes the stream early, the session is automatically marked as failed with a clear failure reason.

Full Production Example

What You See in the Dashboard

Session Overview

Agent name, user ID, conversation thread, status, duration, cost.

Input / Output

The prompt and Claude’s final response.

Tool Call Timeline

Every Bash, Read, Write, Glob call — with input, output, and tool use ID.

Token & Cost Breakdown

Prompt tokens, completion tokens, total, estimated USD cost.

Next Steps

Claude Code (TypeScript)

Same integration for the TypeScript Claude Agent SDK.

Python SDK Reference

Full SDK documentation with all methods and options.