forked from olimorris/codecompanion.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodecompanion.txt
More file actions
7939 lines (6013 loc) · 276 KB
/
codecompanion.txt
File metadata and controls
7939 lines (6013 loc) · 276 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
*codecompanion.txt* For NVIM v0.11 Last change: 2026 May 03
==============================================================================
Table of Contents *codecompanion-table-of-contents*
1. Welcome |codecompanion-welcome|
- Features |codecompanion-welcome-features|
- Overview |codecompanion-welcome-overview|
- Supported LLMs and Agents|codecompanion-welcome-supported-llms-and-agents|
2. Installation |codecompanion-installation|
- Requirements |codecompanion-installation-requirements|
- Installation |codecompanion-installation-installation|
- Extensions |codecompanion-installation-extensions|
- Other s |codecompanion-installation-other-s|
- Completion |codecompanion-installation-completion|
- Help |codecompanion-installation-help|
3. Getting Started |codecompanion-getting-started|
- Documentation |codecompanion-getting-started-documentation|
- Interactions |codecompanion-getting-started-interactions|
- Setup |codecompanion-getting-started-setup|
- Usage |codecompanion-getting-started-usage|
- Suggested Workflow |codecompanion-getting-started-suggested-workflow|
4. Architecture |codecompanion-architecture|
- How Context Is Managed |codecompanion-architecture-how-context-is-managed|
5. ACP |codecompanion-acp|
- Implementation |codecompanion-acp-implementation|
- Protocol Version |codecompanion-acp-protocol-version|
- Current Limitations |codecompanion-acp-current-limitations|
- See Also |codecompanion-acp-see-also|
6. MCP |codecompanion-mcp|
- Usage |codecompanion-mcp-usage|
- Implementation |codecompanion-mcp-implementation|
- Protocol Version |codecompanion-mcp-protocol-version|
- See Also |codecompanion-mcp-see-also|
7. Configuration |codecompanion-configuration|
- Action Palette |codecompanion-configuration-action-palette|
- ACP Adapters |codecompanion-configuration-acp-adapters|
- HTTP Adapters |codecompanion-configuration-http-adapters|
- Chat Buffer |codecompanion-configuration-chat-buffer|
- Command-Line Interface (CLI)|codecompanion-configuration-command-line-interface-(cli)|
- Inline Interaction |codecompanion-configuration-inline-interaction|
- MCP Servers |codecompanion-configuration-mcp-servers|
- Rules |codecompanion-configuration-rules|
- Prompt Library |codecompanion-configuration-prompt-library|
- System Prompts |codecompanion-configuration-system-prompts|
- Extensions |codecompanion-configuration-extensions|
- Other Options |codecompanion-configuration-other-options|
8. Usage |codecompanion-usage|
- |codecompanion-usage-|
- Action Palette |codecompanion-usage-action-palette|
- Chat Buffer |codecompanion-usage-chat-buffer|
- Agents and Tools |codecompanion-usage-agents-and-tools|
- Editor Context |codecompanion-usage-editor-context|
- Rules |codecompanion-usage-rules|
- Slash Commands |codecompanion-usage-slash-commands|
- Command-Line Interface (CLI)|codecompanion-usage-command-line-interface-(cli)|
- Events / Hooks |codecompanion-usage-events-/-hooks|
- Inline Interaction |codecompanion-usage-inline-interaction|
- Prompt Library |codecompanion-usage-prompt-library|
- User Interface |codecompanion-usage-user-interface|
- Workflows |codecompanion-usage-workflows|
9. Extending |codecompanion-extending|
- Extending with Adapters |codecompanion-extending-extending-with-adapters|
- Extending with Agentic Workflows|codecompanion-extending-extending-with-agentic-workflows|
- Extending with Extensions|codecompanion-extending-extending-with-extensions|
- Extending with Rules Parsers|codecompanion-extending-extending-with-rules-parsers|
- Extending with Tools |codecompanion-extending-extending-with-tools|
- Extending the UI |codecompanion-extending-extending-the-ui|
==============================================================================
1. Welcome *codecompanion-welcome*
AI Coding, Vim Style
CodeCompanion is a plugin which enables you to code with AI, using LLMs and
agents, in Neovim.
FEATURES *codecompanion-welcome-features*
- Copilot Chat <https://github.com/features/copilot> meets Zed AI <https://zed.dev/blog/zed-ai>, in Neovim
- Integrates Neovim with LLMs and Agents in the CLI
- Support for LLMs from Anthropic, Copilot, GitHub Models, DeepSeek, Gemini, Mistral AI, Novita, Ollama, OpenAI, Azure OpenAI, HuggingFace and xAI out of the box (or bring your own!)
- Support for Agent Client Protocol <https://agentclientprotocol.com/overview/introduction>, enabling coding with agents like Augment Code <https://docs.augmentcode.com/cli/overview>, Cagent <https://github.com/docker/cagent> from Docker, Claude Code <https://docs.anthropic.com/en/docs/claude-code/overview>, Cline CLI <https://docs.cline.bot/home>, Codex <https://openai.com/codex>, Copilot CLI <https://github.com/features/copilot/cli>, Gemini CLI <https://github.com/google-gemini/gemini-cli>, Goose <https://block.github.io/goose/>, Cursor CLI <https://cursor.com/docs/cli/overview>, Kilo Code <https://kilo.ai>, Kimi CLI <https://github.com/MoonshotAI/kimi-cli>, Kiro <https://kiro.dev/cli/>, Mistral Vibe <https://github.com/mistralai/mistral-vibe> and OpenCode <https://opencode.ai>
- User contributed and supported |codecompanion-configuration-adapters-http-community-adapters|
- Support for |codecompanion-model-context-protocol|
- |codecompanion-usage-inline.html|, code creation and refactoring
- |codecompanion-usage-chat-buffer-editor-context|, |codecompanion-usage-chat-buffer-slash-commands|, |codecompanion-usage-chat-buffer-agents-tools| and |codecompanion-usage-workflows| to improve LLM output
- Support for |codecompanion-usage-chat-buffer-rules| files like `CLAUDE.md`, `.cursor/rules` and your own custom ones
- Built-in |codecompanion-usage-action-palette.html| for common tasks like advice on LSP errors and code explanations
- Create your own |codecompanion-configuration-prompt-library-creating-prompts|, Editor Context and Slash Commands
- Have |codecompanion-usage-introduction-quickly-accessing-a-chat-buffer| open at the same time
- Support for |codecompanion-usage-chat-buffer--images-vision| as input
- Async execution for fast performance
OVERVIEW *codecompanion-welcome-overview*
The plugin utilises objects called `interactions`. These are the different ways
that a user can interact with the plugin. The `chat` interaction harnesses a
buffer to allow direct conversation with the LLM. The `inline` interaction
allows for output from the LLM to be written directly into a pre-existing
Neovim buffer.
The plugin allows you to specify adapters for each interaction and also for
each |codecompanion-configuration-prompt-library| entry.
SUPPORTED LLMS AND AGENTS *codecompanion-welcome-supported-llms-and-agents*
CodeCompanion uses |codecompanion-configuration-adapters-http| and
|codecompanion-configuration-adapters-acp| adapters to connect to LLMs and
agents. Out of the box, the plugin supports:
- Anthropic (`anthropic`) - Requires an API key and supports prompt caching <https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching>
- Augment Code (`auggie_cli`) - Requires an API key
- Cagent (`cagent`)
- Claude Code (`claude_code`) - Requires an API key or a Claude Pro subscription
- Cline CLI (`cline_cli`)
- Codex (`codex`) - Requires an API key
- Copilot (`copilot`) - Requires a token which is created via `:Copilot setup` in Copilot.vim <https://github.com/github/copilot.vim>
- DeepSeek (`deepseek`) - Requires an API key
- Gemini (`gemini`) - Requires an API key
- Gemini CLI (`gemini_cli`) - Requires an API key or a Gemini Pro subscription
- GitHub Models (`githubmodels`) - Requires `gh` <https://github.com/cli/cli> to be installed and logged in
- Goose (`goose`) - Requires an API key
- HuggingFace (`huggingface`) - Requires an API key
- Kilo Code (`kilocode`) - Requires an API key
- Kimi (`kimi`) - Moonshot's Kimi K2 family; requires an API key
- Kimi CLI (`kimi_cli`) - Requires an API key
- Mistral AI (`mistral`) - Requires an API key or a Le Chat Pro subscription
- Novita (`novita`) - Requires an API key
- Ollama (`ollama`) - Both local and remotely hosted
- OpenAI (`openai`) - Requires an API key
- opencode (`opencode`) - Requires an API key
- xAI (`xai`) - Requires an API key
In order to add a custom adapter, please refer to the
|codecompanion-extending-adapters| documentation. Also, be sure to check out
the |codecompanion-configuration-adapters-http-community-adapters| section for
user contributed adapters.
==============================================================================
2. Installation *codecompanion-installation*
[!IMPORTANT] To avoid breaking changes, it is recommended to pin the plugin to
a specific release when installing.
REQUIREMENTS *codecompanion-installation-requirements*
- The `curl` library
- Neovim 0.11.0 or greater
- `(Optional)` An API key for your chosen LLM
- `(Optional)` nvim-treesitter <https://github.com/nvim-treesitter/nvim-treesitter> and a `yaml` parser for markdown prompt library items
- `(Optional)` The file <https://man7.org/linux/man-pages/man1/file.1.html> command for detecting image mimetype
- `(Optional)` The ripgrep <https://github.com/BurntSushi/ripgrep> library for the `grep_search` tool
You can run `:checkhealth codecompanion` to verify that all requirements are
met.
INSTALLATION *codecompanion-installation-installation*
The plugin can be installed with the plugin manager of your choice. It is
recommended to pin the plugin to a specific release to avoid breaking changes.
nvim-treesitter <https://github.com/nvim-treesitter/nvim-treesitter> is
required if you plan to use markdown prompts in the
|codecompanion-configuration-prompt-library|, ensuring you have the `yaml`
parser installed.
**Plenary.nvim note:**
As per #377 <https://github.com/olimorris/codecompanion.nvim/issues/377>, if
you pin your plugins to the latest releases, ensure you set plenary.nvim to
follow the master branch
EXTENSIONS *codecompanion-installation-extensions*
CodeCompanion supports extensions that add additional functionality to the
plugin. Below is an example which installs and configures mcphub.nvim
<https://github.com/ravitemer/mcphub.nvim>:
Visit the |codecompanion-extending-extensions| to learn more about available
extensions and how to create your own.
OTHER S *codecompanion-installation-other-s*
CodeCompanion integrates with a number of other plugins to make your AI coding
experience more enjoyable. Below are some common lazy.nvim configurations for
popular plugins:
Use render-markdown.nvim
<https://github.com/MeanderingProgrammer/render-markdown.nvim> or markview.nvim
<https://github.com/OXY2DEV/markview.nvim> to render the markdown in the chat
buffer. Use img-clip.nvim <https://github.com/hakonharnes/img-clip.nvim> to
copy images from your system clipboard into a chat buffer via `:PasteImage`:
COMPLETION *codecompanion-installation-completion*
When in the |codecompanion-usage-chat-buffer-index|, completion can be used to
more easily add |codecompanion-usage-chat-buffer-editor-context|,
|codecompanion-usage-chat-buffer-slash-commands| and
|codecompanion-usage-chat-buffer-agents-tools|. Out of the box, the plugin
supports completion with both nvim-cmp <https://github.com/hrsh7th/nvim-cmp>
and blink.cmp <https://github.com/Saghen/blink.cmp>. For the latter, on version
<= 0.10.0, ensure that you've added `codecompanion` as a source:
>lua
sources = {
per_filetype = {
codecompanion = { "codecompanion" },
}
},
<
The plugin also supports |codecompanion-usage-chat-buffer-index-completion| and
coc.nvim <https://github.com/neoclide/coc.nvim>.
HELP *codecompanion-installation-help*
Consider using the minimal.lua
<https://github.com/olimorris/codecompanion.nvim/blob/main/minimal.lua> file to
troubleshoot, running it with `nvim --clean -u minimal.lua`.
==============================================================================
3. Getting Started *codecompanion-getting-started*
[!IMPORTANT] The default adapter in CodeCompanion is GitHub Copilot
<https://docs.github.com/en/copilot/using-github-copilot/copilot-chat/asking-github-copilot-questions-in-your-ide>.
If you have copilot.vim <https://github.com/github/copilot.vim> or copilot.lua
<https://github.com/zbirenbaum/copilot.lua> installed then expect CodeCompanion
to work out of the box.
This guide is intended to help you get up and running with CodeCompanion and
begin your journey of coding with AI in Neovim. It assumes that you have
already installed the plugin. If you haven't done so, please refer to the
|codecompanion-installation| first.
DOCUMENTATION *codecompanion-getting-started-documentation*
Throughout the documentation you will see examples that are wrapped in a
`require("codecompanion").setup({ })` block. This is purposefully done so that
users can apply them to their own Neovim configuration.
If you're using lazy.nvim <https://github.com/folke/lazy.nvim>, you can simply
apply the examples that you see in this documentation in the `opts` table. For
example, the following code snippet from these docs:
>lua
require("codecompanion").setup({
interactions = {
chat = {
adapter = "anthropic",
model = "claude-sonnet-4-20250514"
},
},
opts = {
log_level = "DEBUG",
},
})
<
can be used in a `lazy.nvim` configuration like so:
>lua
{
"olimorris/codecompanion.nvim",
dependencies = {
"nvim-lua/plenary.nvim"
},
opts = {
interactions = {
chat = {
adapter = "anthropic",
model = "claude-sonnet-4-20250514"
},
},
-- NOTE: The log_level is in `opts.opts`
opts = {
log_level = "DEBUG",
},
},
},
<
INTERACTIONS *codecompanion-getting-started-interactions*
The plugin uses the notion of `interactions` to describe the many different
ways that you can interact with an Agent or LLM from within CodeCompanion.
There are five main types of interactions:
- **Chat** - A chat buffer where you can converse with an LLM (`:CodeCompanionChat`)
- **CLI** - A terminal wrapper around agent CLI tools such a Claude Code or Opencode (`:CodeCompanionCLI`)
- **Inline** - An inline interaction that can write code directly into a buffer (`:CodeCompanion`)
- **Cmd** - Create Neovim commands in the command-line (`:CodeCompanionCmd`)
- **Background** - Runs tasks in the background such as compacting chat messages or generating titles for chats
SETUP *codecompanion-getting-started-setup*
CHAT AND INLINE ~
[!NOTE] The adapters that the plugin supports out of the box can be found here
<https://github.com/olimorris/codecompanion.nvim/tree/main/lua/codecompanion/adapters>.
Or, see the user contributed adapters
|codecompanion-configuration-adapters-http-community-adapters|.
|codecompanion-configuration-adapters-acp| are only supported for the chat
interaction.
The Chat Buffer is where you can converse with an LLM from within a Neovim
buffer. It operates on a single response per turn basis. The inline interaction
enables an LLM to write code directly into a Neovim buffer.
The |codecompanion-usage-chat-buffer-| and |codecompanion-usage-inline|
interactions need an adapter to function. In CodeCompanion terminology, an
adapter is the connection between Neovim and an LLM or agent. CodeCompanion has
two `types` of adapters; HTTP adapters which connect you to an LLM via it's API
and ACP adapters which connect you to an agent via the Agent Client Protocol
<https://agentclientprotocol.com>. CodeCompanion has a number of built-in
adapters
<https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua>
that you can leverage and you can find more details in the respective
|codecompanion-configuration-adapters-http| and
|codecompanion-configuration-adapters-acp| sections of the documentation.
To set an adapter:
>lua
require("codecompanion").setup({
interactions = {
chat = {
-- You can specify an adapter by name and model (both ACP and HTTP)
adapter = {
name = "copilot",
model = "gpt-4.1",
},
},
-- Or, just specify the adapter by name
inline = {
adapter = "anthropic",
},
cmd = {
adapter = "openai",
},
background = {
adapter = {
name = "ollama",
model = "qwen-7b-instruct",
},
},
},
})
<
In the example above, we're using the Copilot adapter for the chat interaction
and the Anthropic one for the inline. We're also using something cheap for the
background adapter (although these interactions are opt-in). You can mix and
match adapters as you see fit for your workflow.
**Setting an API Key**
Because most LLMs require an API key, you'll need to share that with the
adapter. By default, the built-in adapters will look in your environment for a
`*_API_KEY` where `*` is the name of the adapter such as `ANTHROPIC` or
`OPENAI`. Refer to the documentation of the LLM or agent you're using to find
out what the environment variable is called.
You can set/change the API key by using the `extend` function:
>lua
require("codecompanion").setup({
adapters = {
http = {
anthropic = function()
return require("codecompanion.adapters").extend("anthropic", {
env = {
api_key = "MY_OTHER_ANTHROPIC_KEY",
},
})
end,
},
},
})
<
There are numerous ways that environment variables can be set for adapters.
Refer to the |codecompanion-configuration-adapters-http-environment-variables|
section for more information.
CLI ~
The CLI interaction allows you to interact with agents that operate in the
command-line like Claude Code and Opencode. To use CodeCompanion with a CLI
agent, you'll need to configure an agent first:
>lua
require("codecompanion").setup({
interactions = {
cli = {
agent = "claude_code",
agents = {
claude_code = {
cmd = "claude",
args = {},
description = "Claude Code CLI",
provider = "terminal",
},
},
},
},
})
<
In the example above, we're setting up Claude Code in the `agents` table,
specifying the command to run it. Then we're setting it as the default CLI
interaction with `agent = "claude_code"`.
USAGE *codecompanion-getting-started-usage*
The below section has been curated from the lengthier usage documentation to
give you a quick overview of how each feature works.
CHAT ~
Run `:CodeCompanionChat` to open a chat buffer. Type your prompt and send it by
pressing `<C-s>` while in insert mode or `<CR>` in normal mode. Alternatively,
run `:CodeCompanionChat why are Lua and Neovim so perfect together?` to open
the chat buffer and send a prompt at the same time. Toggle the chat buffer with
`:CodeCompanionChat Toggle`.
You can add context from your code base by using `Editor Context` and `Slash
Commands` in the chat buffer.
**Editor Context**
`Editor Context`, accessed via `#` (by default), contain data about the present
state of Neovim. You can find a list of available editor context,
|codecompanion-usage-chat-buffer-editor-context|. The buffer editor context
will automatically link a buffer to the chat buffer, by default, updating the
LLM when the buffer changes.
You can use them in your prompts like:
>
What does the code in #{buffer} do?`
<
**Slash Commands**
[!IMPORTANT] These have been designed to work with native Neovim completions
alongside nvim-cmp and blink.cmp. To open the native completion menu use
`<C-_>` in insert mode when in the chat buffer. Note: Slash commands should
also work with coc.nvim.
`Slash commands`, accessed via `/` (by default), run commands to insert
additional context into the chat buffer. You can find a list of available
commands as well as how to use them,
|codecompanion-usage-chat-buffer-slash-commands.html|.
**Tools**
`Tools`, accessed via `@` (by default), allow the LLM to function as an agent
and leverage external tools. You can find a list of available tools as well as
how to use them,
|codecompanion-usage-chat-buffer-agents-tools-available-tools|.
You can use them in your prompts like:
>
Can you use @{grep_search} to find occurrences of "hello world"
<
CLI ~
Running `:CodeCompanionCLI` will open a new CLI interaction. Running
`:CodeCompanionCLI <your prompt>` will send the prompt to the last CLI
interaction (or create a new one). You can also run `:CodeCompanionCLI Ask` to
use a rich prompt input field complete with |codecompanion--editor-context|.
Save with `:w` to send the prompt to the agent, or `:w!` to send and
auto-submit it.
Adding `!` to the command (e.g. `:CodeCompanionCLI! <prompt>`) will auto-submit
the prompt and keep your cursor in the current buffer. You can also specify
which agent to use with `:CodeCompanionCLI agent=<agent name>`.
INLINE ~
[!NOTE] The diff provider in the video is mini.diff
<https://github.com/echasnovski/mini.diff>
Run `:CodeCompanion your prompt` to call the inline interaction. The
interaction will evaluate the prompt and either write code or open a chat
buffer. You can also make a visual selection and call the inline interaction.
To send additional context alongside your prompt, you can leverage
|codecompanion-usage-inline-editor-context| such as `:CodeCompanion #{buffer}
<your prompt>`.
For convenience, you can call prompts with their `alias` from the prompt
library
<https://github.com/olimorris/codecompanion.nvim/blob/6a4341a4cfe8988a57ad9e8b7dc01ccd6f3e1628/lua/codecompanion/config.lua#L565>
such as `:'<,'>CodeCompanion /explain`. The prompt library comes with the
following presets:
- `/commit` - Generate a commit message
- `/explain` - Explain how selected code in a buffer works
- `/fix` - Fix the selected code
- `/lsp` - Explain the LSP diagnostics for the selected code
- `/tests` - Generate unit tests for selected code
ACTION PALETTE ~
Run `:CodeCompanionActions` to open the action palette, which gives you access
to the plugin's features, including your prompts from the
|codecompanion-configuration-prompt-library|.
By default the plugin uses `vim.ui.select`, however, you can change the
provider by altering the `display.action_palette.provider` config value to be
`telescope`, `mini_pick` or `snacks`. You can also call the Telescope extension
with `:Telescope codecompanion`.
[!NOTE] Some actions and prompts will only be visible if you're in `Visual
mode`.
LIST OF COMMANDS ~
The plugin has five core commands:
- `CodeCompanion` - Open the inline interaction
- `CodeCompanionChat` - Open a chat buffer
- `CodeCompanionCLI` - Open a CLI interaction
- `CodeCompanionCmd` - Generate a command in the command-line
- `CodeCompanionActions` - Open the `Action Palette`
However, there are multiple options available:
- `CodeCompanion <prompt>` - Prompt the inline interaction
- `CodeCompanion adapter=<adapter> <prompt>` - Prompt the inline interaction with a specific adapter
- `CodeCompanion /<prompt library>` - Call an item via its alias from the |codecompanion-configuration-prompt-library|
- `CodeCompanionChat <prompt>` - Send a prompt to the LLM via a chat buffer
- `CodeCompanionChat adapter=<adapter> model=<model>` - Open a chat buffer with a specific http adapter and model
- `CodeCompanionChat adapter=<adapter> command=<command>` - Open a chat buffer with a specific ACP adapter and command
- `CodeCompanionChat Add` - Add visually selected chat to the current chat buffer
- `CodeCompanionChat RefreshCache` - Used to refresh conditional elements in the chat buffer
- `CodeCompanionChat Toggle` - Toggle a chat buffer
- `CodeCompanionCLI` - Open a new CLI interaction
- `CodeCompanionCLI <prompt>` - Send a prompt to the last CLI interaction (or create a new one)
- `CodeCompanionCLI! <prompt>` - Send and auto-submit a prompt, keeping focus in the current buffer
- `CodeCompanionCLI agent=<agent> <prompt>` - Start a new CLI interaction with a specific agent
- `CodeCompanionCLI Ask` - Open the rich input buffer for CLI prompts
SUGGESTED WORKFLOW *codecompanion-getting-started-suggested-workflow*
For an optimum plugin workflow, the author recommends the following:
>lua
vim.keymap.set({ "n", "v" }, "<C-a>", "<cmd>CodeCompanionActions<cr>", { noremap = true, silent = true })
vim.keymap.set({ "n", "v" }, "<LocalLeader>a", "<cmd>CodeCompanionChat Toggle<cr>", { noremap = true, silent = true })
vim.keymap.set("v", "ga", "<cmd>CodeCompanionChat Add<cr>", { noremap = true, silent = true })
-- Expand 'cc' into 'CodeCompanion' in the command line
vim.cmd([[cab cc CodeCompanion]])
<
[!NOTE] You can also assign prompts from the library to specific mappings. See
the |codecompanion-configuration-prompt-library-assigning-prompts-to-a-keymap|
section for more information.
==============================================================================
4. Architecture *codecompanion-architecture*
This section of the documentation covers architectural concepts and design
principles that underpin CodeCompanion's functionality.
This is not mandatory reading for users of CodeCompanion. It may be of interest
to those who are looking to understand some of the technical details of how
CodeCompanion works, or those who are looking to contribute to the project.
HOW CONTEXT IS MANAGED *codecompanion-architecture-how-context-is-managed*
One of the limitations of working with LLMs is that of context, as they have a
finite window with which they can respond to a user's ask. That is, there's
only a certain amount of data that LLMs can reference in order to generate a
response. To equate this to human terms, it can be thought of as working memory
<https://en.wikipedia.org/wiki/Working_memory> and it varies greatly depending
on what model you're using. The context window is measured in tokens
<https://platform.claude.com/docs/en/about-claude/glossary#tokens>.
When a user breaches the context window, the conversation **ends** and it
**cannot** continue. This can be hugely inconvenient in the middle of a coding
session and potentially time consuming to recover from. CodeCompanion has
context awareness which means it can prevent this from happening by taking
**preventative** action.
IN THE CHAT BUFFER ~
[!NOTE] CodeCompanion enables context management by default
If you're using the `openai_responses` or `anthropic` adapters, then
CodeCompanion will use their native server-side compaction capabilities. Please
see their respective documentation here
<https://developers.openai.com/api/docs/guides/compaction> and here
<https://platform.claude.com/docs/en/build-with-claude/compaction> for more
information.
To be updated…
Firstly, CodeCompanion manages context by paying close attention to the number
of tokens in the |codecompanion-usage-chat-buffer-index|, matching them against
a defined trigger threshold in your config, which can be
|codecompanion-configuration-chat-buffer-context-management|.
==============================================================================
5. ACP *codecompanion-acp*
CodeCompanion implements the Agent Client Protocol (ACP)
<https://agentclientprotocol.com/> to enable you to work with coding agents
from within Neovim. ACP is an open standard that enables structured interaction
between clients (like CodeCompanion) and AI agents, providing capabilities such
as session management, file system operations, tool execution, and permission
handling.
This page provides a technical reference for what's supported in CodeCompanion
and how it's been implemented.
IMPLEMENTATION *codecompanion-acp-implementation*
CodeCompanion provides comprehensive support for the ACP specification:
------------------------------------------------------------------------
Feature Category Supported Details
------------------------------ ------------------------- ---------------
Core Protocol ✅ JSON-RPC 2.0,
streaming
responses,
message
buffering
Authentication ✅ Multiple auth
methods,
adapter-level
hooks
Content Types ✅ Text, images,
embedded
resources
File System ✅ Read/write text
files with line
ranges
MCP Integration ✅ Stdio, HTTP,
and SSE
transports
Permissions ✅ Interactive UI
with diff
preview for
tool approval
Session Management ✅ Create, list,
load, and
restore
sessions with
state tracking
Session Modes ✅ Mode switching
Session Models ✅ Select specific
models
Tool Calls ✅ Content blocks,
file diffs,
status updates
Agent Plans ❌ Visual display
of an agent's
execution plan
Terminal Operations ❌ Agent has
access to a
Neovim terminal
------------------------------------------------------------------------
SUPPORTED ADAPTERS ~
Please see the |codecompanion-configuration-adapters-acp| page.
CLIENT CAPABILITIES ~
CodeCompanion advertises the following capabilities to ACP agents:
>lua
{
fs = {
readTextFile = true, -- Read files with optional line ranges
writeTextFile = true -- Write/create files
},
terminal = false -- Terminal operations not supported
}
<
CONTENT TYPES ~
Content Type Send to Agent Receive from Agent
-------------------- --------------- --------------------
Text ✅ ✅
File Diffs N/A ✅
Images ✅ ❌
Audio ❌ ❌
Embedded Resources ❌ ❌
STATE MANAGEMENT ~
Unlike HTTP adapters which are stateless (sending the full conversation history
with each request), ACP adapters are stateful. The agent maintains the
conversation context, so CodeCompanion only sends new messages with each
prompt. Session IDs are tracked throughout the conversation lifecycle.
FILE CONTEXT HANDLING ~
When sending files as embedded resources to agents, CodeCompanion re-reads the
file content rather than using the chat buffer representation. This avoids
HTTP-style `<attachment>` tags that are used for LLM adapters but don't make
sense for ACP agents.
SLASH COMMANDS ~
ACP agents can advertise their own slash commands dynamically. You can access
them with `\command` in the chat buffer. CodeCompanion transforms this to
`/command` before sending your prompt to the agent.
SESSION RESUME ~
If an agent supports the `session/list` capability, you can resume a previous
session using the `/resume` slash command in a fresh chat buffer. This calls
`session/list` to discover previous sessions, then `session/load` to restore
the selected session's conversation history into the chat buffer. See
|codecompanion-usage-chat-buffer-slash-commands-resume| for usage details.
MODEL SELECTION ~
CodeCompanion implements a `session/set_model` method that allows you to select
a model for the current session. This feature is not part of the official ACP
specification
<https://agentclientprotocol.com/protocol/draft/schema#session-set_model> and
is subject to change in future versions.
CLEANUP AND LIFECYCLE ~
CodeCompanion ensures clean disconnection from ACP agents by hooking into
Neovim's `VimLeavePre` autocmd. This guarantees that agent processes are
properly terminated even if Neovim exits unexpectedly.
PROTOCOL VERSION *codecompanion-acp-protocol-version*
CodeCompanion currently implements **ACP Protocol Version 1**.
The protocol version is negotiated during initialization. If an agent selects a
different version, CodeCompanion will log a warning but continue to operate,
following the agent's selected version.
CURRENT LIMITATIONS *codecompanion-acp-current-limitations*
- **Terminal Operations**: The `terminal/*` family of methods (`terminal/create`,
`terminal/output`, `terminal/release`, etc.) are not implemented. CodeCompanion
doesn't advertise terminal capabilities to agents.
- **Agent Plan Rendering**: Plan
<https://agentclientprotocol.com/protocol/agent-plan> updates from agents are
received and logged, but they're not currently rendered in the chat buffer UI.
- **Audio Content**: Audio can't be sent or received
SEE ALSO *codecompanion-acp-see-also*
- Agent Client Protocol Specification <https://agentclientprotocol.com/> - Official ACP documentation
- |codecompanion-configuration-adapters-acp| - Setup instructions for specific agents
- |codecompanion-usage-chat-buffer-agents-tools| - How to interact with agents in chat
==============================================================================
6. MCP *codecompanion-mcp*
CodeCompanion implements the Model Context Protocol (MCP)
<https://modelcontextprotocol.io> to enable you to connect the plugin to
external systems and applications. The plugin only implements a subset of the
full MCP specification, focusing on the features that enable developers to
enhance their coding experience.
USAGE *codecompanion-mcp-usage*
To use MCP servers within CodeCompanion, refer to the
|codecompanion-usage-chat-buffer-agents-tools-mcp| section in the chat buffer
usage section of the documentation.
If |codecompanion-configuration-mcp-enabling-servers|, the servers will be
started when you open a chat buffer for the first time. However, you can use
the |codecompanion-usage-chat-buffer-slash-commands-mcp| to start or stop
servers manually.
IMPLEMENTATION *codecompanion-mcp-implementation*
----------------------------------------------------------------------------
Feature Category Supported Details
------------------------- ----------- --------------------------------------
Transport: Stdio ✅
Transport: Streamable ❌
HTTP
Basic: Cancellation ✅ Timeout and user can cancel manually
Basic: Progress ❌
Basic: Task ❌
Client: Roots ✅ Disabled by default
Client: Sampling ❌
Client: Elicitation ❌
Server: Completion ❌
Server: Pagination ✅
Server: Prompts ❌
Server: Resources ❌
Server: Tools ✅ Currently only supports Text Content
Server: Tool list changed ❌
notification
----------------------------------------------------------------------------
PROTOCOL VERSION *codecompanion-mcp-protocol-version*
CodeCompanion currently supports MCP version **2025-11-25**.
SEE ALSO *codecompanion-mcp-see-also*
- Model Context Protocol Specification <https://modelcontextprotocol.io/specification/2025-11-25> - Official MCP documentation
==============================================================================
7. Configuration *codecompanion-configuration*
This document provides a guide for upgrading from one version of CodeCompanion
to another.
CodeCompanion follows semantic versioning <https://semver.org/> and to avoid
breaking changes, it is recommended to pin the plugin to a specific version in
your Neovim configuration. The |codecompanion-installation| provides more
information on how to do this.
- The Super Diff has now been removed from CodeCompanion (#2600 <https://github.com/olimorris/codecompanion.nvim/pull/2600>)
- CodeCompanion now only supports a built-in diff which is enabled by default (#2600 <https://github.com/olimorris/codecompanion.nvim/pull/2600>), dropping support for Mini.Diff
- The `full_stack_dev` group has been renamed to |codecompanion-usage-chat-buffer-agents-tools-agent| (#2786 <https://github.com/olimorris/codecompanion.nvim/pull/2786>)
- The `next_edit_suggestion` and `list_code_usages` tools have been removed
ADAPTERS
- For the Claude Code adapter to work, you'll need to ensure you have Zed's claude-agent-acp <https://github.com/zed-industries/claude-agent-acp> adapter installed. This has been renamed from `claude-code-acp` in recent weeks (#2779 <https://github.com/olimorris/codecompanion.nvim/pull/2779>)
CONFIG
- Diff keymaps have moved from `interactions.inline.keymaps` to `interactions.shared.keymaps` (#2600 <https://github.com/olimorris/codecompanion.nvim/pull/2600>)
- All diff config has moved to `display.diff` (#2600 <https://github.com/olimorris/codecompanion.nvim/pull/2600>)
- `variables` have been renamed to `editor_context` and the config paths are now `interactions.chat.editor_context` and `interactions.inline.editor_context` (#2719 <https://github.com/olimorris/codecompanion.nvim/pull/2719>)
- Across `editor context`, `slash commands` and `tools`, `callback` has been replaced by `path` for string values (module paths and file paths). `callback` is still used for function values, however
PROMPT LIBRARY
- The location of rules within a prompt library item has changed from `opts.rules` to `rules`:
>markdown
---
name: Oli's test workflow
strategy: chat
description: Workflow test prompt
rules:
- test_rule
---
<
CONFIG
- The biggest change in this release is the renaming of `strategies` to `interactions`. This will only be a breaking change if you specifically reference `codecompanion.strategies` in your configuration. If you do, you'll need to change it to `codecompanion.interactions` (#2485 <https://github.com/olimorris/codecompanion.nvim/pull/2485>)
- Previously, built-in slash commands and tools were stored in `/catalog` folders which have now been renamed to `/builtin`. If you reference these in your configuration you'll need to update the paths accordingly (#2482 <https://github.com/olimorris/codecompanion.nvim/pull/2482>)
- Workspaces have now been removed from the plugin. Please use |codecompanion-configuration-rules| instead.
ADAPTERS
- If you have a custom adapter, you'll need to rename `condition` to be `enabled` on any schema items (#2439 <https://github.com/olimorris/codecompanion.nvim/pull/2439/commits/cb14c7bac869346e2d12b775c4bf258606add569>):
>lua
return {
schema = {
["reasoning.effort"] = {
---@type fun(self: CodeCompanion.HTTPAdapter): boolean
condition = function(self) -- [!code --]
enabled = function(self) -- [!code ++]
--
end,
},
}
}
<
- The default adapters on the **Anthropic** and **Gemini** adapters have changed to `claude-sonnet-4-5-20250929` and `gemini-3-pro-preview`, respectively (#2494 <https://github.com/olimorris/codecompanion.nvim/pull/2494>)
- If you wish to hide the adapters that come with CodeCompanion, `adapters.[acp|http].opts.show_defaults` has been renamed to `adapters.[acp|http].opts.show_presets` for both HTTP and ACP adapters (#2497 <https://github.com/olimorris/codecompanion.nvim/pull/2497>)
CHAT
- Memory has been renamed to rules. Please rename any references to `memory` in your configuration to `rules`. Please refer to the |codecompanion-configuration-rules| documentation for more information (#2440 <https://github.com/olimorris/codecompanion.nvim/pull/2440>)
- The variable and parameter `#{buffer}{watch}` has been renamed to `#{buffer}{diff}`. This better reflects that an LLM receives a diff of buffer changes with each request (#2444 <https://github.com/olimorris/codecompanion.nvim/pull/2444>)
- The variable and parameter `#{buffer}{pin}` has now been renamed to `#{buffer}{all}`. This better reflects that the
entire buffer is sent to the LLM with each request (#2444 <https://github.com/olimorris/codecompanion.nvim/pull/2444>)
—
- Passing an adapter as an argument to `:CodeCompanionChat` is now done with `:CodeCompanionChat adapter=<adapter_name>` (#2437 <https://github.com/olimorris/codecompanion.nvim/pull/2437>)
- If your chat buffer system prompt is still stored at `opts.system_prompt` you'll need to change it to `interactions.chat.opts.system_prompt` (#2484 <https://github.com/olimorris/codecompanion.nvim/pull/2484>)
PROMPT LIBRARY
If you have any prompts defined in your config, you'll need to:
- Rename `opts.short_name` to `opts.alias` for each item in order to allow you to call them with `require("codecompanion").prompt("my_prompt")` or as slash commands in the chat buffer (#2471 <https://github.com/olimorris/codecompanion.nvim/pull/2471>).
>lua
["my custom prompt"] = {
strategy = "chat",
description = "My custom prompt",
opts = {
short_name = "my_prompt", -- [!code --]
alias = "my_prompt", -- [!code ++]
},
prompts = {
-- ...
},
},
<
- Change all workflow prompts, replacing `strategy = "workflow"` with `interaction = "chat"` and specifying `opts.is_workflow = true` (#2487 <https://github.com/olimorris/codecompanion.nvim/pull/2487>).
>lua
["my_workflow"] = {
strategy = "workflow", -- [!code --]
interaction = "chat", -- [!code ++]
description = "My custom workflow",
opts = {
is_workflow = true, -- [!code ++]
},
prompts = {