Skip to content

Commit d188af9

Browse files
authored
feat(chat): allow users to send a btw message (#3060)
1 parent 0bc4868 commit d188af9

6 files changed

Lines changed: 253 additions & 56 deletions

File tree

doc/codecompanion.txt

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*codecompanion.txt* For NVIM v0.11 Last change: 2026 April 21
1+
*codecompanion.txt* For NVIM v0.11 Last change: 2026 April 23
22

33
==============================================================================
44
Table of Contents *codecompanion-table-of-contents*
@@ -496,9 +496,9 @@ use a rich prompt input field complete with |codecompanion--editor-context|.
496496
Save with `:w` to send the prompt to the agent, or `:w!` to send and
497497
auto-submit it.
498498

499-
Adding `!` to the command (e.g. `:CodeCompanionCLI! <prompt>`) will
500-
auto-submit the prompt and keep your cursor in the current buffer. You can also
501-
specify which agent to use with `:CodeCompanionCLI agent=<agent name>`.
499+
Adding `!` to the command (e.g. `:CodeCompanionCLI! <prompt>`) will auto-submit
500+
the prompt and keep your cursor in the current buffer. You can also specify
501+
which agent to use with `:CodeCompanionCLI agent=<agent name>`.
502502

503503

504504
INLINE ~
@@ -591,7 +591,7 @@ For an optimum plugin workflow, the author recommends the following:
591591
4. Architecture *codecompanion-architecture*
592592

593593
This section of the documentation covers architectural concepts and design
594-
principles that underpin CodeCompanions functionality.
594+
principles that underpin CodeCompanion's functionality.
595595

596596
This is not mandatory reading for users of CodeCompanion. It may be of interest
597597
to those who are looking to understand some of the technical details of how
@@ -601,11 +601,11 @@ CodeCompanion works, or those who are looking to contribute to the project.
601601
HOW CONTEXT IS MANAGED *codecompanion-architecture-how-context-is-managed*
602602

603603
One of the limitations of working with LLMs is that of context, as they have a
604-
finite window with which they can respond to a users ask. That is, theres
604+
finite window with which they can respond to a user's ask. That is, there's
605605
only a certain amount of data that LLMs can reference in order to generate a
606606
response. To equate this to human terms, it can be thought of as working memory
607607
<https://en.wikipedia.org/wiki/Working_memory> and it varies greatly depending
608-
on what model youre using. The context window is measured in tokens
608+
on what model you're using. The context window is measured in tokens
609609
<https://platform.claude.com/docs/en/about-claude/glossary#tokens>.
610610

611611
When a user breaches the context window, the conversation **ends** and it
@@ -619,7 +619,7 @@ IN THE CHAT BUFFER ~
619619

620620

621621
[!NOTE] CodeCompanion enables context management by default
622-
If youre using the `openai_responses` or `anthropic` adapters, then
622+
If you're using the `openai_responses` or `anthropic` adapters, then
623623
CodeCompanion will use their native server-side compaction capabilities. Please
624624
see their respective documentation here
625625
<https://developers.openai.com/api/docs/guides/compaction> and here
@@ -801,9 +801,8 @@ CURRENT LIMITATIONS *codecompanion-acp-current-limitations*
801801
doesn't advertise terminal capabilities to agents.
802802
- **Agent Plan Rendering**: Plan
803803
<https://agentclientprotocol.com/protocol/agent-plan> updates from agents are
804-
received and logged, but they’re not currently rendered in the chat buffer
805-
UI.
806-
- **Audio Content**: Audio can’t be sent or received
804+
received and logged, but they're not currently rendered in the chat buffer UI.
805+
- **Audio Content**: Audio can't be sent or received
807806

808807

809808
SEE ALSO *codecompanion-acp-see-also*
@@ -900,7 +899,7 @@ information on how to do this.
900899

901900
ADAPTERS
902901

903-
- For the Claude Code adapter to work, youll need to ensure you have Zeds 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>)
902+
- 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>)
904903

905904

906905
CONFIG
@@ -928,14 +927,14 @@ PROMPT LIBRARY
928927

