Skip to content

Commit 062126b

Browse files
authored
fix(adapters): fix claude-code always outputting tool content (#2169)
fix(acp): fix claude always outputting tool content Co-authored-by: Oli Morris <olimorris@users.noreply.github.com>
1 parent 5c8ec88 commit 062126b

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lua/codecompanion/adapters/acp/claude_code.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ return {
1111
},
1212
opts = {
1313
vision = true,
14+
-- Claude Code has an annoying habit of outputting the entire contents of a
15+
-- file in a tool call. This messes up the chat buffer formatting.
16+
trim_tool_output = true,
1417
},
1518
commands = {
1619
default = {

lua/codecompanion/adapters/acp/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local shared = require("codecompanion.adapters.shared")
99
---@field roles table The mapping of roles in the config to the LLM's defined roles
1010
---@field command table The command to execute
1111
---@field commands { default: table, [string]: table } The list of possible commands for the adapter. Must include a 'default' key
12+
---@field opts? table Additional options for the adapter
1213
---@field defaults? table Additional options for the adapter
1314
---@field env? table Environment variables which can be referenced in the parameters
1415
---@field env_replaced? table Replacement of environment variables with their actual values

lua/codecompanion/strategies/chat/acp/formatters.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ end
127127
function M.tool_message(tool_call, adapter)
128128
local status = tool_call.status or "pending"
129129
local title = M.short_title(tool_call)
130+
local trim_tool_output = adapter.opts and adapter.opts.trim_tool_output
131+
130132
if status == "completed" then
131133
local summary
132-
if adapter.name == "claude_code" then
134+
if trim_tool_output then
133135
summary = title
134136
else
135137
summary = M.summarize_tool_content(tool_call)
@@ -138,8 +140,13 @@ function M.tool_message(tool_call, adapter)
138140
elseif status == "in_progress" then
139141
return title .. " — running"
140142
elseif status == "failed" then
141-
local summary = M.summarize_tool_content(tool_call)
142-
return summary and (title .. " — failed: " .. summary) or (title .. " — failed")
143+
local summary
144+
if trim_tool_output then
145+
summary = title
146+
else
147+
summary = M.summarize_tool_content(tool_call)
148+
end
149+
return summary or (title .. " — failed")
143150
else
144151
return title
145152
end

0 commit comments

Comments
 (0)