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
- Define a synchronous
stderr_callback(message: str)and store or filter only necessary lines. [stderr] - Pass it with
ClaudeAgentOptions(stderr=stderr_callback)toquery(..., options=...). [stderr] - 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
- Python 3.10+, SDK, and a writable temporary log location with access controls.
Permissions
- Do not upload full stderr to public logs; retain only what is needed for diagnosis.
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
- 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