Skip to content

Commit 73833a0

Browse files
authored
feat(acp): add session/set_config_option support (#3002)
1 parent 7d7957c commit 73833a0

17 files changed

Lines changed: 703 additions & 1027 deletions

File tree

doc/codecompanion.txt

Lines changed: 75 additions & 399 deletions
Large diffs are not rendered by default.

doc/configuration/adapters-acp.md

Lines changed: 66 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,37 @@ description: Learn how to configure ACP adapters like Claude Code, Gemini CLI an
66

77
This section contains configuration which is specific to Agent Client Protocol (ACP) adapters only. There is a lot of shared functionality between ACP and [http](/configuration/adapters-http) adapters. Therefore it's recommended you read the two pages together.
88

9-
## Configuring Default Adapter
9+
## Configuring Adapter Settings
10+
11+
To change any of the default settings for an ACP adapter, you can extend it in your CodeCompanion setup. For example, to change the timeout and authentication method for the Gemini CLI adapter, you can do the following:
12+
13+
```lua
14+
require("codecompanion").setup({
15+
adapters = {
16+
acp = {
17+
gemini_cli = function()
18+
return require("codecompanion.adapters").extend("gemini_cli", {
19+
commands = {
20+
default = {
21+
"some-other-gemini"
22+
"--experimental-acp",
23+
},
24+
},
25+
defaults = {
26+
auth_method = "gemini-api-key",
27+
timeout = 20000, -- 20 seconds
28+
},
29+
env = {
30+
GEMINI_API_KEY = "GEMINI_API_KEY",
31+
},
32+
})
33+
end,
34+
},
35+
},
36+
})
37+
```
38+
39+
## Setting a Default Adapter
1040

1141
You can select an ACP adapter to be the default for all chat interactions:
1242

@@ -20,33 +50,39 @@ require("codecompanion").setup({
2050
}),
2151
```
2252

23-
## Configuring Default Model
53+
## Setting Default Session Config Options
2454

25-
You can change the default model used by an ACP adapter. For example, to change the default model for the Claude Code adapter:
55+
The ACP specification has recently added support for [session config options](https://agentclientprotocol.com/protocol/session-config-options). These are lists of configuration options that agents can share with CodeCompanion at the start of a session such as models, reasoning levels, and more.
56+
57+
### Models
58+
59+
There are numerous was you can set a model in your config and it differs significantly from other session config options because of how CodeCompanion integrates adapters and models into the chat interaction.
2660

2761
::: code-group
2862

29-
```lua [For Interactions] {4-7}
63+
```lua [Interactions] {4-7}
3064
require("codecompanion").setup({
3165
interactions = {
3266
chat = {
3367
adapter = {
34-
name = "claude_code",
35-
model = "opus",
68+
name = "codex",
69+
model = "gpt-5.4",
3670
},
3771
},
3872
},
3973
}),
4074
```
4175

42-
```lua [Adapters: Text] {6-8}
76+
```lua [Adapter String] {6-10}
4377
require("codecompanion").setup({
4478
adapters = {
4579
acp = {
46-
claude_code = function()
47-
return require("codecompanion.adapters").extend("claude_code", {
80+
codex = function()
81+
return require("codecompanion.adapters").extend("codex", {
4882
defaults = {
49-
model = "opus"
83+
session_config_options = {
84+
model = "gpt-5.4"
85+
},
5086
},
5187
})
5288
end,
@@ -55,18 +91,20 @@ require("codecompanion").setup({
5591
}),
5692
```
5793

58-
```lua [Adapters: Function] {6-12}
94+
```lua [Adapter Function] {6-14}
5995
require("codecompanion").setup({
6096
adapters = {
6197
acp = {
62-
claude_code = function()
63-
return require("codecompanion.adapters").extend("claude_code", {
98+
codex = function()
99+
return require("codecompanion.adapters").extend("codex", {
64100
defaults = {
65-
---@param self CodeCompanion.ACPAdapter
66-
---@return string
67-
model = function(self)
68-
return "opus"
69-
end,
101+
session_config_options = {
102+
---@param self CodeCompanion.ACPAdapter
103+
---@return string
104+
model = function(self)
105+
return "gpt-5.4"
106+
end,
107+
},
70108
},
71109
})
72110
end,
@@ -77,42 +115,21 @@ require("codecompanion").setup({
77115

78116
:::
79117

80-
Using a _function_ is useful for working around the [limitations](https://github.com/zed-industries/claude-code-acp/issues/225) in the Claude Code SDK (which enables ACP support).
118+
### Others
81119

82-
## Configuring Default Mode
83-
84-
You can configure an ACP adapter to start in a specific agent mode (e.g., plan mode) by setting the `defaults.mode` option. This is useful if you want to always start sessions in plan mode or another specific mode.
85-
86-
::: code-group
87-
88-
```lua [Adapters: Text] {6-8}
89-
require("codecompanion").setup({
90-
adapters = {
91-
acp = {
92-
claude_code = function()
93-
return require("codecompanion.adapters").extend("claude_code", {
94-
defaults = {
95-
mode = "plan"
96-
},
97-
})
98-
end,
99-
}
100-
},
101-
}),
102-
```
120+
To set any other session config option, you can pass them in the `defaults.session_config_options` table:
103121

104-
```lua [Adapters: Function] {6-12}
122+
```lua {6-11}
105123
require("codecompanion").setup({
106124
adapters = {
107125
acp = {
108-
claude_code = function()
109-
return require("codecompanion.adapters").extend("claude_code", {
126+
codex = function()
127+
return require("codecompanion.adapters").extend("codex", {
110128
defaults = {
111-
---@param self CodeCompanion.ACPAdapter
112-
---@return string
113-
mode = function(self)
114-
return "plan"
115-
end,
129+
session_config_options = {
130+
mode = "Full Access",
131+
thought_level = "Xhigh",
132+
},
116133
},
117134
})
118135
end,
@@ -121,39 +138,7 @@ require("codecompanion").setup({
121138
}),
122139
```
123140

124-
:::
125-
126-
The mode is applied automatically after the session is established. Available mode IDs can be viewed using the `/mode` slash command in the chat buffer.
127-
128-
## Configuring Adapter Settings
129-
130-
To change any of the default settings for an ACP adapter, you can extend it in your CodeCompanion setup. For example, to change the timeout and authentication method for the Gemini CLI adapter, you can do the following:
131-
132-
```lua
133-
require("codecompanion").setup({
134-
adapters = {
135-
acp = {
136-
gemini_cli = function()
137-
return require("codecompanion.adapters").extend("gemini_cli", {
138-
commands = {
139-
default = {
140-
"some-other-gemini"
141-
"--experimental-acp",
142-
},
143-
},
144-
defaults = {
145-
auth_method = "gemini-api-key",
146-
timeout = 20000, -- 20 seconds
147-
},
148-
env = {
149-
GEMINI_API_KEY = "GEMINI_API_KEY",
150-
},
151-
})
152-
end,
153-
},
154-
},
155-
})
156-
```
141+
To find out what the available session config options are for a specific adapter you can open the [debug window](/usage/chat-buffer/#debug-window) in the chat buffer.
157142

158143
## Configuring MCP Servers
159144

0 commit comments

Comments
 (0)