claude-code-sdk-python/examples
Dickson Tsai 180d64887a
feat: add stderr callback to capture CLI debug output (#170)
## Summary
- Add stderr callback option to ClaudeCodeOptions to capture CLI
subprocess stderr output
- Matches TypeScript SDK's stderr callback behavior for feature parity
- Useful for debugging and monitoring CLI operations

## Changes
- Added `stderr: Callable[[str], None] | None` field to
`ClaudeCodeOptions`
- Updated `SubprocessCLITransport` to handle stderr streaming with async
task
- Added example demonstrating stderr callback usage
- Added e2e tests to verify functionality

## Test plan
- [x] Run e2e tests: `python -m pytest e2e-tests/test_stderr_callback.py
-v`
- [x] Run example: `python examples/stderr_callback_example.py`
- [x] Verify backward compatibility with existing `debug_stderr` field
- [x] All linting and type checks pass

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-28 14:10:10 -07:00
..
agents.py Rename ClaudeCodeOptions to ClaudeAgentOptions (#185) 2025-09-26 21:38:05 -07:00
hooks.py Rename ClaudeCodeOptions to ClaudeAgentOptions (#185) 2025-09-26 21:38:05 -07:00
include_partial_messages.py Rename ClaudeCodeOptions to ClaudeAgentOptions (#185) 2025-09-26 21:38:05 -07:00
mcp_calculator.py Rename ClaudeCodeOptions to ClaudeAgentOptions (#185) 2025-09-26 21:38:05 -07:00
quick_start.py Rename ClaudeCodeOptions to ClaudeAgentOptions (#185) 2025-09-26 21:38:05 -07:00
setting_sources.py Rename ClaudeCodeOptions to ClaudeAgentOptions (#185) 2025-09-26 21:38:05 -07:00
stderr_callback_example.py feat: add stderr callback to capture CLI debug output (#170) 2025-09-28 14:10:10 -07:00
streaming_mode.py Rename ClaudeCodeOptions to ClaudeAgentOptions (#185) 2025-09-26 21:38:05 -07:00
streaming_mode_ipython.py feat: Add in-process SDK MCP server support (#142) 2025-09-03 08:29:32 -07:00
streaming_mode_trio.py Rename ClaudeCodeOptions to ClaudeAgentOptions (#185) 2025-09-26 21:38:05 -07:00
system_prompt.py Rename ClaudeCodeOptions to ClaudeAgentOptions (#185) 2025-09-26 21:38:05 -07:00
tool_permission_callback.py Rename ClaudeCodeOptions to ClaudeAgentOptions (#185) 2025-09-26 21:38:05 -07:00