{"record":{"id":"de754060b6c559cf","repo":"github/copilot-sdk","slug":"env-is-not-supported-with-inprocessconnection-the","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"go/client.go","lineNumber":111,"sourceCode":"\t\treturn errors.New(\"SessionFS.Conventions must be either 'posix' or 'windows'\")\n\t}\n\treturn nil\n}\n\n// validateEnvironmentOptions enforces the transport-specific rules for\n// per-client environment, working directory, and telemetry. It panics (fails\n// loud) on a misconfiguration, matching the other SDKs.\n//\n// The in-process transport loads the native runtime into this process, whose\n// single environment block and process-global working directory cannot carry\n// per-client values, and whose telemetry lowers to shared process-global env\n// vars — so options that depend on them are rejected there. Child-process\n// transports each own their OS process, so per-connection env is allowed, but\n// setting it in both the client-level option and the connection is rejected.\nfunc validateEnvironmentOptions(connection RuntimeConnection, opts *ClientOptions) {\n\tif _, ok := connection.(InProcessConnection); ok {\n\t\tif opts.Env != nil {\n\t\t\tpanic(\"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.\")\n\t\t}\n\t\tif opts.WorkingDirectory != \"\" {\n\t\t\tpanic(\"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.\")\n\t\t}\n\t\tif opts.Telemetry != nil {\n\t\t\tpanic(\"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.\")\n\t\t}\n\t\treturn\n\t}\n\n\tif cp, ok := connection.(childProcessConnection); ok {\n\t\tif cp.connEnv() != nil && opts.Env != nil {\n\t\t\tpanic(\"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.\")\n\t\t}\n\t}\n}\n\n// Client manages the connection to the Copilot CLI server and provides session management.","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L93-L129","documentation":"NewClient validates ClientOptions against the chosen RuntimeConnection. The in-process transport loads the native runtime into the host process, so a single shared environment block cannot carry per-client values; setting opts.Env (and likewise WorkingDirectory/Telemetry) with InProcessConnection panics immediately at construction time. The fix is to set those variables on the host process environment or use a child-process transport.","triggerScenarios":"Calling NewClient with an InProcessConnection while passing WithEnv-style options in ClientOptions (opts.Env != nil) — panics synchronously inside validateEnvironmentOptions.","commonSituations":"Reusing client option helpers written for the child-process transport when switching to in-process; configuring per-client env in tests that embed the runtime; copying setup code that assumed process isolation.","solutions":["Remove the Env option and set the variables on the host process environment before NewClient","Or switch to a child-process connection which owns its OS process and supports per-connection env","If you also set WorkingDirectory or Telemetry, move those to the host process/env as well","Split option sets per transport type so in-process clients never receive env/telemetry options"],"exampleFix":"// before\nclient, err := NewClient(ctx, InProcessConnection{},\n    WithEnv([]string{\"DEBUG=1\"})) // panics\n// after\nos.Setenv(\"DEBUG\", \"1\")\nclient, err := NewClient(ctx, InProcessConnection{})","handlingStrategy":"validation","validationCode":"func newInProcessClient(ctx context.Context, opts ...ClientOption) (*Client, error) {\n    for _, o := range opts {\n        if isEnvOption(o) {\n            return nil, errors.New(\"Env is not supported with InProcessConnection\")\n        }\n    }\n    return NewClient(ctx, InProcessConnection{}, opts...)\n}","typeGuard":"func isChildProcess(c RuntimeConnection) bool {\n    _, ok := c.(InProcessConnection)\n    return !ok // env options only safe when not in-process\n}","tryCatchPattern":"func() (c *Client) {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"invalid client options: %v\", r)\n        }\n    }()\n    c, _ = NewClient(ctx, InProcessConnection{}, opts...)\n    return\n}()","preventionTips":["Maintain separate option builders for in-process vs child-process transports","Set needed env vars on the host process before creating in-process clients","Remember NewClient panics (not returns error) for these invalid combinations — construct early, not lazily"],"tags":["go","configuration","in-process","environment","panic"],"backgroundTag":"conflicting-config-options","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}