github/copilot-sdk · error
WorkingDirectory is not supported with InProcessConnection…
Error message
WorkingDirectory is not supported with InProcessConnection: the native runtime shares the host process working directory. Use a child-process transport, or set the process working directory before creating the client.
What it means
NewClient panics when ClientOptions.WorkingDirectory is set while using InProcessConnection. The in-process transport loads the native runtime into the shared host process, so the runtime necessarily shares the host's working directory; a per-client working directory cannot be honored. The library fails loud at client construction instead of silently ignoring the option.
Solutions
- Remove the WorkingDirectory option when using InProcessConnection.
- If an isolated working directory is required, switch the connection to StdioConnection{} (child-process transport).
- Set os.Chdir on the host process before creating the client if you truly need a different working directory in-process (note this is process-global).
Example fix
// before
client := clientpkg.NewClient(&clientpkg.Options{
Connection: clientpkg.InProcessConnection{},
WorkingDirectory: "/tmp/agent-work",
})
// after
client := clientpkg.NewClient(&clientpkg.Options{
Connection: clientpkg.InProcessConnection{},
})
// or, keep the working directory by using the child-process transport:
client := clientpkg.NewClient(&clientpkg.Options{
Connection: clientpkg.StdioConnection{},
WorkingDirectory: "/tmp/agent-work",
}) Defensive patterns
Strategy: validation
Validate before calling
if _, isInProc := opts.Connection.(clientpkg.InProcessConnection); isInProc && opts.WorkingDirectory != "" {
return fmt.Errorf("WorkingDirectory is unsupported with InProcessConnection")
} Type guard
func isInProcess(c clientpkg.RuntimeConnection) bool { _, ok := c.(clientpkg.InProcessConnection); return ok } Prevention
- Keep transport-specific options grouped per transport in your config layer.
- Audit option structs when switching transports between stdio and in-process.
- Wrap NewClient in a small constructor that validates options for the chosen connection type first.
When it happens
Trigger: Calling NewClient with Options.Connection set to InProcessConnection{} (or COPILOT_CLI_CONNECTION=inprocess) while ClientOptions.WorkingDirectory is a non-empty string. Panics inside validateEnvironmentOptions (go/client.go:114), reached via NewClient.
Common situations: Code that previously used the default stdio child-process transport and set WorkingDirectory for the child is switched to the in-process transport for startup performance; the stale WorkingDirectory option now trips the guard.
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
- Telemetry is not supported with InProcessConnection…
- Env is not supported with InProcessConnection: the…
- Set environment variables via either the client-level Env…
- GitHubToken and UseLoggedInUser cannot be used with…
- err.Error()
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/b622bd480a2504c0.
Report an issue: GitHub.
Appendix: source
Thrown at go/client.go:114
}
// validateEnvironmentOptions enforces the transport-specific rules for
// per-client environment, working directory, and telemetry. It panics (fails
// loud) on a misconfiguration, matching the other SDKs.
//
// The in-process transport loads the native runtime into this process, whose
// single environment block and process-global working directory cannot carry
// per-client values, and whose telemetry lowers to shared process-global env
// vars — so options that depend on them are rejected there. Child-process
// transports each own their OS process, so per-connection env is allowed, but
// setting it in both the client-level option and the connection is rejected.
func validateEnvironmentOptions(connection RuntimeConnection, opts *ClientOptions) {
if _, ok := connection.(InProcessConnection); ok {
if opts.Env != nil {
panic("Env is not supported with InProcessConnection: 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 opts.WorkingDirectory != "" {
panic("WorkingDirectory is not supported with InProcessConnection: the native runtime shares the host process working directory. Use a child-process transport, or set the process working directory before creating the client.")
}
if opts.Telemetry != nil {
panic("Telemetry is not supported with InProcessConnection: 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.")
}
return
}
if cp, ok := connection.(childProcessConnection); ok {
if cp.connEnv() != nil && opts.Env != nil {
panic("Set environment variables via either the client-level Env option or the connection's Env, not both. Prefer the connection-level Env for child-process transports.")
}
}
}
// Client manages the connection to the Copilot CLI server and provides session management.
//
// The Client can either spawn a CLI server process or connect to an existing server.
// It handles JSON-RPC communication, session lifecycle, tool execution, and permission requests.View on GitHub (pinned to cd8cf15dc3)