|
| 1 | +# Remote Sessions |
| 2 | + |
| 3 | +Remote sessions let users access their Copilot session from GitHub web and mobile via [Mission Control](https://github.com). When enabled, the SDK connects each session to Mission Control, producing a URL that can be shared as a link or QR code. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- The user must be authenticated (GitHub token or logged-in user) |
| 8 | +- The session's working directory must be a GitHub repository |
| 9 | + |
| 10 | +## Enabling Remote Sessions |
| 11 | + |
| 12 | +### Always-on (client-level) |
| 13 | + |
| 14 | +Set `remote: true` when creating the client. Every session in a GitHub repo automatically gets a remote URL. |
| 15 | + |
| 16 | +<!-- tabs:start --> |
| 17 | + |
| 18 | +#### **TypeScript** |
| 19 | + |
| 20 | +```typescript |
| 21 | +import { CopilotClient } from "@github/copilot-sdk"; |
| 22 | + |
| 23 | +const client = new CopilotClient({ remote: true }); |
| 24 | +const session = await client.createSession({ |
| 25 | + workingDirectory: "/path/to/github-repo", |
| 26 | + onPermissionRequest: async () => ({ allowed: true }), |
| 27 | +}); |
| 28 | + |
| 29 | +session.on("session.info", (event) => { |
| 30 | + if (event.data.infoType === "remote") { |
| 31 | + console.log("Remote URL:", event.data.url); |
| 32 | + } |
| 33 | +}); |
| 34 | +``` |
| 35 | + |
| 36 | +#### **Python** |
| 37 | + |
| 38 | +```python |
| 39 | +from copilot import CopilotClient, SubprocessConfig |
| 40 | + |
| 41 | +client = CopilotClient(SubprocessConfig(remote=True)) |
| 42 | +session = await client.create_session( |
| 43 | + working_directory="/path/to/github-repo", |
| 44 | + on_permission_request=lambda req: {"allowed": True}, |
| 45 | +) |
| 46 | + |
| 47 | +def on_event(event): |
| 48 | + if event.type == "session.info" and event.data.info_type == "remote": |
| 49 | + print(f"Remote URL: {event.data.url}") |
| 50 | + |
| 51 | +session.on(on_event) |
| 52 | +``` |
| 53 | + |
| 54 | +#### **Go** |
| 55 | + |
| 56 | +```go |
| 57 | +client, _ := copilot.NewClient(&copilot.ClientOptions{Remote: true}) |
| 58 | +session, _ := client.CreateSession(ctx, &copilot.SessionConfig{ |
| 59 | + WorkingDirectory: "/path/to/github-repo", |
| 60 | + OnPermissionRequest: func(req copilot.PermissionRequest) copilot.PermissionResponse { |
| 61 | + return copilot.PermissionResponse{Allowed: true} |
| 62 | + }, |
| 63 | +}) |
| 64 | + |
| 65 | +session.On(func(event copilot.SessionEvent) { |
| 66 | + if event.Type == "session.info" { |
| 67 | + // Check infoType and extract URL |
| 68 | + } |
| 69 | +}) |
| 70 | +``` |
| 71 | + |
| 72 | +#### **C#** |
| 73 | + |
| 74 | +```csharp |
| 75 | +var client = new CopilotClient(new CopilotClientOptions { Remote = true }); |
| 76 | +var session = await client.CreateSessionAsync(new SessionConfig |
| 77 | +{ |
| 78 | + WorkingDirectory = "/path/to/github-repo", |
| 79 | + OnPermissionRequest = async (req, ct) => new() { Allowed = true }, |
| 80 | +}); |
| 81 | + |
| 82 | +session.On((SessionEvent e) => |
| 83 | +{ |
| 84 | + if (e is SessionInfoEvent info && info.Data.InfoType == "remote") |
| 85 | + { |
| 86 | + Console.WriteLine($"Remote URL: {info.Data.Url}"); |
| 87 | + } |
| 88 | +}); |
| 89 | +``` |
| 90 | + |
| 91 | +<!-- tabs:end --> |
| 92 | + |
| 93 | +### On-demand (per-session toggle) |
| 94 | + |
| 95 | +Use `session.rpc.remote.enable()` to start remote access mid-session, and `session.rpc.remote.disable()` to stop it. This is equivalent to the CLI's `/remote on` and `/remote off` commands. |
| 96 | + |
| 97 | +<!-- tabs:start --> |
| 98 | + |
| 99 | +#### **TypeScript** |
| 100 | + |
| 101 | +```typescript |
| 102 | +const result = await session.rpc.remote.enable(); |
| 103 | +console.log("Remote URL:", result.url); |
| 104 | + |
| 105 | +// Later: stop sharing |
| 106 | +await session.rpc.remote.disable(); |
| 107 | +``` |
| 108 | + |
| 109 | +#### **Python** |
| 110 | + |
| 111 | +```python |
| 112 | +result = await session.rpc.remote.enable() |
| 113 | +print(f"Remote URL: {result.url}") |
| 114 | + |
| 115 | +# Later: stop sharing |
| 116 | +await session.rpc.remote.disable() |
| 117 | +``` |
| 118 | + |
| 119 | +#### **Go** |
| 120 | + |
| 121 | +```go |
| 122 | +result, err := session.RPC.Remote.Enable(ctx) |
| 123 | +fmt.Println("Remote URL:", *result.URL) |
| 124 | + |
| 125 | +// Later: stop sharing |
| 126 | +err = session.RPC.Remote.Disable(ctx) |
| 127 | +``` |
| 128 | + |
| 129 | +#### **C#** |
| 130 | + |
| 131 | +```csharp |
| 132 | +var result = await session.Rpc.Remote.EnableAsync(); |
| 133 | +Console.WriteLine($"Remote URL: {result.Url}"); |
| 134 | + |
| 135 | +// Later: stop sharing |
| 136 | +await session.Rpc.Remote.DisableAsync(); |
| 137 | +``` |
| 138 | + |
| 139 | +<!-- tabs:end --> |
| 140 | + |
| 141 | +## QR Code Generation |
| 142 | + |
| 143 | +The remote URL can be rendered as a QR code for easy mobile access. The SDK provides the URL — use your preferred QR code library: |
| 144 | + |
| 145 | +- **TypeScript**: [qrcode](https://www.npmjs.com/package/qrcode) |
| 146 | +- **Python**: [qrcode](https://pypi.org/project/qrcode/) |
| 147 | +- **Go**: [go-qrcode](https://github.com/skip2/go-qrcode) |
| 148 | +- **C#**: [QRCoder](https://www.nuget.org/packages/QRCoder) |
| 149 | + |
| 150 | +## Notes |
| 151 | + |
| 152 | +- The `remote` client option only applies when the SDK spawns the CLI process. It is ignored when connecting to an external server via `cliUrl`. |
| 153 | +- If the working directory is not a GitHub repository, remote setup is silently skipped (always-on mode) or returns an error (on-demand mode). |
| 154 | +- Remote sessions require authentication. Ensure `gitHubToken` or `useLoggedInUser` is configured. |
0 commit comments