Skip to content

multi subagents with long prompt do not work on windows #238

@QudaRulo

Description

@QudaRulo

problem is at line 175

cmd.extend(["--agents", json.dumps(agents_dict)])

and windows cmd max length is 8191.
error log in console:

PS > uv run .\xxxx.py
命令行太长。
Fatal error in message reader: Command failed with exit code 1 (exit code: 1)
Error output: Check stderr output for details

and this is the monkey patch by claude code

   from claude_agent_sdk._internal.transport.subprocess_cli import SubprocessCLITransport

    _original_build_command = SubprocessCLITransport._build_command

    def _patched_build_command(self):
        cmd = _original_build_command(self)

        if '--agents' in cmd:
            idx = cmd.index('--agents')
            if idx + 1 < len(cmd):
                agents_json = cmd[idx + 1]
                temp_file = tempfile.NamedTemporaryFile(
                    mode='w',
                    suffix='.json',
                    delete=False,
                    encoding='utf-8'
                )
                temp_file.write(agents_json)
                temp_file.close()

                cmd[idx + 1] = f"@{temp_file.name}"

        return cmd

    SubprocessCLITransport._build_command = _patched_build_command
    print("[Windows Workaround] Applied monkey patch to fix 'command line too long' issue")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions