From 2385effaf3ca44f83f8956d3e318f031788067ae Mon Sep 17 00:00:00 2001 From: MarkXian Date: Sat, 1 Aug 2026 16:52:20 +0800 Subject: [PATCH] docs(dotnet): clarify working directory fallback --- dotnet/README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/dotnet/README.md b/dotnet/README.md index 1971c2107..9e5f3e234 100644 --- a/dotnet/README.md +++ b/dotnet/README.md @@ -84,7 +84,7 @@ new CopilotClient(CopilotClientOptions? options = null) - `Connection` - How to connect to the Copilot runtime. Defaults to `null` (equivalent to `RuntimeConnection.ForStdio()` with the bundled runtime). See "RuntimeConnection" below. - `LogLevel` - Runtime log level. Accepts well-known values `CopilotLogLevel.None`, `Error`, `Warning`, `Info`, `Debug`, `All`. Defaults to null (the runtime's own default). -- `WorkingDirectory` - Working directory for the runtime process. +- `WorkingDirectory` - Working directory for the runtime process. When not set, the spawned runtime inherits the calling application's current working directory. - `BaseDirectory` - Base directory for Copilot data (session state, config, etc.). Sets `COPILOT_HOME` on the spawned runtime process. When not set, the runtime defaults to `~/.copilot`. Useful in restricted environments where only specific directories are writable. Ignored when connecting via `RuntimeConnection.ForUri(...)`. - `EnableRemoteSessions` - Enables remote-session features. - `Environment` - Environment variables to pass to the runtime process. @@ -131,11 +131,34 @@ Create a new conversation session. - `Provider` - Custom API provider configuration (BYOK) - `Streaming` - Enable streaming of response chunks (default: false) - `InfiniteSessions` - Configure automatic context compaction (see below) +- `WorkingDirectory` - Working directory for the session. When not set, the runtime uses its own process working directory. +- `EnableConfigDiscovery` - Enables runtime discovery of supported configuration. Set to `false` to avoid loading project or user configuration for the session. - `EnableSessionStore` - Enables the cross-session store for search and retrieval across sessions. When unset in `CopilotClientMode.CopilotCli`, the runtime default applies (enabled). In `CopilotClientMode.Empty`, defaults to disabled. - `OnPermissionRequest` - Optional handler called before each tool execution to approve or deny it. When omitted, permission requests are emitted as events and left pending for manual resolution. `PermissionHandler.ApproveAll` approves requests when managed settings are disabled and throws when `EnableManagedSettings` is true. Custom handlers can inspect `ManagedApprovalRequired` for human-facing confirmation logic. See [Permission Handling](#permission-handling) section. - `OnUserInputRequest` - Handler for user input requests from the agent (enables ask_user tool). See [User Input Requests](#user-input-requests) section. - `Hooks` - Hook handlers for session lifecycle events. See [Session Hooks](#session-hooks) section. +`CopilotClientOptions.WorkingDirectory` and `SessionConfig.WorkingDirectory` control different working directories. The client option controls the OS working directory for the spawned runtime process. The session option is sent to the runtime as the session working directory. If the session value is `null`, the runtime falls back to its process working directory, so a desktop or debug app may pick up the application's binary directory. + +For a project-neutral chat, set both values to a stable neutral directory and disable config discovery: + +```csharp +var neutralDirectory = Path.GetTempPath(); + +var client = new CopilotClient(new CopilotClientOptions +{ + WorkingDirectory = neutralDirectory +}); + +var session = await client.CreateSessionAsync(new SessionConfig +{ + WorkingDirectory = neutralDirectory, + EnableConfigDiscovery = false +}); +``` + +Use the same `WorkingDirectory` and `EnableConfigDiscovery` values with `ResumeSessionConfig` when resuming the session to keep the context stable. + ##### `ResumeSessionAsync(string sessionId, ResumeSessionConfig? config = null): Task` Resume an existing session. Returns the session with `WorkspacePath` populated if infinite sessions were enabled.