claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

`cwd` in ClaudeCodeOptions does not seem to be honored at all

Open abhaybhargav opened this issue 6 months ago • 5 comments

Update

This is now ok when I use opus for some reason.

Using this code from the examples and docs. The cwd is completely ignored and random paths are picked. Even with bypassPermissions enabled

async def main():
    messages: list[Message] = []

    async for message in query(
        prompt = prompt,
        options = ClaudeCodeOptions(
            cwd = Path("/path/to/app"),
            system_prompt = "You are a helpful assistant",
            allowed_tools = ['Task', 'Agent', 'Bash', 'Glob', 'Grep', 'LS', 'exit_plan_mode', 'Read', 'Edit', 'MultiEdit', 'Write', 'NotebookRead', 'NotebookEdit', 'WebFetch', 'TodoRead', 'TodoWrite'],
            permission_mode = "bypassPermissions",
            continue_conversation=True,
            max_turns = 10,
        ),
    ):
        messages.append(message)

    print(messages)

anyio.run(main)

abhaybhargav avatar Jun 15 '25 05:06 abhaybhargav

Me too. when I set "/path/to/app", it becomes "/private/path/to/app"

tim-watcha avatar Jun 25 '25 15:06 tim-watcha

Me too. when I set "/path/to/app", it becomes "/private/path/to/app"

I figured out that Mac's symlink works in that way when I use /tmp/... folder. My issue was another one.

tim-watcha avatar Jun 26 '25 03:06 tim-watcha

same,must specify in prompt

Found it works find with gemini-2.5-pro,lol

wodexiaobai322 avatar Jul 23 '25 06:07 wodexiaobai322

Same issue here. Not only it does not respect the cwd option, it tries to perform tasks in other directories, which is dangerous! Thank god it runs into permissions issues!

elmspace avatar Aug 06 '25 04:08 elmspace

Gently ping @ltawfik , any update on this? It still writes files to /tmp randomly even if I set a cwd

marswong avatar Oct 24 '25 04:10 marswong