-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAPI.html
More file actions
2104 lines (2021 loc) · 160 KB
/
Copy pathAPI.html
File metadata and controls
2104 lines (2021 loc) · 160 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC ""
"">
<html><head><meta charset="UTF-8" /><title>API Reference</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="css/highlight.css" /><script type="text/javascript" src="js/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a></h2><h1><a href="index.html"><span class="project-title"><span class="project-name"></span> <span class="project-version"></span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 "><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Topics</span></h3><ul><li class="depth-1 current"><a href="API.html"><div class="inner"><span>API Reference</span></div></a></li><li class="depth-1 "><a href="azure-managed-identity.html"><div class="inner"><span>Azure Managed Identity with BYOK</span></div></a></li><li class="depth-1 "><a href="byok.html"><div class="inner"><span>BYOK (Bring Your Own Key)</span></div></a></li><li class="depth-1 "><a href="codegen.html"><div class="inner"><span>Schema-Driven Code Generation</span></div></a></li><li class="depth-1 "><a href="custom-agents.html"><div class="inner"><span>Custom Agents & Sub-Agent Orchestration</span></div></a></li><li class="depth-1 "><a href="debugging.html"><div class="inner"><span>MCP Server Debugging Guide</span></div></a></li><li class="depth-1 "><a href="getting-started.html"><div class="inner"><span>Getting Started with the Copilot SDK for Clojure</span></div></a></li><li class="depth-1 "><a href="index.html"><div class="inner"><span>Authentication</span></div></a></li><li class="depth-1 "><a href="index.html"><div class="inner"><span>Documentation</span></div></a></li><li class="depth-1 "><a href="overview.html"><div class="inner"><span>Using MCP Servers with the Copilot SDK for Clojure</span></div></a></li><li class="depth-1 "><a href="style.html"><div class="inner"><span>Documentation Style Guide</span></div></a></li><li class="depth-1 "><a href="upstream-doc-gap-matrix.html"><div class="inner"><span>Upstream Documentation Gap Matrix</span></div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1"><div class="no-link"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>github</span></div></div></li><li class="depth-2"><a href="github.copilot-sdk.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>copilot-sdk</span></div></a></li><li class="depth-3 branch"><a href="github.copilot-sdk.client.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>client</span></div></a></li><li class="depth-3"><div class="no-link"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>generated</span></div></div></li><li class="depth-4 branch"><a href="github.copilot-sdk.generated.coerce.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>coerce</span></div></a></li><li class="depth-4"><a href="github.copilot-sdk.generated.event-specs.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>event-specs</span></div></a></li><li class="depth-3 branch"><a href="github.copilot-sdk.helpers.html"><div class="inner"><span class="tree" style="top: -83px;"><span class="top" style="height: 92px;"></span><span class="bottom"></span></span><span>helpers</span></div></a></li><li class="depth-3 branch"><a href="github.copilot-sdk.instrument.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>instrument</span></div></a></li><li class="depth-3 branch"><a href="github.copilot-sdk.logging.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>logging</span></div></a></li><li class="depth-3 branch"><a href="github.copilot-sdk.process.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>process</span></div></a></li><li class="depth-3 branch"><a href="github.copilot-sdk.protocol.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>protocol</span></div></a></li><li class="depth-3 branch"><a href="github.copilot-sdk.session.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>session</span></div></a></li><li class="depth-3 branch"><a href="github.copilot-sdk.specs.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>specs</span></div></a></li><li class="depth-3 branch"><a href="github.copilot-sdk.tool-set.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>tool-set</span></div></a></li><li class="depth-3 branch"><a href="github.copilot-sdk.tools.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>tools</span></div></a></li><li class="depth-3"><a href="github.copilot-sdk.util.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>util</span></div></a></li></ul></div><div class="document" id="content"><div class="doc"><div class="markdown"><h1><a href="#api-reference" id="api-reference"></a>API Reference</h1>
<h2><a href="#helpers-api" id="helpers-api"></a>Helpers API</h2>
<p>The helpers namespace provides simple, stateless query functions with automatic client management.</p>
<pre><code class="language-clojure">(require '[github.copilot-sdk.helpers :as h])
</code></pre>
<h3><a href="#query" id="query"></a><code>query</code></h3>
<pre><code class="language-clojure">(h/query prompt & {:keys [client session timeout-ms]})
</code></pre>
<p>Execute a query and return the response text.</p>
<p><strong>Options:</strong> - <code>:client</code> - Client options map (cli-path, log-level, cwd, env) OR a CopilotClient instance - <code>:session</code> - Session options map (model, system-prompt, tools, etc.) OR a CopilotSession instance - <code>:timeout-ms</code> - Timeout in milliseconds (default: 180000)</p>
<p>When <code>:session</code> is a CopilotSession instance, the query uses that session directly (enabling multi-turn conversations). When <code>:client</code> is a CopilotClient instance, it uses that client directly.</p>
<pre><code class="language-clojure">;; Simple query (shared client, fresh session)
(h/query "What is 2+2?")
;; => "4"
;; With session options
(h/query "Explain monads" :session {:on-permission-request copilot/approve-all :model "claude-sonnet-4.5"})
;; With system prompt
(h/query "Hello" :session {:on-permission-request copilot/approve-all :system-prompt "Be concise."})
;; With explicit client
(copilot/with-client [client {}]
(h/query "What is Clojure?" :client client))
;; With explicit session (multi-turn conversation)
(copilot/with-client [client {}]
(copilot/with-session [session client {:on-permission-request copilot/approve-all}]
(h/query "My name is Alice." :session session)
(h/query "What is my name?" :session session))) ;; context preserved!
</code></pre>
<h3><a href="#query-seq" id="query-seq"></a><code>query-seq!</code></h3>
<pre><code class="language-clojure">(h/query-seq! prompt & {:keys [client session max-events]})
</code></pre>
<p>Execute a query and return a bounded lazy sequence of events with guaranteed cleanup (default: 256 events).</p>
<pre><code class="language-clojure">(->> (h/query-seq! "Tell me a story" :session {:on-permission-request copilot/approve-all :streaming? true})
(filter #(= :copilot/assistant.message_delta (:type %)))
(map #(get-in % [:data :delta-content]))
(run! print))
</code></pre>
<h3><a href="#query-chan" id="query-chan"></a><code>query-chan</code></h3>
<pre><code class="language-clojure">(h/query-chan prompt & {:keys [client session buffer]})
</code></pre>
<p>Execute a query and return a core.async channel of events. Use this when you need an explicit lifecycle or want to stop reading early without leaking session resources.</p>
<pre><code class="language-clojure">(let [ch (h/query-chan "Tell me a story" :session {:on-permission-request copilot/approve-all :streaming? true})]
(go-loop []
(when-let [event (<! ch)]
(when (= :copilot/assistant.message_delta (:type event))
(print (get-in event [:data :delta-content])))
(recur))))
</code></pre>
<h3><a href="#shutdown" id="shutdown"></a><code>shutdown!</code></h3>
<pre><code class="language-clojure">(h/shutdown!)
</code></pre>
<p>Explicitly shutdown the shared client. Safe to call multiple times.</p>
<h3><a href="#client-info" id="client-info"></a><code>client-info</code></h3>
<pre><code class="language-clojure">(h/client-info)
;; => {:client-opts {:log-level :info, ...} :connected? true}
</code></pre>
<p>Get information about the current shared client state. Returns <code>nil</code> if no shared client exists, otherwise a map with <code>:client-opts</code> and <code>:connected?</code> keys.</p>
<hr />
<h2><a href="#copilotclient" id="copilotclient"></a>CopilotClient</h2>
<pre><code class="language-clojure">(require '[github.copilot-sdk :as copilot])
</code></pre>
<h3><a href="#constructor" id="constructor"></a>Constructor</h3>
<pre><code class="language-clojure">(copilot/client options)
</code></pre>
<p><strong>Options:</strong></p>
<table>
<thead>
<tr><th> Key </th><th> Type </th><th> Default </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>:cli-path</code> </td><td> string </td><td> <code>"copilot"</code> </td><td> Path to CLI executable. Falls back to <code>COPILOT_CLI_PATH</code> env var when not set </td></tr>
<tr><td> <code>:cli-args</code> </td><td> vector </td><td> <code>[]</code> </td><td> Extra arguments prepended before SDK-managed flags </td></tr>
<tr><td> <code>:cli-url</code> </td><td> string </td><td> nil </td><td> URL of existing CLI server (e.g., <code>"localhost:8080"</code>). When provided, no CLI process is spawned </td></tr>
<tr><td> <code>:port</code> </td><td> number </td><td> <code>0</code> </td><td> Server port (0 = random) </td></tr>
<tr><td> <code>:use-stdio?</code> </td><td> boolean </td><td> <code>true</code> </td><td> Use stdio transport instead of TCP </td></tr>
<tr><td> <code>:log-level</code> </td><td> keyword </td><td> <code>:info</code> </td><td> One of <code>:none</code> <code>:error</code> <code>:warning</code> <code>:info</code> <code>:debug</code> <code>:all</code> </td></tr>
<tr><td> <code>:auto-start?</code> </td><td> boolean </td><td> <code>true</code> </td><td> Auto-start server on first operation </td></tr>
<tr><td> <code>:auto-restart?</code> </td><td> boolean </td><td> <code>true</code> </td><td> Auto-restart on crash </td></tr>
<tr><td> <code>:notification-queue-size</code> </td><td> number </td><td> <code>4096</code> </td><td> Max queued protocol notifications </td></tr>
<tr><td> <code>:router-queue-size</code> </td><td> number </td><td> <code>4096</code> </td><td> Max queued non-session notifications </td></tr>
<tr><td> <code>:tool-timeout-ms</code> </td><td> number </td><td> <code>120000</code> </td><td> Timeout for tool handlers returning channels </td></tr>
<tr><td> <code>:cwd</code> </td><td> string </td><td> nil </td><td> Working directory for CLI process </td></tr>
<tr><td> <code>:env</code> </td><td> map </td><td> nil </td><td> Environment variables </td></tr>
<tr><td> <code>:github-token</code> </td><td> string </td><td> nil </td><td> GitHub token for authentication. Sets <code>COPILOT_SDK_AUTH_TOKEN</code> env var and passes <code>--auth-token-env</code> flag </td></tr>
<tr><td> <code>:use-logged-in-user?</code> </td><td> boolean </td><td> <code>true</code> </td><td> Use logged-in user auth. Defaults to <code>false</code> when <code>:github-token</code> is provided. Cannot be used with <code>:cli-url</code> </td></tr>
<tr><td> <code>:copilot-home</code> </td><td> string </td><td> nil </td><td> Base directory for Copilot data files. Sets <code>COPILOT_HOME</code> env var on the spawned CLI. (upstream PR #1191) </td></tr>
<tr><td> <code>:tcp-connection-token</code> </td><td> string </td><td> nil </td><td> Connection token for the headless CLI server (TCP only). When the SDK spawns its own CLI in TCP mode and this is omitted, a UUID is generated automatically so the loopback listener is safe by default. The token is sent to the CLI via <code>COPILOT_CONNECTION_TOKEN</code> and forwarded over the wire on the new <code>connect</code> handshake. Rejected when combined with <code>:use-stdio? true</code>. (upstream PR #1176) </td></tr>
<tr><td> <code>:remote?</code> </td><td> boolean </td><td> <code>false</code> </td><td> When <code>true</code>, append <code>--remote</code> to the spawned CLI args so the CLI exposes the session over a GitHub-hosted remote endpoint. Ignored when <code>:cli-url</code> is set. (upstream PR #1192) </td></tr>
<tr><td> <code>:session-idle-timeout-seconds</code> </td><td> integer </td><td> <code>0</code> (disabled) </td><td> Server-wide session idle timeout in seconds. When <code>> 0</code>, append <code>--session-idle-timeout <n></code> to the spawned CLI so idle sessions are cleaned up after the given duration. </td></tr>
<tr><td> <code>:on-list-models</code> </td><td> fn </td><td> nil </td><td> Zero-arg function returning model info maps. Bypasses <code>models.list</code> RPC; does not require <code>start!</code>. Results are cached the same way as RPC results </td></tr>
<tr><td> <code>:telemetry</code> </td><td> map </td><td> nil </td><td> OpenTelemetry export config, applied as environment variables to the <strong>spawned</strong> CLI (ignored when connecting to an existing server via <code>:cli-url</code> or a parent process via <code>:is-child-process?</code>, since no CLI is spawned). When present, enables OTel. Keys (all optional): <code>:otlp-endpoint</code> (OTLP HTTP endpoint), <code>:otlp-protocol</code> (<code>"http/json"</code> or <code>"http/protobuf"</code> — sets <code>OTEL_EXPORTER_OTLP_PROTOCOL</code>), <code>:file-path</code> (write spans to a file), <code>:exporter-type</code> (exporter selection), <code>:source-name</code> (service/source name), <code>:capture-content?</code> (boolean — capture prompt/response content; <strong>off by default for privacy</strong>). See <a href="#observability">Observability</a>. (upstream PR #785, <a href="https://github.com/github/copilot-sdk/pull/1648">PR #1648</a>) </td></tr>
<tr><td> <code>:on-get-trace-context</code> </td><td> fn </td><td> nil </td><td> Zero-arg function returning <code>{:traceparent "..." :tracestate "..."}</code>, called per request (session create/resume and each message send) to propagate a distributed-trace context. Only <code>:traceparent</code> and <code>:tracestate</code> are forwarded. See <a href="#observability">Observability</a> </td></tr>
<tr><td> <code>:is-child-process?</code> </td><td> boolean </td><td> <code>false</code> </td><td> When <code>true</code>, connect via own stdio to a parent Copilot CLI process (no process spawning). Requires <code>:use-stdio?</code> <code>true</code>; mutually exclusive with <code>:cli-url</code> </td></tr>
<tr><td> <code>:session-fs</code> </td><td> map </td><td> nil </td><td> Session filesystem provider config. Keys: <code>:initial-cwd</code> (string, required), <code>:session-state-path</code> (string, required), <code>:conventions</code> (<code>"windows"</code> or <code>"posix"</code>, required). When set, the client calls <code>sessionFs.setProvider</code> on connect and routes filesystem operations through per-session handlers. See <a href="#session-filesystem">Session Filesystem</a> </td></tr>
<tr><td> <code>:mode</code> </td><td> keyword </td><td> <code>:copilot-cli</code> </td><td> Client multitenancy mode: <code>:copilot-cli</code> (default — preserve historical CLI behavior) or <code>:empty</code> (multi-tenant SaaS hosts that must isolate sessions from local machine state). In <code>:empty</code> mode the SDK requires at least one tenant-scoped storage root (<code>:copilot-home</code>, <code>:session-fs</code>, <code>:cli-url</code>, or <code>:is-child-process?</code>), sets <code>COPILOT_DISABLE_KEYTAR=1</code> on the spawned CLI, spreads 10 safe defaults under caller session config, forces <code>installedPlugins []</code>, and normalizes <code>:system-message</code> to strip <code>environment_context</code>. See <a href="#client-mode-empty">Client Mode</a>. (upstream PR #1428) </td></tr>
</tbody>
</table>
<h3><a href="#methods" id="methods"></a>Methods</h3>
<h4><a href="#start" id="start"></a><code>start!</code></h4>
<pre><code class="language-clojure">(copilot/start! client)
</code></pre>
<p>Start the CLI server and establish connection. Blocks until connected.</p>
<h4><a href="#with-client" id="with-client"></a><code>with-client</code></h4>
<pre><code class="language-clojure">(copilot/with-client [client {:log-level :info}]
;; use client
)
</code></pre>
<p>Create a client, start it, and ensure <code>stop!</code> runs on exit.</p>
<h4><a href="#stop" id="stop"></a><code>stop!</code></h4>
<pre><code class="language-clojure">(copilot/stop! client)
</code></pre>
<p>Stop the server and close all sessions gracefully.</p>
<p>For SDK-spawned processes (not <code>:external-server?</code>), <code>stop!</code> issues a <code>runtime.shutdown</code> RPC before closing the connection, giving the CLI a chance to flush state and exit cleanly. The call is bounded by a 10-second timeout; on timeout or error the SDK falls back to terminating the process (SIGTERM, then SIGKILL). Connecting to an external server (<code>:cli-url</code>) skips the shutdown RPC and the process is left running. (upstream <a href="https://github.com/github/copilot-sdk/pull/1667">PR #1667</a>)</p>
<h4><a href="#force-stop" id="force-stop"></a><code>force-stop!</code></h4>
<pre><code class="language-clojure">(copilot/force-stop! client)
</code></pre>
<p>Force stop the CLI server without graceful cleanup. Use when <code>stop!</code> takes too long.</p>
<h4><a href="#client-options" id="client-options"></a><code>client-options</code></h4>
<pre><code class="language-clojure">(copilot/client-options client)
;; => {:log-level :info, :use-stdio? true, :auto-start? true, ...}
</code></pre>
<p>Get the options that were used to create this client.</p>
<h4><a href="#create-session" id="create-session"></a><code>create-session</code></h4>
<pre><code class="language-clojure">(copilot/create-session client config)
</code></pre>
<p>Create a new conversation session.</p>
<h4><a href="#with-session" id="with-session"></a><code>with-session</code></h4>
<pre><code class="language-clojure">(copilot/with-session [session client {:model "gpt-5.4"
:on-permission-request copilot/approve-all}]
;; use session
)
</code></pre>
<p>Create a session and ensure <code>disconnect!</code> runs on exit.</p>
<h4><a href="#with-client-session" id="with-client-session"></a><code>with-client-session</code></h4>
<pre><code class="language-clojure">;; Form 1: [session session-opts] - anonymous client with default options
(copilot/with-client-session [session {:model "gpt-5.4"
:on-permission-request copilot/approve-all}]
;; use session
)
;; Form 2: [client-opts session session-opts] - anonymous client with custom options
(copilot/with-client-session [{:log-level :debug} session {:model "gpt-5.4"
:on-permission-request copilot/approve-all}]
;; use session
)
;; Form 3: [client session session-opts] - named client with default options
(copilot/with-client-session [client session {:model "gpt-5.4"
:on-permission-request copilot/approve-all}]
;; use client and session
)
;; Form 4: [client client-opts session session-opts] - named client with custom options
(copilot/with-client-session [client {:log-level :debug} session {:model "gpt-5.4"
:on-permission-request copilot/approve-all}]
;; use client and session
)
</code></pre>
<p>Create a client and session together, ensuring both are cleaned up on exit.</p>
<p><strong>Config:</strong></p>
<table>
<thead>
<tr><th> Key </th><th> Type </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>:session-id</code> </td><td> string </td><td> Custom session ID (optional) </td></tr>
<tr><td> <code>:client-name</code> </td><td> string </td><td> Client name to identify the application (included in User-Agent header) </td></tr>
<tr><td> <code>:model</code> </td><td> string </td><td> Model to use (<code>"gpt-5.4"</code>, <code>"claude-sonnet-4.5"</code>, etc.) </td></tr>
<tr><td> <code>:tools</code> </td><td> vector </td><td> Custom tools exposed to the CLI </td></tr>
<tr><td> <code>:system-message</code> </td><td> map </td><td> System message customization (see below) </td></tr>
<tr><td> <code>:available-tools</code> </td><td> vector </td><td> List of allowed tool names </td></tr>
<tr><td> <code>:excluded-tools</code> </td><td> vector </td><td> List of excluded tool names </td></tr>
<tr><td> <code>:provider</code> </td><td> map </td><td> Provider config for BYOK (see <a href="../auth/byok.html">BYOK docs</a>). Required key: <code>:base-url</code>. Optional: <code>:provider-type</code> (<code>:openai</code>/<code>:azure</code>/<code>:anthropic</code>), <code>:wire-api</code> (<code>:completions</code>/<code>:responses</code>), <code>:api-key</code>, <code>:bearer-token</code>, <code>:azure-options</code>, <code>:headers</code> (map of HTTP header name→value, sent with each provider request — upstream PR #1094), <code>:model-id</code> (string — the model identifier to send to the provider; overrides session <code>:model</code>), <code>:wire-model</code> (string — model name as sent on the provider wire when it differs from <code>:model-id</code>), <code>:max-input-tokens</code> (integer — input/prompt token cap; serialized as wire <code>maxPromptTokens</code>), <code>:max-output-tokens</code> (integer — output token cap), <code>:transport</code> (<code>:http</code>/<code>:websockets</code> — provider transport; serialized as wire <code>transport</code> — upstream PR #1711), <code>:bearer-token-provider</code> (fn — dynamic bearer-token callback, see <a href="../auth/byok.md#dynamic-bearer-tokens">BYOK docs</a> — upstream PR #1748). The four override fields were added in upstream PR #966 </td></tr>
<tr><td> <code>:providers</code> </td><td> vector </td><td> (Experimental) Multi-provider BYOK registry — a vector of named providers. Each entry takes the connection fields of <code>:provider</code> — <code>:base-url</code> (required), <code>:provider-type</code>, <code>:wire-api</code>, <code>:api-key</code>, <code>:bearer-token</code>, <code>:azure-options</code>, <code>:headers</code>, <code>:bearer-token-provider</code> — plus a required <code>:name</code> (the registry key, no <code>/</code>). Unlike the singular <code>:provider</code>, a named provider does <strong>not</strong> accept <code>:transport</code> or the inline model-override fields (<code>:model-id</code>, <code>:wire-model</code>, <code>:max-input-tokens</code>, <code>:max-output-tokens</code>); model overrides are declared in <code>:models</code> instead. Pairs with <code>:models</code> to declare a model catalog. Cannot be combined with the singular <code>:provider</code>. (upstream PR #1718) </td></tr>
<tr><td> <code>:models</code> </td><td> vector </td><td> (Experimental) Model catalog referencing the <code>:providers</code> registry. Each entry: <code>:id</code> (required, provider-local model id), <code>:provider</code> (required, a <code>:name</code> in <code>:providers</code>), and optional override fields (<code>:model-id</code>, <code>:wire-model</code>, <code>:capabilities</code>, <code>:max-input-tokens</code>, <code>:max-context-window-tokens</code>, <code>:max-output-tokens</code>). The full model selection id is <code>"providerName/id"</code>. (upstream PR #1718) </td></tr>
<tr><td> <code>:capi</code> </td><td> map </td><td> CAPI (Copilot API) session options. <code>{:enable-web-socket-responses boolean}</code> — serialized as wire <code>capi.enableWebSocketResponses</code>. (upstream PR #1711) </td></tr>
<tr><td> <code>:exp-assignments</code> </td><td> map </td><td> (Internal) Opaque experiment flight assignments. Keys are source-defined flight ids and are forwarded verbatim (string keys bypass kebab→camel conversion). Serialized as <code>expAssignments</code>. (upstream PR #1750) </td></tr>
<tr><td> <code>:mcp-servers</code> </td><td> map </td><td> MCP server configs keyed by server ID (see <a href="../mcp/overview.html">MCP docs</a>). Local (stdio) servers: <code>:mcp-command</code>, <code>:mcp-args</code>, <code>:mcp-tools</code>. Remote (HTTP/SSE) servers: <code>:mcp-server-type</code> (<code>:http</code>/<code>:sse</code>), <code>:mcp-url</code>, <code>:mcp-tools</code>. Spec aliases: <code>::mcp-stdio-server</code> = <code>::mcp-local-server</code>, <code>::mcp-http-server</code> = <code>::mcp-remote-server</code> </td></tr>
<tr><td> <code>:commands</code> </td><td> vector </td><td> Command definitions (slash commands). See <a href="#commands">Commands</a> </td></tr>
<tr><td> <code>:custom-agents</code> </td><td> vector </td><td> Custom agent configs. Each agent map: <code>:agent-name</code> (required), <code>:agent-prompt</code> (required), <code>:agent-display-name</code>, <code>:agent-description</code>, <code>:agent-tools</code>, <code>:agent-infer?</code>, <code>:agent-skills</code> (vector of strings), <code>:agent-model</code> (string, e.g. <code>"claude-haiku-4.5"</code>; when set the runtime tries this model for the agent, falling back to the parent session model — upstream PR #1309), <code>:mcp-servers</code> </td></tr>
<tr><td> <code>:default-agent</code> </td><td> map </td><td> Built-in/default agent config. Use <code>{:excluded-tools [...]}</code> to hide tools from the default agent while leaving them available to custom agents </td></tr>
<tr><td> <code>:on-permission-request</code> </td><td> fn </td><td> Permission handler function. <strong>Optional</strong> (upstream PR #1308). When omitted, permission requests are not auto-resolved; resolve them manually via <code>handle-pending-permission-request!</code>. Use <code>copilot/approve-all</code> to approve everything. </td></tr>
<tr><td> <code>:streaming?</code> </td><td> boolean </td><td> Enable streaming deltas </td></tr>
<tr><td> <code>:config-dir</code> </td><td> string </td><td> Override config directory for CLI </td></tr>
<tr><td> <code>:skill-directories</code> </td><td> vector </td><td> Additional skill directories to load </td></tr>
<tr><td> <code>:instruction-directories</code> </td><td> vector </td><td> Additional directories to search for custom instruction files. Forwarded as <code>instructionDirectories</code> on <code>session.create</code> and <code>session.resume</code>. (upstream PR #1190) </td></tr>
<tr><td> <code>:disabled-skills</code> </td><td> vector </td><td> Disable specific skills by name </td></tr>
<tr><td> <code>:large-output</code> </td><td> map </td><td> (Experimental) Tool output handling config. CLI protocol feature, not in official SDK. </td></tr>
<tr><td> <code>:working-directory</code> </td><td> string </td><td> Working directory for the session (tool operations relative to this) </td></tr>
<tr><td> <code>:infinite-sessions</code> </td><td> map </td><td> Infinite session config (see below) </td></tr>
<tr><td> <code>:reasoning-effort</code> </td><td> string </td><td> Reasoning effort level: <code>"low"</code>, <code>"medium"</code>, <code>"high"</code>, or <code>"xhigh"</code> </td></tr>
<tr><td> <code>:github-token</code> </td><td> string </td><td> GitHub token for this session. Sent as <code>gitHubToken</code> on <code>session.create</code>; use this for per-session authentication when one client manages sessions for different GitHub users </td></tr>
<tr><td> <code>:on-user-input-request</code> </td><td> fn </td><td> Handler for <code>ask_user</code> requests (see below) </td></tr>
<tr><td> <code>:hooks</code> </td><td> map </td><td> Lifecycle hooks (see below) </td></tr>
<tr><td> <code>:agent</code> </td><td> string </td><td> Name of a custom agent to activate at session start. Must match a name in <code>:custom-agents</code>. Equivalent to calling <code>agent.select</code> after creation. </td></tr>
<tr><td> <code>:on-event</code> </td><td> fn </td><td> Event handler (1-arg fn receiving event maps). Registered before the RPC call, guaranteeing early events like <code>session.start</code> are not missed. </td></tr>
<tr><td> <code>:on-elicitation-request</code> </td><td> fn </td><td> Handler for elicitation requests from the agent. When provided, advertises <code>requestElicitation=true</code> and handles <code>elicitation.requested</code> broadcast events. Single-arg handler receives an <code>ElicitationContext</code> map with <code>:session-id</code>, <code>:message</code>, <code>:requested-schema</code>, <code>:mode</code>, <code>:elicitation-source</code>, <code>:url</code>. Returns an <code>ElicitationResult</code> map <code>{:action "accept"/"decline"/"cancel" :content {...}}</code>. See <a href="#elicitation-provider">Elicitation Provider</a> </td></tr>
<tr><td> <code>:on-exit-plan-mode</code> </td><td> fn </td><td> Handler for <code>exitPlanMode.request</code> RPCs — invoked when the agent asks to leave plan mode. When provided, advertises <code>requestExitPlanMode=true</code>. Receives the request map; returns the approval result. (upstream PR #1228) </td></tr>
<tr><td> <code>:on-auto-mode-switch</code> </td><td> fn </td><td> Handler for <code>autoModeSwitch.request</code> RPCs — invoked when the agent asks to switch autonomy mode. When provided, advertises <code>requestAutoModeSwitch=true</code>. Receives the request map; returns the approval result. (upstream PR #1228) </td></tr>
<tr><td> <code>:enable-session-telemetry?</code> </td><td> boolean </td><td> Enable/disable the CLI’s <strong>internal</strong> session telemetry (distinct from the client <code>:telemetry</code> OpenTelemetry export). Defaults to enabled for GitHub-authenticated sessions; always disabled when a BYOK <code>:provider</code> is set; defaulted to <code>false</code> in <code>:mode :empty</code> (caller can override). Wire-encoded as <code>enableSessionTelemetry</code>. See <a href="#observability">Observability</a>. (upstream PR #1224) </td></tr>
<tr><td> <code>:create-session-fs-handler</code> </td><td> fn </td><td> Factory for session filesystem providers. Required when <code>:session-fs</code> is set on the client. Called as <code>(factory session)</code>, returns a provider-style map or a low-level handler map. See <a href="#session-filesystem">Session Filesystem</a> </td></tr>
<tr><td> <code>:enable-config-discovery</code> </td><td> boolean </td><td> Auto-discover <code>.mcp.json</code>, <code>.vscode/mcp.json</code>, skills, etc. Instruction files always load regardless. (upstream PR #1044) </td></tr>
<tr><td> <code>:model-capabilities</code> </td><td> map </td><td> Model capabilities override. DeepPartial of model capabilities, e.g. <code>{:model-supports {:supports-vision true}}</code>. (upstream PR #1029) </td></tr>
<tr><td> <code>:include-sub-agent-streaming-events?</code> </td><td> boolean </td><td> Forward streaming events from sub-agents to the parent session’s event stream. Defaults to <code>true</code> on the wire. (upstream PR #1108) </td></tr>
<tr><td> <code>:remote-session</code> </td><td> keyword </td><td> Per-session Mission Control mode: <code>:off</code>, <code>:export</code>, or <code>:on</code>. When omitted, the CLI applies its default. <code>:off</code> disables remote, <code>:export</code> exports session events to Mission Control without enabling remote steering, <code>:on</code> enables both. Forwarded as <code>remoteSession</code>. (upstream PR #1295, CLI 1.0.48) </td></tr>
<tr><td> <code>:cloud</code> </td><td> map </td><td> (create-session only) Creates a remote cloud session. Shape: <code>{:repository {:owner "octocat" :name "hello-world" :branch "main"}}</code> — <code>:owner</code> and <code>:name</code> are required non-blank strings; <code>:branch</code> is optional. Forwarded as <code>cloud.repository.*</code> on <code>session.create</code>. Not accepted on <code>resume-session</code> (matches upstream <code>ResumeSessionConfig</code>). When <code>:cloud</code> is set and <code>:session-id</code> is omitted, the SDK defers id assignment to the server and registers the session under the server-returned id (upstream PR #1479). (upstream PR #1306) </td></tr>
<tr><td> <code>:mcp-oauth-token-storage</code> </td><td> keyword </td><td> Controls where MCP OAuth tokens are persisted. <code>#{:persistent :in-memory}</code>. Default is server-side (persistent). Set to <code>:in-memory</code> in multi-tenant hosts that must not leak tokens to disk. Wire-encoded as <code>mcpOAuthTokenStorage</code>. (upstream PR #1326) </td></tr>
<tr><td> <code>:embedding-cache-storage</code> </td><td> keyword </td><td> <code>#{:persistent :in-memory}</code>. Controls where the embedding cache lives. Wire-encoded as <code>embeddingCacheStorage</code>. (upstream PR #1474) </td></tr>
<tr><td> <code>:skip-embedding-retrieval</code> </td><td> boolean </td><td> Skip embedding-based context retrieval. (upstream PR #1474) </td></tr>
<tr><td> <code>:organization-custom-instructions</code> </td><td> string </td><td> Organization-wide instructions injected by the host. (upstream PR #1474) </td></tr>
<tr><td> <code>:enable-on-demand-instruction-discovery</code> </td><td> boolean </td><td> Auto-discover instruction files on demand. (upstream PR #1474) </td></tr>
<tr><td> <code>:enable-file-hooks</code> </td><td> boolean </td><td> Enable file-watcher-style lifecycle hooks. (upstream PR #1474) </td></tr>
<tr><td> <code>:enable-host-git-operations</code> </td><td> boolean </td><td> Allow the CLI to run git operations through the host. (upstream PR #1474) </td></tr>
<tr><td> <code>:enable-session-store</code> </td><td> boolean </td><td> Enable the disk-backed session store. (upstream PR #1474) </td></tr>
<tr><td> <code>:enable-skills</code> </td><td> boolean </td><td> Enable skills discovery and loading. (upstream PR #1474) </td></tr>
<tr><td> <code>:plugin-directories</code> </td><td> vector </td><td> Extra plugin directories loaded even when <code>:enable-config-discovery</code> is <code>false</code>. Wire-encoded as <code>pluginDirectories</code>. (upstream PR #1482) </td></tr>
<tr><td> <code>:reasoning-summary</code> </td><td> string </td><td> <code>"none"</code> / <code>"concise"</code> / <code>"detailed"</code>. Controls inclusion/granularity of reasoning summaries on assistant turns. Wire-encoded as <code>reasoningSummary</code>. String-valued for consistency with <code>:reasoning-effort</code>. </td></tr>
<tr><td> <code>:context-tier</code> </td><td> keyword | <code>nil</code> </td><td> <code>#{:default :long-context}</code> selects the long-context model variant; <code>nil</code> explicitly clears any prior tier (wire-encoded as JSON <code>null</code>). Omit the key entirely to leave the current setting untouched. Wire-encoded as <code>contextTier</code> with values <code>"default"</code> / <code>"long_context"</code>. </td></tr>
<tr><td> <code>:skip-custom-instructions</code> </td><td> boolean </td><td> Skip loading user-level custom instruction files. Forwarded via <code>session.options.update</code> (NOT <code>session.create</code>). Defaulted to <code>true</code> in <code>:empty</code> mode. (upstream PR #1428) </td></tr>
<tr><td> <code>:custom-agents-local-only</code> </td><td> boolean </td><td> Restrict custom-agent loading to caller-supplied configs only (no on-disk discovery). Forwarded via <code>session.options.update</code>. Defaulted to <code>true</code> in <code>:empty</code> mode. (upstream PR #1428) </td></tr>
<tr><td> <code>:coauthor-enabled</code> </td><td> boolean </td><td> Add a Copilot Co-authored-by trailer to commits made by the CLI. Forwarded via <code>session.options.update</code>. Defaulted to <code>false</code> in <code>:empty</code> mode. (upstream PR #1428) </td></tr>
<tr><td> <code>:manage-schedule-enabled</code> </td><td> boolean </td><td> Enable the built-in schedule-management tools. Forwarded via <code>session.options.update</code>. Defaulted to <code>false</code> in <code>:empty</code> mode. (upstream PR #1428) </td></tr>
<tr><td> <code>:open-canvases</code> </td><td> vector </td><td> (resume-session / join-session only) Seed the open-canvases snapshot when reconnecting. Each entry: <code>{:instance-id ... :extension-id ... :canvas-id ... :reopen bool :availability "ready"\|"stale" :extension-name? ... :title? ... :status? ... :url? ... :input? {...}}</code>. Caller-defined <code>:input</code> keys are preserved verbatim through wire conversion (no kebab→camel re-casing). See <a href="#open-canvases"><code>open-canvases</code></a>. (upstream PR #1604) </td></tr>
<tr><td> <code>:memory</code> </td><td> map </td><td> Persistent-memory configuration. Shape: <code>{:enabled boolean}</code>. Sent on <strong>both</strong> <code>session.create</code> and <code>session.resume</code>; omitted entirely when the key is absent (never wire <code>null</code>). Wire-encoded as <code>memory</code>. In <code>:mode :empty</code> it is defaulted to <code>{:enabled false}</code> (caller can override). (upstream <a href="https://github.com/github/copilot-sdk/pull/1617">PR #1617</a>) </td></tr>
</tbody>
</table>
<h4><a href="#resume-session" id="resume-session"></a><code>resume-session</code></h4>
<pre><code class="language-clojure">(copilot/resume-session client session-id config)
</code></pre>
<p>Resume an existing session by ID. The <code>config</code> map accepts the same options as <code>create-session</code> (except <code>:session-id</code>), including per-session <code>:github-token</code>, plus:</p>
<table>
<thead>
<tr><th> Option </th><th> Type </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>:disable-resume?</code> </td><td> boolean </td><td> When true, skip emitting the session.resume event (default: false) </td></tr>
<tr><td> <code>:continue-pending-work?</code> </td><td> boolean </td><td> When true, the runtime re-emits any pending <code>permission.requested</code> and external tool calls so handlers can re-respond on resume; default false treats pending work as interrupted. Forwarded as <code>continuePendingWork</code> on <code>session.resume</code>. </td></tr>
<tr><td> <code>:large-output</code> </td><td> map </td><td> (Experimental) Tool output handling config. Now also forwarded on <code>session.resume</code> (matching upstream <code>client.ts:1308</code>). </td></tr>
</tbody>
</table>
<p>When <code>:on-permission-request</code> is set to <code>default-join-session-permission-handler</code>, the SDK sends <code>requestPermission: false</code> on the wire, telling the CLI that this client does not handle permission requests. Any other handler sends <code>requestPermission: true</code>.</p>
<pre><code class="language-clojure">;; Resume with a different model and reasoning effort
(copilot/resume-session client "session-123"
{:model "claude-sonnet-4"
:reasoning-effort "high"
:on-permission-request copilot/approve-all})
;; Resume without handling permissions (join-style)
(copilot/resume-session client "session-123"
{:on-permission-request copilot/default-join-session-permission-handler})
</code></pre>
<h4><a href="#create-session" id="create-session"></a><code><create-session</code></h4>
<pre><code class="language-clojure">(copilot/<create-session client config)
</code></pre>
<p>Async version of <code>create-session</code>. Returns a channel that delivers a <code>CopilotSession</code>.</p>
<p>Validation is synchronous (throws immediately on invalid config). The RPC call parks instead of blocking, making this safe inside <code>go</code> blocks. On RPC error, delivers an <code>ExceptionInfo</code> to the channel instead of a session — check with <code>(instance? Throwable result)</code>.</p>
<pre><code class="language-clojure">(require '[clojure.core.async :refer [go <!]])
(go
(let [result (<! (copilot/<create-session client {:model "gpt-5.4"
:on-permission-request copilot/approve-all}))]
(if (instance? Throwable result)
(println "Error:" (ex-message result))
(let [answer (<! (copilot/<send! result {:prompt "Hello"}))]
(println answer)))))
</code></pre>
<h4><a href="#resume-session" id="resume-session"></a><code><resume-session</code></h4>
<pre><code class="language-clojure">(copilot/<resume-session client session-id config)
</code></pre>
<p>Async version of <code>resume-session</code>. Returns a channel that delivers a <code>CopilotSession</code>.</p>
<p>Same config options as <code>resume-session</code>. Safe for use inside <code>go</code> blocks. On RPC error, delivers an <code>ExceptionInfo</code> to the channel — check with <code>(instance? Throwable result)</code>.</p>
<pre><code class="language-clojure">(go
(let [session (<! (copilot/<resume-session client "session-123"
{:on-permission-request copilot/approve-all}))]
;; use resumed session
))
</code></pre>
<h4><a href="#join-session" id="join-session"></a><code>join-session</code></h4>
<pre><code class="language-clojure">(copilot/join-session config)
</code></pre>
<p>Join the current foreground session from an extension running as a child process of the Copilot CLI. Reads the <code>SESSION_ID</code> environment variable, creates a child-process client, and resumes the session with <code>:disable-resume?</code> defaulting to <code>true</code>.</p>
<p>Returns a map with <code>:client</code> and <code>:session</code> keys. The caller is responsible for stopping the client when done.</p>
<p>Throws if <code>SESSION_ID</code> is not set in the environment.</p>
<pre><code class="language-clojure">(let [{:keys [client session]} (copilot/join-session
{:on-permission-request copilot/approve-all
:tools [my-tool]})]
;; use session...
(copilot/stop! client))
</code></pre>
<h4><a href="#ping" id="ping"></a><code>ping</code></h4>
<pre><code class="language-clojure">(copilot/ping client)
(copilot/ping client message)
</code></pre>
<p>Ping the server to check connectivity. Returns <code>{:message "..." :timestamp ... :protocol-version ...}</code>.</p>
<h4><a href="#get-status" id="get-status"></a><code>get-status</code></h4>
<pre><code class="language-clojure">(copilot/get-status client)
</code></pre>
<p>Get CLI status including version and protocol information. Returns <code>{:version "0.0.389" :protocol-version 2}</code>.</p>
<h4><a href="#get-auth-status" id="get-auth-status"></a><code>get-auth-status</code></h4>
<pre><code class="language-clojure">(copilot/get-auth-status client)
</code></pre>
<p>Get current authentication status. Returns:</p>
<pre><code class="language-clojure">{:authenticated? true
:auth-type :user ; :user | :env | :gh-cli | :hmac | :api-key | :token
:host "github.com"
:login "username"
:status-message "Authenticated as username"}
</code></pre>
<h4><a href="#list-models" id="list-models"></a><code>list-models</code></h4>
<pre><code class="language-clojure">(copilot/list-models client)
</code></pre>
<p>List available models with their metadata. Results are cached per client connection. When <code>:on-list-models</code> handler is provided in client options, calls the handler instead of the RPC method (no connection required). Requires authentication (unless <code>:on-list-models</code> is provided). Returns a vector of model info maps:</p>
<pre><code class="language-clojure">[{:id "gpt-5.4"
:name "GPT-5.4"
:vendor "openai"
:family "gpt-5.4"
:version "gpt-5.4"
:max-input-tokens 128000
:max-output-tokens 16384
:preview? false
:model-capabilities {:model-supports {:supports-vision true
:supports-reasoning-effort false}
:model-limits {:max-prompt-tokens 128000
:max-context-window-tokens 128000
:vision-capabilities
{:supported-media-types ["image/png" "image/jpeg"]
:max-prompt-images 10
:max-prompt-image-size 20971520}}}
:model-policy {:policy-state "enabled"
:terms "..."}
:model-billing {:multiplier 1.0
;; Per-token prices (upstream PR #1633), present when the
;; model reports them; keys are optional:
:token-prices {:input-price 0.00000125
:output-price 0.00001
:cache-price 0.0000003125
:long-context {:input-price 0.0000025
:output-price 0.00002}}}
;; Model picker categorization (CLI 1.0.46+):
:model-picker-category "powerful" ;; "lightweight" | "versatile" | "powerful"
:model-picker-price-category "very_high" ;; "low" | "medium" | "high" | "very_high"
;; For models supporting reasoning:
:supported-reasoning-efforts ["low" "medium" "high" "xhigh"]
:default-reasoning-effort "medium"}
...]
</code></pre>
<p>List all models with their billing multiplier:</p>
<pre><code class="language-clojure">(require '[github.copilot-sdk :as copilot])
(copilot/with-client [client]
(doseq [m (copilot/list-models client)]
(println (:id m) (str "x" (get-in m [:model-billing :multiplier])))))
;; prints:
;; gpt-5.4 x1.0
;; claude-sonnet-4.5 x1.0
;; o1 x2.0
;; ...
</code></pre>
<h4><a href="#list-tools" id="list-tools"></a><code>list-tools</code></h4>
<pre><code class="language-clojure">(copilot/list-tools client)
(copilot/list-tools client "gpt-5.4")
</code></pre>
<p>List available tools with their metadata. Pass an optional model string to get model-specific tool overrides.</p>
<pre><code class="language-clojure">(copilot/list-tools client)
;; => [{:name "read_file"
;; :namespaced-name "builtin.read_file"
;; :description "Read a file from disk"
;; :parameters {...}
;; :instructions "..."}
;; ...]
;; Print all tool names
(doseq [tool (copilot/list-tools client)]
(println (:name tool) "-" (:description tool)))
</code></pre>
<p>Each tool info map contains:</p>
<table>
<thead>
<tr><th> Key </th><th> Type </th><th> Required </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>:name</code> </td><td> string </td><td> yes </td><td> Short tool name </td></tr>
<tr><td> <code>:namespaced-name</code> </td><td> string </td><td> no </td><td> Fully qualified tool name </td></tr>
<tr><td> <code>:description</code> </td><td> string </td><td> yes </td><td> Human-readable description </td></tr>
<tr><td> <code>:parameters</code> </td><td> map </td><td> no </td><td> JSON Schema of tool parameters </td></tr>
<tr><td> <code>:instructions</code> </td><td> string </td><td> no </td><td> Usage instructions for the tool </td></tr>
</tbody>
</table>
<h4><a href="#get-quota" id="get-quota"></a><code>get-quota</code></h4>
<pre><code class="language-clojure">(copilot/get-quota client)
</code></pre>
<p>Get account quota information. Returns a map of quota type (string) to quota snapshot maps.</p>
<pre><code class="language-clojure">(copilot/get-quota client)
;; => {"chat" {:entitlement-requests 1000
;; :used-requests 42
;; :remaining-percentage 95.8
;; :overage 0
;; :overage-allowed-with-exhausted-quota? false
;; :reset-date "2025-02-01T00:00:00Z"}}
(let [quotas (copilot/get-quota client)]
(doseq [[type snapshot] quotas]
(println type ":" (:remaining-percentage snapshot) "% remaining")))
</code></pre>
<p>Each quota snapshot map contains:</p>
<table>
<thead>
<tr><th> Key </th><th> Type </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>:entitlement-requests</code> </td><td> number </td><td> Total allowed requests </td></tr>
<tr><td> <code>:used-requests</code> </td><td> number </td><td> Requests used so far </td></tr>
<tr><td> <code>:remaining-percentage</code> </td><td> number </td><td> Percentage of quota remaining </td></tr>
<tr><td> <code>:overage</code> </td><td> number </td><td> Number of requests over quota </td></tr>
<tr><td> <code>:overage-allowed-with-exhausted-quota?</code> </td><td> boolean </td><td> Whether overage is allowed when quota is exhausted </td></tr>
<tr><td> <code>:reset-date</code> </td><td> string (optional) </td><td> ISO 8601 date when quota resets </td></tr>
</tbody>
</table>
<h4><a href="#mcp-config-list-mcp-config-add-mcp-config-update-mcp-config-remove" id="mcp-config-list-mcp-config-add-mcp-config-update-mcp-config-remove"></a><code>mcp-config-list</code> / <code>mcp-config-add!</code> / <code>mcp-config-update!</code> / <code>mcp-config-remove!</code></h4>
<blockquote>
<p><strong>Experimental:</strong> These wrap server-level MCP configuration RPCs and may change.</p>
</blockquote>
<pre><code class="language-clojure">;; List configured MCP servers
(copilot/mcp-config-list client)
;; => {:servers [...]}
;; Add a new MCP server config
(copilot/mcp-config-add! client {:name "my-server"
:command "npx"
:args ["-y" "@modelcontextprotocol/server-filesystem" "/tmp"]
:tools ["*"]})
;; Update an existing config
(copilot/mcp-config-update! client {:name "my-server" :tools ["read_file"]})
;; Remove a config
(copilot/mcp-config-remove! client {:name "my-server"})
</code></pre>
<h4><a href="#state" id="state"></a><code>state</code></h4>
<pre><code class="language-clojure">(copilot/state client)
</code></pre>
<p>Get current connection state: <code>:disconnected</code> | <code>:connecting</code> | <code>:connected</code> | <code>:error</code></p>
<h4><a href="#notifications" id="notifications"></a><code>notifications</code></h4>
<pre><code class="language-clojure">(copilot/notifications client)
</code></pre>
<p>Get a channel that receives non-session notifications. The channel is buffered; notifications are dropped if it fills.</p>
<h4><a href="#on-lifecycle-event" id="on-lifecycle-event"></a><code>on-lifecycle-event</code></h4>
<pre><code class="language-clojure">;; Subscribe to all lifecycle events
(def unsub (copilot/on-lifecycle-event client
(fn [event]
(println (:lifecycle-event-type event) (:session-id event)))))
;; Subscribe to a specific event type
(def unsub (copilot/on-lifecycle-event client :session.created
(fn [event]
(println "New session:" (:session-id event)))))
;; Unsubscribe
(unsub)
</code></pre>
<p>Subscribe to session lifecycle events dispatched by the CLI server. The handler receives an event map with:</p>
<table>
<thead>
<tr><th> Key </th><th> Type </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>:lifecycle-event-type</code> </td><td> keyword </td><td> One of <code>:session.created</code>, <code>:session.deleted</code>, <code>:session.updated</code>, <code>:session.foreground</code>, <code>:session.background</code> </td></tr>
<tr><td> <code>:session-id</code> </td><td> string </td><td> The session ID </td></tr>
<tr><td> <code>:metadata</code> </td><td> map (optional) </td><td> Contains <code>:start-time</code>, <code>:modified-time</code>, and optionally <code>:summary</code> </td></tr>
</tbody>
</table>
<p><strong>Two arities:</strong> - <code>(on-lifecycle-event client handler)</code> — wildcard, receives all lifecycle events - <code>(on-lifecycle-event client event-type handler)</code> — receives only events matching <code>event-type</code></p>
<p>Returns an unsubscribe function. Call it with no arguments to remove the handler.</p>
<p>Handlers are called synchronously on the notification router’s go-loop. Keep handlers fast; offload heavy work to another thread or channel.</p>
<h4><a href="#list-sessions" id="list-sessions"></a><code>list-sessions</code></h4>
<pre><code class="language-clojure">(copilot/list-sessions client)
(copilot/list-sessions client {:repository "owner/repo" :branch "main"})
</code></pre>
<p>List available sessions. Pass an optional filter map to narrow results by context fields.</p>
<p><strong>Filter options:</strong></p>
<table>
<thead>
<tr><th> Key </th><th> Type </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>:cwd</code> </td><td> string </td><td> Filter by working directory </td></tr>
<tr><td> <code>:git-root</code> </td><td> string </td><td> Filter by git repository root </td></tr>
<tr><td> <code>:repository</code> </td><td> string </td><td> Filter by repository (e.g., <code>"owner/repo"</code>) </td></tr>
<tr><td> <code>:branch</code> </td><td> string </td><td> Filter by branch name </td></tr>
</tbody>
</table>
<p>Returns a vector of session metadata maps with <code>:start-time</code> and <code>:modified-time</code> as <code>java.time.Instant</code>. Sessions may include a <code>:context</code> map with the session’s working directory and repository info.</p>
<pre><code class="language-clojure">(copilot/list-sessions client)
;; => [{:session-id "abc-123"
;; :start-time #inst "2025-01-15T10:00:00Z"
;; :modified-time #inst "2025-01-15T10:05:00Z"
;; :summary "Refactoring auth module"
;; :remote? false
;; :context {:cwd "/home/user/project"
;; :git-root "/home/user/project"
;; :repository "owner/repo"
;; :branch "main"}}
;; ...]
</code></pre>
<h4><a href="#get-session-metadata" id="get-session-metadata"></a><code>get-session-metadata</code></h4>
<pre><code class="language-clojure">(copilot/get-session-metadata client session-id)
</code></pre>
<p>Get metadata for a specific session by ID. Returns the session metadata map if found, or <code>nil</code> if the session does not exist. Provides an efficient O(1) lookup instead of calling <code>list-sessions</code> and filtering client-side.</p>
<p>The returned map has the same shape as entries returned by <code>list-sessions</code>: - <code>:session-id</code> — session ID string - <code>:start-time</code> — <code>java.time.Instant</code> when the session was created - <code>:modified-time</code> — <code>java.time.Instant</code> of last modification - <code>:remote?</code> — boolean, true if the session is remote - <code>:summary</code> — optional summary string - <code>:context</code> — optional map with <code>:cwd</code> and optional <code>:git-root</code>, <code>:repository</code>, <code>:branch</code></p>
<pre><code class="language-clojure">(def metadata (copilot/get-session-metadata client "session-abc123"))
;; => {:session-id "session-abc123"
;; :start-time #object[java.time.Instant 0x... "2025-01-15T10:00:00Z"]
;; :modified-time #object[java.time.Instant 0x... "2025-01-15T10:05:00Z"]
;; :remote? false
;; :summary "Refactoring auth module"
;; :context {:cwd "/home/user/project"}}
(copilot/get-session-metadata client "non-existent-id")
;; => nil
</code></pre>
<h4><a href="#delete-session" id="delete-session"></a><code>delete-session!</code></h4>
<pre><code class="language-clojure">(copilot/delete-session! client session-id)
</code></pre>
<p>Delete a session and its data from disk. Unlike <code>disconnect!</code> (which gracefully closes an active session), <code>delete-session!</code> removes persisted session data by ID.</p>
<h4><a href="#get-last-session-id" id="get-last-session-id"></a><code>get-last-session-id</code></h4>
<pre><code class="language-clojure">(copilot/get-last-session-id client)
</code></pre>
<p>Get the ID of the most recently updated session.</p>
<h4><a href="#get-foreground-session-id" id="get-foreground-session-id"></a><code>get-foreground-session-id</code></h4>
<pre><code class="language-clojure">(copilot/get-foreground-session-id client)
</code></pre>
<p>Get the foreground session ID. Returns the session ID or nil. Only applicable in TUI+server mode.</p>
<h4><a href="#set-foreground-session-id" id="set-foreground-session-id"></a><code>set-foreground-session-id!</code></h4>
<pre><code class="language-clojure">(copilot/set-foreground-session-id! client session-id)
</code></pre>
<p>Set the foreground session. Requests the TUI to switch to displaying the specified session. Only applicable in TUI+server mode.</p>
<hr />
<h2><a href="#copilotsession" id="copilotsession"></a>CopilotSession</h2>
<p>Represents a single conversation session.</p>
<h3><a href="#methods" id="methods"></a>Methods</h3>
<h4><a href="#send" id="send"></a><code>send!</code></h4>
<pre><code class="language-clojure">(copilot/send! session options)
</code></pre>
<p>Send a message to the session. Returns immediately with the message ID.</p>
<p><strong>Options:</strong></p>
<table>
<thead>
<tr><th> Key </th><th> Type </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>:prompt</code> </td><td> string </td><td> The message/prompt to send </td></tr>
<tr><td> <code>:attachments</code> </td><td> vector </td><td> File attachments (see below) </td></tr>
<tr><td> <code>:mode</code> </td><td> keyword </td><td> <code>:enqueue</code> or <code>:immediate</code> </td></tr>
<tr><td> <code>:agent-mode</code> </td><td> keyword </td><td> <code>#{:interactive :plan :autopilot :shell}</code>. Per-message agent mode. Wire-encoded as <code>agentMode</code>. (upstream PR #1438) </td></tr>
<tr><td> <code>:display-prompt</code> </td><td> string </td><td> Alternate prompt shown in the timeline UI instead of <code>:prompt</code>. Useful when the model-facing prompt contains machinery or context that should not be surfaced to the end user. Wire-encoded as <code>displayPrompt</code>. (upstream PR #1470) </td></tr>
<tr><td> <code>:request-headers</code> </td><td> map </td><td> Extra HTTP headers (string→string) forwarded to the model provider for this request. Merged with provider-level <code>:headers</code>. (upstream PR #1094) </td></tr>
</tbody>
</table>
<p><strong>Attachment types:</strong></p>
<table>
<thead>
<tr><th> Type </th><th> Required Keys </th><th> Optional Keys </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>:file</code> </td><td> <code>:type</code>, <code>:path</code> </td><td> <code>:display-name</code>, <code>:line-range</code> </td><td> File attachment </td></tr>
<tr><td> <code>:directory</code> </td><td> <code>:type</code>, <code>:path</code> </td><td> <code>:display-name</code>, <code>:line-range</code> </td><td> Directory attachment </td></tr>
<tr><td> <code>:selection</code> </td><td> <code>:type</code>, <code>:file-path</code>, <code>:display-name</code> </td><td> <code>:selection-range</code>, <code>:text</code> </td><td> Code selection attachment </td></tr>
<tr><td> <code>:github-reference</code> </td><td> <code>:type</code>, <code>:number</code>, <code>:title</code>, <code>:reference-type</code>, <code>:state</code>, <code>:url</code> </td><td> — </td><td> GitHub issue, PR, or discussion reference </td></tr>
<tr><td> <code>:blob</code> </td><td> <code>:type</code>, <code>:data</code>, <code>:mime-type</code> </td><td> <code>:display-name</code> </td><td> Inline base64-encoded data (e.g. images) </td></tr>
</tbody>
</table>
<p><code>:line-range</code> is a map with <code>:start</code> and <code>:end</code> line numbers (zero-based) to restrict the attachment to a range of lines:</p>
<pre><code class="language-clojure">(copilot/send! session
{:prompt "Explain this function"
:attachments [{:type :file
:path "/path/to/file.clj"
:line-range {:start 10 :end 25}}]})
</code></pre>
<p>Selection range is a map with <code>:start</code> and <code>:end</code> positions, each containing <code>:line</code> and <code>:character</code>:</p>
<pre><code class="language-clojure">(copilot/send! session
{:prompt "Explain this code"
:attachments [{:type :selection
:file-path "/path/to/file.clj"
:display-name "my-fn"
:selection-range {:start {:line 10 :character 0}
:end {:line 25 :character 0}}
:text "(defn my-fn [...] ...)"}]})
</code></pre>
<h4><a href="#send-and-wait" id="send-and-wait"></a><code>send-and-wait!</code></h4>
<pre><code class="language-clojure">(copilot/send-and-wait! session options)
(copilot/send-and-wait! session options timeout-ms)
</code></pre>
<p>Send a message and block until the session becomes idle. Returns the final assistant message event. Default timeout is <code>300000</code> ms (5 minutes).</p>
<h4><a href="#send-async" id="send-async"></a><code>send-async</code></h4>
<pre><code class="language-clojure">(copilot/send-async session options)
</code></pre>
<p>Send a message and return a core.async channel that receives all events for this message, closing when idle. Safe for use inside <code>go</code> blocks — no blocking operations. Supports <code>:timeout-ms</code> in options (default: <code>300000</code>) to force cleanup on long-running requests.</p>
<h4><a href="#send-async-with-id" id="send-async-with-id"></a><code>send-async-with-id</code></h4>
<pre><code class="language-clojure">(copilot/send-async-with-id session options)
</code></pre>
<p>Send a message and return <code>{:message-id :events-ch}</code> for correlating responses. Supports <code>:timeout-ms</code> in options (default: <code>300000</code>).</p>
<h4><a href="#send" id="send"></a><code><send!</code></h4>
<pre><code class="language-clojure">(copilot/<send! session options)
</code></pre>
<p>Async equivalent of <code>send-and-wait!</code> for use inside <code>go</code> blocks. Returns a channel that yields the final content string. Supports <code>:timeout-ms</code> in options (default: <code>300000</code>).</p>
<p>Combined with <code><create-session</code>, enables fully non-blocking pipelines:</p>
<pre><code class="language-clojure">(go
(let [session (<! (copilot/<create-session client {:model "gpt-5.4"
:on-permission-request copilot/approve-all}))
answer (<! (copilot/<send! session {:prompt "Explain monads"}))]
(println answer)))
</code></pre>
<h4><a href="#send-and-wait" id="send-and-wait"></a><code><send-and-wait!</code></h4>
<pre><code class="language-clojure">(copilot/<send-and-wait! session options)
</code></pre>
<p>Async equivalent of <code>send-and-wait!</code> for use inside <code>go</code> blocks. Returns a channel that yields the final assistant message <strong>event</strong> — the same shape as <code>send-and-wait!</code>’s successful return value (content lives under <code>[:data :content]</code>), or closes with nothing if no assistant message was received. Supports <code>:timeout-ms</code> in options (default: <code>300000</code>, set to <code>nil</code> to disable).</p>
<p>Error semantics differ from <code>send-and-wait!</code>: where <code>send-and-wait!</code> throws on <code>:copilot/session.error</code> or timeout, this variant never surfaces those — the channel closes (delivering the last assistant message if one arrived, otherwise nothing), consistent with <code><send!</code>.</p>
<pre><code class="language-clojure">(go
(let [session (<! (copilot/<create-session client {:on-permission-request copilot/approve-all}))
event (<! (copilot/<send-and-wait! session {:prompt "Explain monads"}))]
(println (get-in event [:data :content]))))
</code></pre>
<p>Use <code><send!</code> when you only need the content string; use <code><send-and-wait!</code> when you need the full event (metadata, id, etc.).</p>
<h4><a href="#events" id="events"></a><code>events</code></h4>
<pre><code class="language-clojure">(copilot/events session)
</code></pre>
<p>Get the core.async <code>mult</code> for session events. Use <code>tap</code> to subscribe:</p>
<pre><code class="language-clojure">(let [ch (chan 100)]
(tap (copilot/events session) ch)
(go-loop []
(when-let [event (<! ch)]
(println event)
(recur))))
</code></pre>
<h4><a href="#events-chan" id="events-chan"></a><code>events->chan</code></h4>
<pre><code class="language-clojure">(copilot/events->chan session {:buffer 256
:xf (filter #(= :copilot/assistant.message (:type %)))})
</code></pre>
<p>Subscribe to session events with optional buffer size and transducer.</p>
<h4><a href="#subscribe-events" id="subscribe-events"></a><code>subscribe-events</code></h4>
<pre><code class="language-clojure">(copilot/subscribe-events session)
</code></pre>
<p>Subscribe to session events. Returns a channel (sliding buffer, size 1024) that receives events. This is a convenience wrapper around <code>(tap (copilot/events session) ch)</code>.</p>
<h5><a href="#event-drop-behavior" id="event-drop-behavior"></a>Event Drop Behavior</h5>
<p>Session events are delivered via core.async <code>mult</code> to a per-subscriber <strong>sliding-buffer</strong> channel. Because a sliding buffer never blocks on <code>put!</code>, <code>mult</code> is never stalled by a slow subscriber. <strong>If a subscriber falls behind and its buffer fills, the oldest buffered events are dropped for that subscriber only</strong> to make room for new ones.</p>
<p>Key points: - <strong>Per-subscriber</strong>: Each subscriber is independent. A slow subscriber drops its own oldest events without affecting delivery to other subscribers. - <strong>Oldest-first</strong>: When the buffer is full, the oldest buffered events are dropped, not the newest — subscribers always see the most recent events. - <strong>Silent</strong>: No error, warning, or indication that a drop occurred. - <strong>Not recoverable</strong>: Dropped events are gone for that subscriber.</p>
<p>With the default 1024 buffer, drops are unlikely unless a subscriber completely stops reading. For most use cases, this is not a concern.</p>
<h4><a href="#unsubscribe-events" id="unsubscribe-events"></a><code>unsubscribe-events!</code></h4>
<pre><code class="language-clojure">(copilot/unsubscribe-events! session ch)
</code></pre>
<p>Unsubscribe a channel from session events.</p>
<h4><a href="#abort" id="abort"></a><code>abort!</code></h4>
<pre><code class="language-clojure">(copilot/abort! session)
</code></pre>
<p>Abort the currently processing message.</p>
<h4><a href="#get-messages" id="get-messages"></a><code>get-messages</code></h4>
<pre><code class="language-clojure">(copilot/get-messages session)
</code></pre>
<p>Get all events/messages from this session.</p>
<h4><a href="#handle-pending-tool-call-handle-pending-tool-call" id="handle-pending-tool-call-handle-pending-tool-call"></a><code>handle-pending-tool-call!</code> / <code><handle-pending-tool-call!</code></h4>
<pre><code class="language-clojure">(copilot/handle-pending-tool-call! session
{:request-id "tool-req-7"
:result "STATUS_OK"})
;; or async:
(copilot/<handle-pending-tool-call! session {:request-id "tool-req-7"
:error "lookup failed"})
</code></pre>
<p>Resolve a tool call that was not auto-handled (because <code>:handler</code> was omitted from <code>define-tool</code>). The args map accepts <code>:request-id</code> plus either <code>:result</code> (string or full result map) or <code>:error</code> (string). Sent on the wire as <code>session.tools.handlePendingToolCall</code>. (upstream PR #1308)</p>
<h4><a href="#handle-pending-permission-request-handle-pending-permission-request" id="handle-pending-permission-request-handle-pending-permission-request"></a><code>handle-pending-permission-request!</code> / <code><handle-pending-permission-request!</code></h4>
<pre><code class="language-clojure">(copilot/handle-pending-permission-request! session
{:request-id "perm-req-3"
:result {:kind :approve-once}})
</code></pre>
<p>Resolve a permission request that was not auto-handled (because <code>:on-permission-request</code> was omitted from the session config). The result map must contain a <code>:kind</code> other than <code>:no-result</code>. Sent on the wire as <code>session.permissions.handlePendingPermissionRequest</code>. (upstream PR #1308)</p>
<h4><a href="#get-current-model" id="get-current-model"></a><code>get-current-model</code></h4>
<pre><code class="language-clojure">(copilot/get-current-model session)
;; => "gpt-5.4"
</code></pre>
<p>Get the current model for this session. Returns the model ID string, or nil if none set.</p>
<h4><a href="#switch-model" id="switch-model"></a><code>switch-model!</code></h4>
<pre><code class="language-clojure">(copilot/switch-model! session "claude-sonnet-4.5")
;; => "claude-sonnet-4.5"
;; With model capabilities override (upstream PR #1029):
(copilot/switch-model! session "gpt-5.4"
{:model-capabilities {:model-supports {:supports-vision true}}})
</code></pre>
<p>Switch the model for this session mid-conversation. Returns the new model ID string, or nil.</p>
<p>Optional opts map: - <code>:reasoning-effort</code> — Reasoning effort level (“low”, “medium”, “high”, “xhigh”) - <code>:reasoning-summary</code> — Reasoning summary mode (“none”, “concise”, “detailed”). Wire-encoded as <code>reasoningSummary</code>. - <code>:context-tier</code> — Context window tier for models that support it: <code>:default</code> or <code>:long-context</code> (upstream PR #1522). Wire-encoded as <code>contextTier</code> with values <code>"default"</code> / <code>"long_context"</code>. - <code>:model-capabilities</code> — Model capabilities override map, e.g. <code>{:model-supports {:supports-vision true}}</code></p>
<h4><a href="#set-model" id="set-model"></a><code>set-model!</code></h4>
<pre><code class="language-clojure">(copilot/set-model! session "claude-sonnet-4.5")
;; => "claude-sonnet-4.5"
</code></pre>
<p>Alias for <code>switch-model!</code>, matching the upstream SDK’s <code>setModel()</code> API.</p>
<pre><code class="language-clojure">(copilot/with-client-session [session {:model "gpt-5.4"
:on-permission-request copilot/approve-all}]
(println "Before:" (copilot/get-current-model session))
(copilot/set-model! session "claude-sonnet-4.5")
(println "After:" (copilot/get-current-model session)))
;; prints:
;; Before: gpt-5.4
;; After: claude-sonnet-4.5
</code></pre>
<h4><a href="#log" id="log"></a><code>log!</code></h4>
<pre><code class="language-clojure">(copilot/log! session "Processing started")
(copilot/log! session "Something went wrong" {:level "error"})
(copilot/log! session "Temporary note" {:ephemeral? true})
</code></pre>
<p>Log a message to the session timeline. Returns the event ID string.</p>
<p><strong>Options (optional map):</strong></p>
<table>
<thead>
<tr><th> Key </th><th> Type </th><th> Default </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>:level</code> </td><td> string </td><td> <code>"info"</code> </td><td> Log severity: <code>"info"</code>, <code>"warning"</code>, or <code>"error"</code> </td></tr>
<tr><td> <code>:ephemeral?</code> </td><td> boolean </td><td> <code>false</code> </td><td> When <code>true</code>, the message is transient and not persisted to disk </td></tr>
</tbody>
</table>
<h4><a href="#disconnect" id="disconnect"></a><code>disconnect!</code></h4>
<pre><code class="language-clojure">(copilot/disconnect! session)
</code></pre>
<p>Disconnect the session and free resources. This is the preferred way to close a session.</p>
<h4><a href="#destroy-deprecated" id="destroy-deprecated"></a><code>destroy!</code> <em>(deprecated)</em></h4>
<pre><code class="language-clojure">(copilot/destroy! session)
</code></pre>
<p><strong>Deprecated.</strong> Use <code>disconnect!</code> instead. <code>destroy!</code> delegates to <code>disconnect!</code> and will be removed in a future release.</p>
<h4><a href="#session-id" id="session-id"></a><code>session-id</code></h4>
<pre><code class="language-clojure">(copilot/session-id session)
</code></pre>
<p>Get the session’s unique identifier.</p>
<h4><a href="#workspace-path" id="workspace-path"></a><code>workspace-path</code></h4>
<pre><code class="language-clojure">(copilot/workspace-path session)
</code></pre>
<p>Get the session workspace path when provided by the CLI (may be nil).</p>
<h4><a href="#session-config" id="session-config"></a><code>session-config</code></h4>
<pre><code class="language-clojure">(copilot/session-config session)
;; => {:model "gpt-5.4", :streaming? true, :reasoning-effort "high", ...}
</code></pre>
<p>Get the configuration that was used to create this session.</p>
<h4><a href="#client" id="client"></a><code>client</code></h4>
<pre><code class="language-clojure">(copilot/client session)
</code></pre>
<p>Get the client that owns this session.</p>
<hr />
<h3><a href="#experimental-rpc-methods" id="experimental-rpc-methods"></a>Experimental RPC Methods</h3>
<blockquote>
<p><strong>Note:</strong> These are experimental APIs wrapping emerging CLI RPC methods. They may change in future releases.</p>
</blockquote>
<pre><code class="language-clojure">(require '[github.copilot-sdk.session :as session])
;; List available skills
(session/skills-list my-session)
;; => {:skills [{:name "update-docs" :source-location "project" ...} ...]}
;; Enable/disable MCP servers
(session/mcp-enable! my-session "my-server")
(session/mcp-disable! my-session "my-server")
;; Get/set agent mode
(session/mode-get my-session)
;; => {:mode "interactive"}
(session/mode-set! my-session "plan")
;; Read/update session plan
(session/plan-read my-session)
;; => {:exists? true :content "# Plan\n..." :file-path "/path/to/plan.md"}
(session/plan-update! my-session "# Updated Plan\n...")
(session/plan-delete! my-session)
;; Workspace file operations
(session/workspace-list-files my-session)
;; => {:files ["notes.md" "data.json"]}
(session/workspace-read-file my-session "notes.md")
;; => {:content "..."}
(session/workspace-create-file! my-session "output.txt" "result data")
;; Custom agent management
(session/agent-list my-session)
;; => {:agents [{:name "researcher" ...} ...]}
(session/agent-select! my-session "researcher")
(session/agent-get-current my-session)
;; => {:name "researcher"}
(session/agent-deselect! my-session)
</code></pre>
<p><strong>Skills</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/skills-list</code> </td><td> List available skills. Returns map with <code>:skills</code>. </td></tr>
<tr><td> <code>session/skills-enable!</code> </td><td> Enable a skill by name. </td></tr>
<tr><td> <code>session/skills-disable!</code> </td><td> Disable a skill by name. </td></tr>
<tr><td> <code>session/skills-reload!</code> </td><td> Reload all skills. </td></tr>
</tbody>
</table>
<p><strong>Queued commands</strong></p>
<p>The CLI emits <code>:copilot/command.queued</code> events when a slash-command is dispatched for client-side execution. Each event carries a <code>:request-id</code> and <code>:command</code>. Clients respond via <code>respond-to-queued-command!</code>:</p>
<pre><code class="language-clojure">;; Inside an event handler that observes :copilot/command.queued
(session/respond-to-queued-command! session
{:request-id (:request-id event-data)
:handled? true
:stop-processing-queue? false})
;; Or, to let the CLI fall back to default handling:
(session/respond-to-queued-command! session
{:request-id (:request-id event-data)
:handled? false})
</code></pre>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/respond-to-queued-command!</code> </td><td> Acknowledge a <code>command.queued</code> event (experimental). </td></tr>
</tbody>
</table>
<p><strong>MCP Servers</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/mcp-list</code> </td><td> List configured MCP servers. </td></tr>
<tr><td> <code>session/mcp-enable!</code> </td><td> Enable an MCP server by name. </td></tr>
<tr><td> <code>session/mcp-disable!</code> </td><td> Disable an MCP server by name. </td></tr>
<tr><td> <code>session/mcp-reload!</code> </td><td> Reload all MCP servers. </td></tr>
</tbody>
</table>
<p><strong>Extensions</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/extensions-list</code> </td><td> List extensions. </td></tr>
<tr><td> <code>session/extensions-enable!</code> </td><td> Enable an extension by ID. </td></tr>
<tr><td> <code>session/extensions-disable!</code> </td><td> Disable an extension by ID. </td></tr>
<tr><td> <code>session/extensions-reload!</code> </td><td> Reload all extensions. </td></tr>
</tbody>
</table>
<p><strong>Mode</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/mode-get</code> </td><td> Get current agent mode. Returns <code>{:mode "interactive"\|"plan"\|"autopilot"}</code>. </td></tr>
<tr><td> <code>session/mode-set!</code> </td><td> Set agent mode. Accepts <code>"interactive"</code>, <code>"plan"</code>, or <code>"autopilot"</code>. </td></tr>
</tbody>
</table>
<p><strong>Plan</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/plan-read</code> </td><td> Read the session plan file. Returns <code>{:exists? :content :file-path}</code>. </td></tr>
<tr><td> <code>session/plan-update!</code> </td><td> Update the plan file content. </td></tr>
<tr><td> <code>session/plan-delete!</code> </td><td> Delete the plan file. </td></tr>
</tbody>
</table>
<p><strong>Workspace</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/workspace-list-files</code> </td><td> List files in the session workspace. Returns <code>{:files [...]}</code>. </td></tr>
<tr><td> <code>session/workspace-read-file</code> </td><td> Read a workspace file by relative path. Returns <code>{:content "..."}</code>. </td></tr>
<tr><td> <code>session/workspace-create-file!</code> </td><td> Create a file in the workspace with given path and content. </td></tr>
</tbody>
</table>
<p><strong>Agents</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/agent-list</code> </td><td> List available custom agents. Returns <code>{:agents [...]}</code>. </td></tr>
<tr><td> <code>session/agent-get-current</code> </td><td> Get the currently selected agent. Returns <code>{:name "..."}</code> or <code>{:name nil}</code>. </td></tr>
<tr><td> <code>session/agent-select!</code> </td><td> Select a custom agent by name. </td></tr>
<tr><td> <code>session/agent-deselect!</code> </td><td> Deselect the current custom agent. </td></tr>
<tr><td> <code>session/agent-reload!</code> </td><td> Reload all custom agents. </td></tr>
</tbody>
</table>
<p><strong>Fleet</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/fleet-start!</code> </td><td> Start parallel sub-sessions. Accepts a params map. </td></tr>
</tbody>
</table>
<p><strong>Other</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/plugins-list</code> </td><td> List plugins. </td></tr>
<tr><td> <code>session/compaction-compact!</code> </td><td> Trigger manual context compaction (uses <code>session.history.compact</code> RPC). </td></tr>
<tr><td> <code>session/history-truncate!</code> </td><td> Trigger manual context truncation. </td></tr>
<tr><td> <code>session/sessions-fork!</code> </td><td> Fork the current session. </td></tr>
<tr><td> <code>session/shell-exec!</code> </td><td> Execute a shell command. </td></tr>
<tr><td> <code>session/shell-kill!</code> </td><td> Kill a running shell process. </td></tr>
</tbody>
</table>
<p><strong>Session Name</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/session-name-get</code> </td><td> Get the session name (or auto-generated summary). Returns <code>{:name "..."}</code>. </td></tr>
<tr><td> <code>session/session-name-set!</code> </td><td> Set the session name (1–100 characters). </td></tr>
</tbody>
</table>
<pre><code class="language-clojure">(session/session-name-get my-session)
;; => {:name "My debugging session"}
(session/session-name-set! my-session "Refactoring auth module")
</code></pre>
<p><strong>Workspace (Extended)</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/workspace-get-workspace</code> </td><td> Get current workspace metadata. Returns <code>{:workspace {...}}</code>. </td></tr>
</tbody>
</table>
<pre><code class="language-clojure">(session/workspace-get-workspace my-session)
;; => {:workspace {:path "/home/user/project" ...}}
</code></pre>
<p><strong>MCP Discovery</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/mcp-discover</code> </td><td> Discover MCP servers in a directory. Accepts optional opts map with <code>:working-directory</code>. </td></tr>
</tbody>
</table>
<pre><code class="language-clojure">(session/mcp-discover my-session)
(session/mcp-discover my-session {:working-directory "/path/to/project"})
</code></pre>
<p><strong>Usage Metrics</strong></p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/usage-get-metrics</code> </td><td> Get usage metrics for the session. </td></tr>
</tbody>
</table>
<pre><code class="language-clojure">(session/usage-get-metrics my-session)
</code></pre>
<p><strong>Remote Sessions</strong> (experimental, upstream PR #1192)</p>
<table>
<thead>
<tr><th> Function </th><th> Description </th></tr>
</thead>
<tbody>
<tr><td> <code>session/remote-enable</code> </td><td> Enable remote steerability for the session. Returns <code>{:url <string?> :remote-steerable <boolean>}</code>. Optional 2-arity <code>opts</code> map accepts <code>:mode</code> set to <code>:off</code>, <code>:export</code>, or <code>:on</code> (upstream CLI 1.0.48-1). </td></tr>
<tr><td> <code>session/remote-disable</code> </td><td> Disable remote steerability for the session. Returns <code>nil</code>. </td></tr>
</tbody>
</table>
<pre><code class="language-clojure">(session/remote-enable my-session)
;; => {:url "https://copilot-remote.test/abc" :remote-steerable true}
;; Optional per-session mode (upstream CLI 1.0.48-1):
;; - :off — disable remote
;; - :export — export session events to Mission Control without remote steering
;; - :on — export + enable remote steering
(session/remote-enable my-session {:mode :export})
;; => {:remote-steerable false}
(session/remote-disable my-session)
;; => nil
</code></pre>
<hr />
<h2><a href="#ui-elicitation" id="ui-elicitation"></a>UI Elicitation</h2>
<p>Request structured user input via interactive dialogs. Check host support before calling.</p>
<pre><code class="language-clojure">(require '[github.copilot-sdk :as copilot])
</code></pre>
<h3><a href="#capabilities" id="capabilities"></a><code>capabilities</code></h3>
<pre><code class="language-clojure">(copilot/capabilities session)
;; => {:ui {:elicitation true}}
</code></pre>
<p>Get the host capabilities map reported when the session was created or resumed.</p>
<h3><a href="#open-canvases" id="open-canvases"></a><code>open-canvases</code></h3>