929928
CONFIG
930929

931-
- 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, youll need to change it to `codecompanion.interactions` (#2485 <https://github.com/olimorris/codecompanion.nvim/pull/2485>)
932-
- 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 youll need to update the paths accordingly (#2482 <https://github.com/olimorris/codecompanion.nvim/pull/2482>)
930+
- 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>)
931+
- 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>)
933932
- Workspaces have now been removed from the plugin. Please use |codecompanion-configuration-rules| instead.
934933

935934

936935
ADAPTERS
937936

938-
- If you have a custom adapter, youll need to rename `condition` to be `enabled` on any schema items (#2439 <https://github.com/olimorris/codecompanion.nvim/pull/2439/commits/cb14c7bac869346e2d12b775c4bf258606add569>):
937+
- 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>):
939938

940939
>lua
941940
return {
@@ -964,12 +963,12 @@ CHAT
964963
entire buffer is sent to the LLM with each request (#2444 <https://github.com/olimorris/codecompanion.nvim/pull/2444>)
965964
966965
- 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>)
967-
- If your chat buffer system prompt is still stored at `opts.system_prompt` youll need to change it to `interactions.chat.opts.system_prompt` (#2484 <https://github.com/olimorris/codecompanion.nvim/pull/2484>)
966+
- 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>)
968967

969968

970969
PROMPT LIBRARY
971970

972-
If you have any prompts defined in your config, youll need to:
971+
If you have any prompts defined in your config, you'll need to:
973972

974973
- 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>).
975974

@@ -1003,12 +1002,12 @@ If you have any prompts defined in your config, you’ll need to:
10031002
},
10041003
<
10051004

