Skip to content

Commit 6457045

Browse files
ashwin-antclaude
andcommitted
feat: Add debug_stderr parameter for flexible debug output routing
- Add debug_stderr field to ClaudeCodeOptions with sys.stderr as default - Allows customers to route debug output to files, buffers, or custom streams - Maintains backward compatibility while providing maximum flexibility - Only routes debug output when both debug-to-stderr flag and debug_stderr are set 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c23acae commit 6457045

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/claude_code_sdk/_internal/transport/subprocess_cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import logging
55
import os
66
import shutil
7-
import sys
87
from collections.abc import AsyncIterable, AsyncIterator
98
from contextlib import suppress
109
from pathlib import Path
@@ -181,9 +180,12 @@ async def connect(self) -> None:
181180
if self._cwd:
182181
process_env["PWD"] = self._cwd
183182

184-
# Only output stderr if customer explicitly requested debug output
183+
# Only output stderr if customer explicitly requested debug output and provided a file object
185184
stderr_dest = (
186-
sys.stderr if "debug-to-stderr" in self._options.extra_args else None
185+
self._options.debug_stderr
186+
if "debug-to-stderr" in self._options.extra_args
187+
and self._options.debug_stderr
188+
else None
187189
)
188190

189191
self._process = await anyio.open_process(

src/claude_code_sdk/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Type definitions for Claude SDK."""
22

3+
import sys
34
from collections.abc import Awaitable, Callable
45
from dataclasses import dataclass, field
56
from pathlib import Path
@@ -250,6 +251,9 @@ class ClaudeCodeOptions:
250251
extra_args: dict[str, str | None] = field(
251252
default_factory=dict
252253
) # Pass arbitrary CLI flags
254+
debug_stderr: Any = (
255+
sys.stderr
256+
) # File-like object for debug output when debug-to-stderr is set
253257

254258
# Tool permission callback
255259
can_use_tool: CanUseTool | None = None

0 commit comments

Comments
 (0)