Skip to main content
Requires: @anthropic-ai/claude-agent-sdk v0.2.0+ as a peer dependency. Works with the query() function for one-shot and multi-turn interactions.

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 convoId — multi-turn conversations appear linked.

Errors

Failed tool calls, errored sessions, and generator exceptions — all recorded.

Duration

Wall-clock time from start to result, plus API-side duration when available.
Consume the stream until the result message to record final tokens/cost/output. If you close the generator early (for example via break/return), the session is marked failed with Session interrupted (generator closed early) so runs do not remain stuck in running.

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 convoId to group related sessions into a conversation. Each call to trackedQuery() creates a new session, but they appear linked in the dashboard.

How Tool Tracking Works

The wrapper uses PostToolUse and PostToolUseFailure hooks to capture every tool execution. Hooks fire asynchronously and never block the agent. A session-ready gate ensures hooks wait for session creation before tracking.
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 (Python)

Same integration for the Python Claude Agent SDK.

TypeScript SDK Reference

Full SDK documentation with all methods and options.