github/copilot-sdk · error · ArgumentException
CopilotClientOptions.WorkingDirectory is not supported with…
Error message
CopilotClientOptions.WorkingDirectory is not supported with RuntimeConnection.ForInProcess(): the in-process transport hosts the native runtime in the shared host process and spawns the worker without a working-directory parameter, 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
CopilotClient throws this ArgumentException when CopilotClientOptions.WorkingDirectory is set with RuntimeConnection.ForInProcess(). The in-process transport hosts the native runtime in the shared host process and spawns the worker without a working-directory parameter, so a per-client working directory cannot be honored. The library throws at construction rather than ignoring the value.
Solutions
- Set options.WorkingDirectory to null when using ForInProcess().
- Call Directory.SetCurrentDirectory(path) (or set the process working directory) before creating the client.
- Use RuntimeConnection.ForStdio() if a per-client working directory is required.
Example fix
// before
var options = new CopilotClientOptions { WorkingDirectory = @"C:\repos\app" };
var client = new CopilotClient(options, RuntimeConnection.ForInProcess());
// after
var options = new CopilotClientOptions();
Directory.SetCurrentDirectory(@"C:\repos\app");
var client = new CopilotClient(options, RuntimeConnection.ForInProcess()); Defensive patterns
Strategy: validation
Validate before calling
if (connection is InProcessRuntimeConnection && options.WorkingDirectory is not null)
throw new InvalidOperationException("Use Directory.SetCurrentDirectory or ForStdio for a per-client working directory."); Type guard
static bool AllowsOptionsWorkingDirectory(RuntimeConnection c) => c is not InProcessRuntimeConnection;
Try / catch
try { client = new CopilotClient(options, connection); }
catch (ArgumentException ex) when (ex.Message.Contains("WorkingDirectory")) { Directory.SetCurrentDirectory(options.WorkingDirectory); options.WorkingDirectory = null; client = new CopilotClient(options, connection); } Prevention
- Clear WorkingDirectory when using in-process transport
- Set process current directory before client creation
- Prefer ForStdio when per-client working directories matter
When it happens
Trigger: new CopilotClient(options, RuntimeConnection.ForInProcess()) where options.WorkingDirectory is a non-null path. Checked by ValidateEnvironmentOptions during CopilotClient construction.
Common situations: Pointing the client at a project directory per workspace in a multi-workspace app; reusing options built for a stdio (child-process) transport after switching to in-process.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- CopilotClientOptions.Environment is not supported with…
- CopilotClientOptions.Telemetry is not supported with…
- working_directory is not supported with…
- CopilotClientOptions.
- Unsupported RuntimeConnection type
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/d9e10ec62c68d474.
Report an issue: GitHub.
Appendix: source
Thrown at dotnet/src/Client.cs:253
"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.",
nameof(options));
}
if (options.Telemetry is not null)
{
throw new ArgumentException(
$"{nameof(CopilotClientOptions)}.{nameof(CopilotClientOptions.Telemetry)} is not supported with " +
$"{nameof(RuntimeConnection)}.{nameof(RuntimeConnection.ForInProcess)}(): 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.",
nameof(options));
}
if (options.WorkingDirectory is not null)
{
throw new ArgumentException(
$"{nameof(CopilotClientOptions)}.{nameof(CopilotClientOptions.WorkingDirectory)} is not supported with " +
$"{nameof(RuntimeConnection)}.{nameof(RuntimeConnection.ForInProcess)}(): the in-process transport hosts " +
"the native runtime in the shared host process and spawns the worker without a working-directory " +
"parameter, 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.",
nameof(options));
}
return;
}
if (connection is ChildProcessRuntimeConnection { Environment: not null } && options.Environment is not null)
{
throw new ArgumentException(
$"Set environment variables via either {nameof(CopilotClientOptions)}.{nameof(CopilotClientOptions.Environment)} " +
$"or {nameof(ChildProcessRuntimeConnection)}.{nameof(ChildProcessRuntimeConnection.Environment)}, not both. " +
$"Prefer {nameof(ChildProcessRuntimeConnection)}.{nameof(ChildProcessRuntimeConnection.Environment)} for " +
"child-process transports.",View on GitHub (pinned to cd8cf15dc3)