Claude Agent SDK hooks for the Grafana Agent Observability Python SDK
Project description
Sigil Python Framework Module: Claude Agent SDK
agento11y-claude-agent-sdk records Claude Agent SDK sessions as Sigil generations and maps Claude tool hooks to Sigil 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
Sigil guards run through Claude Agent SDK hooks:
UserPromptSubmitevaluates the submitted prompt before Claude proceeds. A Sigil deny returnscontinue_=False, stopping the run.PreToolUseevaluates tool requests before execution. A Sigil deny maps to Claude'spermissionDecision="deny".
Enable guards on the Sigil 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:
- Explicit
conversation_idpassed to the Sigil handler oragento11y_query ClaudeAgentOptions.session_idClaudeAgentOptions.resume- 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-sdkagento11y.framework.source=hooksagento11y.framework.language=python
Metadata includes:
agento11y.framework.run_idagento11y.framework.run_type=agentagento11y.framework.session_idwhen Claude returns oneagento11y.claude_agent.permission_modewhen configuredagento11y.claude_agent.cwdwhen configuredagento11y.claude_agent.total_cost_usdwhen Claude returns cost data
Claude Native OpenTelemetry
This package records Sigil generations and tool spans through the Sigil 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 Sigil client was created with
ClientConfig(hooks=HooksConfig(enabled=True)). - Always call
client.shutdown()during teardown.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agento11y_claude_agent_sdk-0.10.0.tar.gz.
File metadata
- Download URL: agento11y_claude_agent_sdk-0.10.0.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
272934df778f8b67683fc18f0e83cd01040c68a5d6f929d771fde183a5c2b621
|
|
| MD5 |
a1ca1b06e63587f529cd12a25a8888c5
|
|
| BLAKE2b-256 |
8e8fbeef8c0a0cfeb36bcec296b5abe4bc98b2695c3b2fc3eece7368628407c6
|
Provenance
The following attestation bundles were made for agento11y_claude_agent_sdk-0.10.0.tar.gz:
Publisher:
python-sdks-publish.yml on grafana/agento11y
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agento11y_claude_agent_sdk-0.10.0.tar.gz -
Subject digest:
272934df778f8b67683fc18f0e83cd01040c68a5d6f929d771fde183a5c2b621 - Sigstore transparency entry: 2212060526
- Sigstore integration time:
-
Permalink:
grafana/agento11y@a4e0bb2da205e2db40e7668df4e343263872cb3a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/grafana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-sdks-publish.yml@a4e0bb2da205e2db40e7668df4e343263872cb3a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file agento11y_claude_agent_sdk-0.10.0-py3-none-any.whl.
File metadata
- Download URL: agento11y_claude_agent_sdk-0.10.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7807a0d8a44cc46bd5549164ebd3b59e4c529e31c24dfb0d12209206d211541b
|
|
| MD5 |
466b6d9a64911710a7f3d36a89214694
|
|
| BLAKE2b-256 |
43ed0ada3c2b58e1c81dbbd04e226d8617c532ab5c8619f7274093b5a3ea9457
|
Provenance
The following attestation bundles were made for agento11y_claude_agent_sdk-0.10.0-py3-none-any.whl:
Publisher:
python-sdks-publish.yml on grafana/agento11y
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agento11y_claude_agent_sdk-0.10.0-py3-none-any.whl -
Subject digest:
7807a0d8a44cc46bd5549164ebd3b59e4c529e31c24dfb0d12209206d211541b - Sigstore transparency entry: 2212060550
- Sigstore integration time:
-
Permalink:
grafana/agento11y@a4e0bb2da205e2db40e7668df4e343263872cb3a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/grafana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-sdks-publish.yml@a4e0bb2da205e2db40e7668df4e343263872cb3a -
Trigger Event:
workflow_dispatch
-
Statement type: