{"record":{"id":"481867ec2de2da68","repo":"github/copilot-sdk","slug":"githubtoken-and-useloggedinuser-cannot-be-combined","errorCode":null,"errorMessage":"GitHubToken and UseLoggedInUser cannot be combined with RuntimeConnection.ForUri (the existing runtime manages its own auth).","messagePattern":"GitHubToken and UseLoggedInUser cannot be combined with RuntimeConnection\\.ForUri \\(the existing runtime manages its own auth\\)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Client.cs","lineNumber":177,"sourceCode":"\n            case TcpRuntimeConnection tcp:\n                if (tcp.ConnectionToken is { Length: 0 })\n                {\n                    throw new ArgumentException(\"ConnectionToken must be a non-empty string or null.\", nameof(options));\n                }\n                // Auto-generate a connection token when the SDK spawns the runtime over TCP\n                // so the loopback listener is safe by default.\n                tcp.ConnectionToken ??= Guid.NewGuid().ToString();\n                break;\n\n            case UriRuntimeConnection uri:\n                if (string.IsNullOrEmpty(uri.Url))\n                {\n                    throw new ArgumentException(\"UriRuntimeConnection.Url must be a non-empty string.\", nameof(options));\n                }\n                if (!string.IsNullOrEmpty(_options.GitHubToken) || _options.UseLoggedInUser != null)\n                {\n                    throw new ArgumentException(\"GitHubToken and UseLoggedInUser cannot be combined with RuntimeConnection.ForUri (the existing runtime manages its own auth).\", nameof(options));\n                }\n                var parsed = ParseRuntimeUrl(uri.Url);\n                _optionsHost = parsed.Host.Trim('[', ']');\n                _optionsPort = parsed.Port;\n                break;\n\n            default:\n                throw new ArgumentException($\"Unsupported RuntimeConnection type: {_connection.GetType().Name}\", nameof(options));\n        }\n\n        ValidateEnvironmentOptions(_options, _connection);\n\n        _logger = _options.Logger ?? NullLogger.Instance;\n        _onListModels = _options.OnListModels;\n\n        _clientGlobalApis = BuildClientGlobalApis();\n\n        // Empty mode: validate at construction time that the app supplied a","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Client.cs#L159-L195","documentation":"When using RuntimeConnection.ForUri (an external, already-running runtime), the SDK must not supply auth because the existing runtime manages its own authentication. Combining GitHubToken or UseLoggedInUser with a UriRuntimeConnection is rejected with ArgumentException.","triggerScenarios":"new CopilotClient(options) where options.Connection is a UriRuntimeConnection AND options.GitHubToken is non-empty OR options.UseLoggedInUser is set.","commonSituations":"Sharing one options-builder for both in-process and external-runtime modes; leftover GitHubToken from a previous auth setup; enabling UseLoggedInUser for local dev then pointing at an external runtime.","solutions":["Remove GitHubToken and UseLoggedInUser from options when using RuntimeConnection.ForUri","Use separate options objects for external-runtime vs SDK-managed modes","Set GitHubToken to null (not just empty-looking values) for the URI mode"],"exampleFix":"// before\noptions.Connection = RuntimeConnection.ForUri(url);\noptions.GitHubToken = token;\n// after\noptions.Connection = RuntimeConnection.ForUri(url); // auth handled by the external runtime","handlingStrategy":"validation","validationCode":"if (options.Connection is UriRuntimeConnection && (!string.IsNullOrEmpty(options.GitHubToken) || options.UseLoggedInUser != null)) throw new InvalidOperationException(\"GitHubToken/UseLoggedInUser are not allowed with RuntimeConnection.ForUri\");","typeGuard":null,"tryCatchPattern":"try { client = new CopilotClient(options); } catch (ArgumentException ex) when (ex.Message.Contains(\"RuntimeConnection.ForUri\")) { options.GitHubToken = null; options.UseLoggedInUser = null; client = new CopilotClient(options); }","preventionTips":["Keep separate options builders for external-runtime vs SDK-managed modes","Strip auth fields whenever Connection is ForUri","Document auth ownership (external runtime) in options setup code"],"tags":["dotnet","auth","config"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}