github/copilot-sdk · error · ValueError

working_directory is not supported with…

Error message

working_directory is not supported with RuntimeConnection.for_inprocess(): the native runtime shares the host process working directory, so a per-client working directory cannot be honored in-process. Use a child-process transport, or set the process working directory before creating the client.

What it means

The native runtime shares the host process working directory in the in-process transport, so a per-client working_directory cannot be honored. Passing options.working_directory with an in-process connection raises ValueError to avoid silently using the wrong directory.

Solutions

  1. Remove working_directory and call os.chdir() on the host process before creating the client
  2. Switch to RuntimeConnection.for_stdio() for per-client working directories

Example fix

// before
client = CopilotClient(connection=RuntimeConnection.for_inprocess(), working_directory="/repo")
// after
os.chdir("/repo")
client = CopilotClient(connection=RuntimeConnection.for_inprocess())
Defensive patterns

Strategy: validation

Validate before calling

if isinstance(conn, InProcessRuntimeConnection) and opts.working_directory is not None:
    raise ValueError("working_directory is unsupported for in-process; os.chdir() instead")

Type guard

def supports_client_workdir(conn) -> bool:
    return not isinstance(conn, InProcessRuntimeConnection)

Try / catch

try:
    client = CopilotClient(connection=conn, working_directory=wd)
except ValueError as e:
    if "working_directory is not supported" in str(e):
        os.chdir(wd); wd = None
        client = CopilotClient(connection=conn)

Prevention

When it happens

Trigger: Creating CopilotClient with RuntimeConnection.for_inprocess() and a non-None working_directory in _CopilotClientOptions.

Common situations: Per-project tooling that sets a working directory per session; refactoring a stdio-based client to in-process while keeping directory customization.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/e342bea15d3f56c9. Report an issue: GitHub.

Appendix: source

Thrown at python/copilot/client.py:1505

    """
    if isinstance(connection, InProcessRuntimeConnection):
        if options.env is not None:
            raise ValueError(
                "env is not supported with RuntimeConnection.for_inprocess(): the "
                "in-process transport loads the native runtime into the shared host "
                "process, whose single environment block cannot carry per-client "
                "values. Set the variables on the host process environment instead."
            )
        if options.telemetry is not None:
            raise ValueError(
                "telemetry is not supported with RuntimeConnection.for_inprocess(): "
                "telemetry configuration is lowered to environment variables read by "
                "native runtime code running in the shared host process, so per-client "
                "telemetry cannot be honored in-process. Configure telemetry via the "
                "host process environment, or use a child-process transport."
            )
        if options.working_directory is not None:
            raise ValueError(
                "working_directory is not supported with RuntimeConnection.for_inprocess(): "
                "the native runtime shares the host process working directory, so a "
                "per-client working directory cannot be honored in-process. Use a "
                "child-process "
                "transport, or set the process working directory before creating the client."
            )
        return

    if (
        isinstance(connection, ChildProcessRuntimeConnection)
        and connection.env is not None
        and options.env is not None
    ):
        raise ValueError(
            "Set environment variables via either the client-level env argument or "
            "ChildProcessRuntimeConnection.env, not both. Prefer the connection-level "
            "env for child-process transports."
        )

View on GitHub (pinned to cd8cf15dc3)