1006-
- If you dont wish to display any of the built-in prompt library items, youll need to change `display.action_palette.show_default_prompt_library` to `display.action_palette.show_preset_prompts` (#2499 <https://github.com/olimorris/codecompanion.nvim/pull/2499>)
1005+
- If you don't wish to display any of the built-in prompt library items, you'll need to change `display.action_palette.show_default_prompt_library` to `display.action_palette.show_preset_prompts` (#2499 <https://github.com/olimorris/codecompanion.nvim/pull/2499>)
10071006

10081007

10091008
TOOLS
10101009

1011-
If you have any tools in your config, youll need to rename:
1010+
If you have any tools in your config, you'll need to rename:
10121011

10131012
- `requires_approval` to `require_approval_before` (#2439 <https://github.com/olimorris/codecompanion.nvim/pull/2439/commits/cb14c7bac869346e2d12b775c4bf258606add569>)
10141013
- `user_confirmation` to `require_confirmation_after` (#2450 <https://github.com/olimorris/codecompanion.nvim/pull/2450>)
@@ -1503,8 +1502,8 @@ connect you to an agent.
15031502
The configuration for both types of adapters is exactly the same, however they
15041503
sit within their own tables (`adapters.http.*` and `adapters.acp.*`) and have
15051504
different options available. HTTP adapters use `models` to allow users to
1506-
select the specific LLM theyd like to interact with. ACP adapters use
1507-
`commands` to allow users to customize their interaction with agents (e.g.
1505+
select the specific LLM they'd like to interact with. ACP adapters use
1506+
`commands` to allow users to customize their interaction with agents (e.g.
15081507
enabling `yolo` mode). As there is a lot of shared functionality between the
15091508
two adapters, it is recommend that you read this page alongside the ACP one.
15101509

@@ -1588,8 +1587,8 @@ selection UI), you can set the `show_model_choices` option to `false`:
15881587
<
15891588

15901589
With `show_model_choices = false`, the default model (as defined in the
1591-
adapters schema) will be automatically selected when changing adapters, and
1592-
no model selection will be shown to the user.
1590+
adapter's schema) will be automatically selected when changing adapters, and no
1591+
model selection will be shown to the user.
15931592

15941593

15951594
ENVIRONMENT VARIABLES ~
@@ -1605,7 +1604,7 @@ the adapter's URL, headers, parameters and other fields at runtime.
16051604
<https://github.com/olimorris/codecompanion.nvim/discussions/601>
16061605
Supported `env` value types: - **Plain environment variable name (string)**: if
16071606
the value is the name of an environment variable that has already been set
1608-
(e.g. `"HOME"` or `"GEMINI_API_KEY"`), the plugin will read the value. -
1607+
(e.g. `"HOME"` or `"GEMINI_API_KEY"`), the plugin will read the value. -
16091608
**Command (string prefixed with cmd:)**: any value that starts with `cmd:` will
16101609
be executed via the shell. Example: `"cmd:op read
16111610
op://personal/Gemini/credential --no-newline"`. - **Function**: you can provide
@@ -2134,7 +2133,7 @@ stack:
21342133
CONTEXT MANAGEMENT ~
21352134

21362135
CodeCompanion can manage context in the chat buffer to try and prevent
2137-
breaching the LLMs context window. It can be enabled with:
2136+
breaching the LLM's context window. It can be enabled with:
21382137

21392138

21402139
CodeCompanion makes use of a trigger, a threshold at which the context
@@ -3559,7 +3558,7 @@ The fastest way to copy an LLM's code output is with `gy`. This will yank the
35593558
nearest codeblock.
35603559

35613560

3562-
APPLYING AN LLM€�S EDITS TO A BUFFER OR FILE ~
3561+
APPLYING AN LLM'S EDITS TO A BUFFER OR FILE ~
35633562

35643563
The |codecompanion-usage-chat-buffer-agents-tools-files| tool, combined with
35653564
the |codecompanion-usage-chat-buffer-editor-context.html-buffer| editor context
@@ -3649,8 +3648,12 @@ and LLM's responses. The plugin is turn-based, meaning that the user sends a
36493648
response which is then followed by the LLM's. The user's responses are parsed
36503649
by treesitter and sent via an adapter to an LLM for a response which is then
36513650
streamed back into the buffer. A response is sent to the LLM by pressing `<CR>`
3652-
or `<C-s>`. This can of course be changed as per the |codecompanion--keymaps|
3653-
section.
3651+
or `<C-s>` in normal mode or `<C-CR>` in insert mode. This can of course be
3652+
changed as per the |codecompanion--keymaps| section.
3653+
3654+
New in `v19.12.0`, you can send a message to the LLM whilst it's executing tool
3655+
calls with the `btw` keymap which is triggered with `gm`. When safe to do so,
3656+
CodeCompanion will send the message to the LLM.
36543657

36553658

36563659
CHANGING ADAPTER AND MODEL ~
@@ -3796,22 +3799,23 @@ available to the user in normal mode are:
37963799
- `close`: `<C-c>` to close the chat buffer
37973800
- `stop`: `q` to stop the current request
37983801
- `change_adapter`: `ga` to change the adapter for the current chat
3802+
- `clear`: `gx` to clear the chat buffer's contents
3803+
- `copilot_stats`: `gS` to show copilot usage stats
3804+
- `btw`: `gm` type a message to the LLM whilst it's streaming
37993805
- `buffer_sync_all`: `gba` to sync the entire buffer on every turn
38003806
- `buffer_sync_diff`: `gbd` to sync only a buffers diff on every turn
38013807
- `codeblock`: `gc` to insert a codeblock in the chat buffer
38023808
- `debug`: `gd` to view/debug the chat buffer's contents
38033809
- `fold_code`: `gf` to fold any codeblocks in the chat buffer
3804-
- `rules`: `gM` to clear all rules from the chat buffer
3810+
- `goto_file_under_cursor`: `gR` to go to the file under cursor
3811+
- `next_chat`: `}` to move to the next chat
3812+
- `next_header`: `]]` to move to the next header
3813+
- `previous_chat`: `{` to move to the previous chat
3814+
- `previous_header`: `[[` to move to the previous header
38053815
- `regenerate`: `gr` to regenerate the last response
3806-
- `goto_file_under_cursor`: `gR` to go to the file under cursor. If the file is already opened, it'll jump to the existing window. Otherwise, it'll be opened in a new tab.
3816+
- `rules`: `gM` to clear all rules from the chat buffer
38073817
- `system_prompt`: `gs` to toggle the system prompt on/off
3808-
- `copilot_stats`: `gS` to show copilot usage stats
3809-
- `clear`: `gx` to clear the chat buffer's contents
38103818
- `yank_code`: `gy` to yank the last codeblock in the chat buffer
3811-
- `previous_header`: `[[` to move to the previous header
3812-
- `next_header`: `]]` to move to the next header
3813-
- `previous_chat`: `{` to move to the previous chat
3814-
- `next_chat`: `}` to move to the next chat
38153819

38163820

38173821
MESSAGES ~
@@ -4431,7 +4435,7 @@ message to the LLM.
44314435

44324436
[!IMPORTANT] With the exception of `#{buffer}` and `#{buffers}`, editor context
44334437
captures a point-in-time snapshot when your message is sent. If the underlying
4434-
data changes (e.g. new diagnostics, a different quickfix list), simply use the
4438+
data changes (e.g. new diagnostics, a different quickfix list), simply use the
44354439
context again in a new message to share the latest state.
44364440

44374441
#BUFFER ~
@@ -5207,7 +5211,7 @@ LIST OF EVENTS ~
52075211
The events that are fired from within the plugin are:
52085212

52095213
- `CodeCompanionACPConnected` - Fired after the ACP connection is authenticated and ready to use
5210-
- `CodeCompanionACPSessionPre` - Fired after ACP authentication completes but before a new session is established; allows subscribers to modify the connection (e.g. inject MCP servers) synchronously
5214+
- `CodeCompanionACPSessionPre` - Fired after ACP authentication completes but before a new session is established; allows subscribers to modify the connection (e.g. inject MCP servers) synchronously
52115215
- `CodeCompanionACPSessionPost` - Fired after a new ACP session has been established
52125216
- `CodeCompanionChatACPModeChanged` - Fired after the ACP mode has been changed in the chat
52135217
- `CodeCompanionACPChatRestored` - Fired after an ACP session has been restored
@@ -5220,7 +5224,7 @@ The events that are fired from within the plugin are:
52205224
- `CodeCompanionChatCompacting` - Fired after the chat begins compacting messages to reduce token usage
52215225
- `CodeCompanionChatStopped` - Fired after a chat has been stopped
52225226
- `CodeCompanionChatCleared` - Fired after a chat has been cleared
5223-
- `CodeCompanionChatRestored` - Fired after a chat has been restored to an editable state (e.g. when `on_before_submit` prevents submission)
5227+
- `CodeCompanionChatRestored` - Fired after a chat has been restored to an editable state (e.g. when `on_before_submit` prevents submission)
52245228
- `CodeCompanionChatAdapter` - Fired after the adapter has been set in the chat
52255229
- `CodeCompanionChatModel` - Fired after the model has been set in the chat
52265230
- `CodeCompanionCLICreated` - Fired after a CLI buffer has been created for the first time
@@ -5710,7 +5714,7 @@ These handlers manage tool/function calling:
57105714
as a great reference to understand how they're working with the output of the
57115715
API
57125716

5713-
OPENAI€�S API OUTPUT
5717+
OPENAI'S API OUTPUT
57145718

57155719
If we reference the OpenAI documentation
57165720
<https://platform.openai.com/docs/guides/text-generation/chat-completions-api>
@@ -7618,8 +7622,8 @@ tool to function. In the case of Anthropic, we insert additional headers.
76187622
<
76197623

76207624
Some adapter tools can be a `hybrid` in terms of their implementation. That is,
7621-
theyre an adapter tool that requires a client-side component (i.e.� a
7622-
built-in tool). This is the case for the
7625+
they're an adapter tool that requires a client-side component (i.e. a built-in
7626+
tool). This is the case for the
76237627
|codecompanion-usage-chat-buffer-agents-tools-memory| tool from Anthropic. To
76247628
allow for this, ensure that the tool definition in `available_tools` has
76257629
`client_tool` defined:

doc/usage/chat-buffer/index.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ require("codecompanion").chat({ window_opts = { layout = "float", width = 0.6 }}
2323
require("codecompanion").toggle({ window_opts = { layout = "float", width = 0.6 }})
2424
```
2525

26-
The chat buffer uses markdown as its syntax and `H2` headers separate the user and LLM's responses. The plugin is turn-based, meaning that the user sends a response which is then followed by the LLM's. The user's responses are parsed by treesitter and sent via an adapter to an LLM for a response which is then streamed back into the buffer. A response is sent to the LLM by pressing `<CR>` or `<C-s>`. This can of course be changed as per the [keymaps](#keymaps) section.
26+
The chat buffer uses markdown as its syntax and `H2` headers separate the user and LLM's responses. The plugin is turn-based, meaning that the user sends a response which is then followed by the LLM's. The user's responses are parsed by treesitter and sent via an adapter to an LLM for a response which is then streamed back into the buffer. A response is sent to the LLM by pressing `<CR>` or `<C-s>` in normal mode or `<C-CR>` in insert mode. This can of course be changed as per the [keymaps](#keymaps) section.
27+
28+
New in `v19.12.0`, you can send a message to the LLM whilst it's executing tool calls with the `btw` keymap which is triggered with `gm`. When safe to do so, CodeCompanion will send the message to the LLM.
2729

2830
## Changing Adapter and Model
2931

@@ -126,23 +128,25 @@ The plugin has a host of keymaps available in the chat buffer. The keymaps avail
126128
- `send`: `<CR>|<C-s>` to send a message to the LLM
127129
- `close`: `<C-c>` to close the chat buffer
128130
- `stop`: `q` to stop the current request
131+
129132
- `change_adapter`: `ga` to change the adapter for the current chat
133+
- `clear`: `gx` to clear the chat buffer’s contents
134+
- `copilot_stats`: `gS` to show copilot usage stats
135+
- `btw`: `gm` type a message to the LLM whilst it's streaming
130136
- `buffer_sync_all`: `gba` to sync the entire buffer on every turn
131137
- `buffer_sync_diff`: `gbd` to sync only a buffers diff on every turn
132138
- `codeblock`: `gc` to insert a codeblock in the chat buffer
133139
- `debug`: `gd` to view/debug the chat buffer’s contents
134140
- `fold_code`: `gf` to fold any codeblocks in the chat buffer
135-
- `rules`: `gM` to clear all rules from the chat buffer
141+
- `goto_file_under_cursor`: `gR` to go to the file under cursor
142+
- `next_chat`: `}` to move to the next chat
143+
- `next_header`: `]]` to move to the next header
144+
- `previous_chat`: `{` to move to the previous chat
145+
- `previous_header`: `[[` to move to the previous header
136146
- `regenerate`: `gr` to regenerate the last response
137-
- `goto_file_under_cursor`: `gR` to go to the file under cursor. If the file is already opened, it’ll jump to the existing window. Otherwise, it’ll be opened in a new tab.
147+
- `rules`: `gM` to clear all rules from the chat buffer
138148
- `system_prompt`: `gs` to toggle the system prompt on/off
139-
- `copilot_stats`: `gS` to show copilot usage stats
140-
- `clear`: `gx` to clear the chat buffer’s contents
141149
- `yank_code`: `gy` to yank the last codeblock in the chat buffer
142-
- `previous_header`: `[[` to move to the previous header
143-
- `next_header`: `]]` to move to the next header
144-
- `previous_chat`: `{` to move to the previous chat
145-
- `next_chat`: `}` to move to the next chat
146150

147151
## Messages
148152

lua/codecompanion/config.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,12 @@ If you are providing code changes, use the insert_edit_into_file tool (if availa
669669
callback = "keymaps.copilot_stats",
670670
description = "[Adapter] Copilot statistics",
671671
},
672+
-- Note: This is only available during streaming
673+
_btw = {
674+
modes = { n = "gm" },
675+
callback = "keymaps.btw",
676+
description = "[Request] Send a message to the LLM",
677+
},
672678
},
673679
opts = {
674680
context_management = {

0 commit comments

Comments
 (0)