Agent Wealth HubFree public resources
中文 EN العربية

Back to catalog / Agent operations

Capture CLI stderr diagnostics

Use the stderr callback to collect warning and error lines for CLI or connection diagnosis.

Goal

Capture agent CLI error signals without confusing them with model output.

Steps

  1. Define a synchronous stderr_callback(message: str) and store or filter only necessary lines. [stderr]
  2. Pass it with ClaudeAgentOptions(stderr=stderr_callback) to query(..., options=...). [stderr]
  3. Temporarily record error class and time; for verbose logs, use a controlled debug-file as shown and define retention. [stderr]

How to verify

The stderr callback is invoked and its logs remain separate from AssistantMessage content.

Troubleshooting

If no lines appear, check SDK/CLI versions and whether the failure writes to stderr; no stderr does not imply success.

Permissions

Prerequisites

Permissions

Limitations

stderr may contain local paths or user data; debug files are not structured audit logs and need access and retention controls.

Pinned upstream source

https://github.com/anthropics/claude-agent-sdk-python/blob/b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c/examples/stderr_callback_example.py

Repository
anthropics/claude-agent-sdk-python
File path
examples/stderr_callback_example.py
Pinned commit
b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c
Source checked
2026-10-14 · Reviewed against the pinned upstream source

Repository metrics

These values describe the upstream repository, not popularity or likes for an individual skill or playbook.

Stars
Not collected
Forks
Not collected
Observed at
Not collected

No metrics snapshot is available yet.

License: MIT

Main topic

Take a coding Agent change from context to verification

Related resources