Support --add-dir flag (#104)

This commit is contained in:
Dickson Tsai 2025-07-31 20:52:30 -07:00 committed by GitHub
parent fbda510ee4
commit 0cb5efa923
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 0 deletions

View file

@ -1,5 +1,10 @@
# Changelog
## 0.0.19
- Add `ClaudeCodeOptions.add_dirs` for `--add-dir`
- Fix ClaudeCodeSDK hanging when MCP servers log to Claude Code stderr
## 0.0.18
- Add `ClaudeCodeOptions.settings` for `--settings`

View file

@ -124,6 +124,11 @@ class SubprocessCLITransport(Transport):
if self._options.settings:
cmd.extend(["--settings", self._options.settings])
if self._options.add_dirs:
# Convert all paths to strings and add each directory
for directory in self._options.add_dirs:
cmd.extend(["--add-dir", str(directory)])
if self._options.mcp_servers:
cmd.extend(
["--mcp-config", json.dumps({"mcpServers": self._options.mcp_servers})]

View file

@ -128,3 +128,4 @@ class ClaudeCodeOptions:
permission_prompt_tool_name: str | None = None
cwd: str | Path | None = None
settings: str | None = None
add_dirs: list[str | Path] = field(default_factory=list)

View file

@ -79,6 +79,24 @@ class TestSubprocessCLITransport:
assert "--max-turns" in cmd
assert "5" in cmd
def test_build_command_with_add_dirs(self):
"""Test building CLI command with add_dirs option."""
from pathlib import Path
transport = SubprocessCLITransport(
prompt="test",
options=ClaudeCodeOptions(
add_dirs=["/path/to/dir1", Path("/path/to/dir2")]
),
cli_path="/usr/bin/claude",
)
cmd = transport._build_command()
cmd_str = " ".join(cmd)
# Check that the command string contains the expected --add-dir flags
assert "--add-dir /path/to/dir1 --add-dir /path/to/dir2" in cmd_str
def test_session_continuation(self):
"""Test session continuation options."""
transport = SubprocessCLITransport(