Skip to main content

Agent Observability Python Framework Module: Claude Agent SDK

agento11y-claude-agent-sdk records Claude Agent SDK sessions as agento11y generations and maps Claude tool hooks to agento11y tool spans.

Installation

pip install agento11y agento11y-claude-agent-sdk
pip install claude-agent-sdk

The Claude Agent SDK runs the Claude Code CLI. Authenticate and configure Claude Code the same way you would for a normal Claude Agent SDK application.

Quickstart

import asyncio

from claude_agent_sdk import ClaudeAgentOptions
from agento11y import Client
from agento11y_claude_agent import agento11y_query


async def main():
    client = Client()
    try:
        async for message in agento11y_query(
            prompt="List the files in this directory.",
            options=ClaudeAgentOptions(
                permission_mode="default",
                model="claude-sonnet-4-5",
            ),
            client=client,
            conversation_id="demo-claude-agent-sdk",
            agent_name="claude-agent-demo",
        ):
            print(message)
    finally:
        client.shutdown()


asyncio.run(main())

Existing ClaudeSDKClient Usage

For bidirectional sessions, attach hooks to your ClaudeAgentOptions and pass every stream message to the handler:

from claude_agent_sdk import ClaudeAgentOptions
from agento11y import Client
from agento11y_claude_agent import Agento11yClaudeSDKClient

agento11y = Client()
options = ClaudeAgentOptions(permission_mode="default")

async with Agento11yClaudeSDKClient(
    client=agento11y,
    options=options,
    conversation_id="customer-42",
    agent_name="support-agent",
) as claude:
    await claude.query("Help me inspect this project.")
    async for message in claude.receive_response():
        print(message)

    await claude.set_permission_mode("acceptEdits")

agento11y.shutdown()

Agento11yClaudeSDKClient forwards query(), receive_response(), receive_messages(), set_permission_mode(), rewind_files(), interrupt(), and disconnect() to the wrapped Claude client. Use agento11y_query() for simple single-query scripts and Agento11yClaudeSDKClient when you need Claude SDK session control such as permission mode changes, resume/checkpoint flows, or multiple queries in one client session.

Guards

Agent Observability guards run through Claude Agent SDK hooks:

  • UserPromptSubmit evaluates the submitted prompt before Claude proceeds. A guard deny returns continue_=False, stopping the run.
  • PreToolUse evaluates tool requests before execution. A guard deny maps to Claude's permissionDecision="deny".

Enable guards on the agento11y client:

from agento11y import Client, ClientConfig, HooksConfig

client = Client(ClientConfig(hooks=HooksConfig(enabled=True)))

HooksConfig keeps the core SDK defaults: preflight phase, 15 second timeout, and fail-open transport behavior unless configured otherwise.

Conversation Mapping

Conversation ID precedence:

  1. Explicit conversation_id passed to the agento11y handler or agento11y_query
  2. ClaudeAgentOptions.session_id
  3. ClaudeAgentOptions.resume
  4. unique fallback agento11y:framework:claude-agent-sdk:<run_id>

Agento11yClaudeSDKClient uses the same explicit conversation_id, session_id, and resume precedence. If none are set, it creates one client-level fallback conversation ID and reuses it for every query in that client session so multi-query sessions stay grouped.

When Claude returns a session ID in the stream, the handler also records it in generation metadata as agento11y.framework.session_id.

Metadata

Required framework tags:

  • agento11y.framework.name=claude-agent-sdk
  • agento11y.framework.source=hooks
  • agento11y.framework.language=python

Metadata includes:

  • agento11y.framework.run_id
  • agento11y.framework.run_type=agent
  • agento11y.framework.session_id when Claude returns one
  • agento11y.claude_agent.permission_mode when configured
  • agento11y.claude_agent.cwd when configured
  • agento11y.claude_agent.total_cost_usd when Claude returns cost data

Claude Native OpenTelemetry

This package records agento11y generations and tool spans through the agento11y Python SDK. The Claude Agent SDK can also make the Claude Code CLI export its native OpenTelemetry spans, metrics, and logs directly to your OTLP collector. Configure those variables in the parent process before calling agento11y_query; the Python Claude Agent SDK merges options.env on top of the inherited environment.

For Grafana Cloud, the important Claude variables are:

CLAUDE_CODE_ENABLE_TELEMETRY=1
CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1
OTEL_TRACES_EXPORTER=otlp
OTEL_METRICS_EXPORTER=otlp
OTEL_LOGS_EXPORTER=otlp
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp-gateway-prod-<region>.grafana.net/otlp
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Basic <base64 of OTLP_INSTANCE_ID:SIGIL_AUTH_TOKEN>

Do not use the console OTel exporter with the Claude Agent SDK; stdout is part of its message channel.

Local Validation

From the repository root:

mise run test:py:sdk-claude-agent-sdk

To run only this package manually:

uv run --python "$PYTHON_BIN" \
  --with './python[dev]' \
  --with-editable './python-frameworks/claude-agent-sdk[dev]' \
  pytest python-frameworks/claude-agent-sdk/tests

Troubleshooting

  • If generations are fragmented, pass a stable conversation_id.
  • If no Claude native traces appear, verify CLAUDE_CODE_ENABLE_TELEMETRY=1, an OTLP exporter is selected, and the endpoint/header values are visible to the Python process.
  • If guards do not run, make sure the agento11y client was created with ClientConfig(hooks=HooksConfig(enabled=True)).
  • Always call client.shutdown() during teardown.

Metadata

Release files for agento11y-claude-agent-sdk 0.20.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agento11y-claude-agent-sdk 0.20.0
File Size Uploaded Provenance Actions
agento11y_claude_agent_sdk-0.20.0.tar.gz 17.8 kB With provenance Details for agento11y_claude_agent_sdk-0.20.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for agento11y-claude-agent-sdk 0.20.0
File Interpreter ABI Platform Actions
agento11y_claude_agent_sdk-0.20.0-py3-none-any.whl Python 3 none any Details for agento11y_claude_agent_sdk-0.20.0-py3-none-any.whl

Total release size: 28.9 kB

Release files / agento11y_claude_agent_sdk-0.20.0.tar.gz

Download URL agento11y_claude_agent_sdk-0.20.0.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
04abfc44b3b29ee4d9b74c3f63fc884e78217e94c4e18148049e62168c8d8422
BLAKE2b-256 checksum
How to use checksums
30ae94ffd755a0b9931d7dce14057e0eb043954e869a75741ec64c5611d5daff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / agento11y_claude_agent_sdk-0.20.0-py3-none-any.whl

Download URL agento11y_claude_agent_sdk-0.20.0-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50c6a8be2575d1de7e224c6a909357aee56e86c0c7e40145af4c3c48a302635c
BLAKE2b-256 checksum
How to use checksums
6976312f18b34aa0c7379c5a0f0f3dd0144301171e8dbc43132adce1a93a157d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Security for agento11y-claude-agent-sdk 0.20.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for agento11y_claude_agent_sdk-0.20.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page