Skip to content

Commit 590ea7a

Browse files
dicksontsairushilpatel0
authored andcommitted
Support --add-dir flag (anthropics#104)
Signed-off-by: Rushil Patel <rpatel@codegen.com>
1 parent b6ddaea commit 590ea7a

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.0.19
4+
5+
- Add `ClaudeCodeOptions.add_dirs` for `--add-dir`
6+
- Fix ClaudeCodeSDK hanging when MCP servers log to Claude Code stderr
7+
38
## 0.0.18
49

510
- Add `ClaudeCodeOptions.settings` for `--settings`

src/claude_code_sdk/_internal/transport/subprocess_cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ def _build_command(self) -> list[str]:
134134
if self._options.settings:
135135
cmd.extend(["--settings", self._options.settings])
136136

137+
if self._options.add_dirs:
138+
# Convert all paths to strings and add each directory
139+
for directory in self._options.add_dirs:
140+
cmd.extend(["--add-dir", str(directory)])
141+
137142
if self._options.mcp_servers:
138143
cmd.extend(
139144
["--mcp-config", json.dumps({"mcpServers": self._options.mcp_servers})]

src/claude_code_sdk/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,4 @@ class ClaudeCodeOptions:
128128
permission_prompt_tool_name: str | None = None
129129
cwd: str | Path | None = None
130130
settings: str | None = None
131+
add_dirs: list[str | Path] = field(default_factory=list)

tests/test_transport.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ def test_build_command_with_options(self):
7979
assert "--max-turns" in cmd
8080
assert "5" in cmd
8181

82+
def test_build_command_with_add_dirs(self):
83+
"""Test building CLI command with add_dirs option."""
84+
from pathlib import Path
85+
86+
transport = SubprocessCLITransport(
87+
prompt="test",
88+
options=ClaudeCodeOptions(
89+
add_dirs=["/path/to/dir1", Path("/path/to/dir2")]
90+
),
91+
cli_path="/usr/bin/claude",
92+
)
93+
94+
cmd = transport._build_command()
95+
cmd_str = " ".join(cmd)
96+
97+
# Check that the command string contains the expected --add-dir flags
98+
assert "--add-dir /path/to/dir1 --add-dir /path/to/dir2" in cmd_str
99+
82100
def test_session_continuation(self):
83101
"""Test session continuation options."""
84102
transport = SubprocessCLITransport(

0 commit comments

Comments
 (0)