Skip to content

Commit f7b7f50

Browse files
CopilotfriggeriSteveSandersonMS
authored
Document external CLI server connection (#103)
* Initial plan * Add documentation for connecting to external CLI server Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com> * Apply suggestions from code review * Apply suggestions from code review --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com> Co-authored-by: Steve Sanderson <SteveSandersonMS@users.noreply.github.com>
1 parent 41f0071 commit f7b7f50

File tree

2 files changed

+102
-1
lines changed

2 files changed

+102
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Your Application
4545
Copilot CLI (server mode)
4646
```
4747

48-
The SDK manages the CLI process lifecycle automatically. You can also connect to an external CLI server—see individual SDK docs for details.
48+
The SDK manages the CLI process lifecycle automatically. You can also connect to an external CLI server—see the [Getting Started Guide](./docs/getting-started.md#connecting-to-an-external-cli-server) for details on running the CLI in server mode.
4949

5050
## FAQ
5151

docs/getting-started.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,107 @@ const session = await client.createSession({
864864

865865
---
866866

867+
## Connecting to an External CLI Server
868+
869+
By default, the SDK automatically manages the Copilot CLI process lifecycle, starting and stopping the CLI as needed. However, you can also run the CLI in server mode separately and have the SDK connect to it. This can be useful for:
870+
871+
- **Debugging**: Keep the CLI running between SDK restarts to inspect logs
872+
- **Resource sharing**: Multiple SDK clients can connect to the same CLI server
873+
- **Development**: Run the CLI with custom settings or in a different environment
874+
875+
### Running the CLI in Server Mode
876+
877+
Start the CLI in server mode using the `--server` flag and optionally specify a port:
878+
879+
```bash
880+
copilot --server --port 4321
881+
```
882+
883+
If you don't specify a port, the CLI will choose a random available port.
884+
885+
### Connecting the SDK to the External Server
886+
887+
Once the CLI is running in server mode, configure your SDK client to connect to it using the "cli url" option:
888+
889+
<details open>
890+
<summary><strong>Node.js / TypeScript</strong></summary>
891+
892+
```typescript
893+
import { CopilotClient } from "@github/copilot-sdk";
894+
895+
const client = new CopilotClient({
896+
cliUrl: "localhost:4321"
897+
});
898+
899+
// Use the client normally
900+
const session = await client.createSession();
901+
// ...
902+
```
903+
904+
</details>
905+
906+
<details>
907+
<summary><strong>Python</strong></summary>
908+
909+
```python
910+
from copilot import CopilotClient
911+
912+
client = CopilotClient({
913+
"cli_url": "localhost:4321"
914+
})
915+
await client.start()
916+
917+
# Use the client normally
918+
session = await client.create_session()
919+
# ...
920+
```
921+
922+
</details>
923+
924+
<details>
925+
<summary><strong>Go</strong></summary>
926+
927+
```go
928+
import copilot "github.com/github/copilot-sdk/go"
929+
930+
client := copilot.NewClient(&copilot.ClientOptions{
931+
CLIUrl: "localhost:4321",
932+
})
933+
934+
if err := client.Start(); err != nil {
935+
log.Fatal(err)
936+
}
937+
defer client.Stop()
938+
939+
// Use the client normally
940+
session, err := client.CreateSession()
941+
// ...
942+
```
943+
944+
</details>
945+
946+
<details>
947+
<summary><strong>.NET</strong></summary>
948+
949+
```csharp
950+
using GitHub.Copilot.SDK;
951+
952+
using var client = new CopilotClient(new CopilotClientOptions
953+
{
954+
CliUrl = "localhost:4321"
955+
});
956+
957+
// Use the client normally
958+
await using var session = await client.CreateSessionAsync();
959+
// ...
960+
```
961+
962+
</details>
963+
964+
**Note:** When `cli_url` / `cliUrl` / `CLIUrl` is provided, the SDK will not spawn or manage a CLI process - it will only connect to the existing server at the specified URL.
965+
966+
---
967+
867968
## Learn More
868969

869970
- [Node.js SDK Reference](../nodejs/README.md)

0 commit comments

Comments
 (0)