Skip to content

Commit 2c1a17b

Browse files
committed
fix(ai-chat): forward replace_all from Edit tool to buffer applier
The PreToolUse hook intercepting Claude's Edit tool was dropping the replace_all flag, so buffer/plan edits only ever replaced the first occurrence even when Claude requested replace_all=true.
1 parent cf881f0 commit 2c1a17b

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src-node/claude-code-agent.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,13 @@ async function _runQuery(requestId, prompt, projectPath, model, signal, locale,
522522
content = fs.readFileSync(input.tool_input.file_path, "utf8");
523523
}
524524
if (input.tool_input.old_string && input.tool_input.new_string) {
525-
content = content.replace(input.tool_input.old_string, input.tool_input.new_string);
525+
if (input.tool_input.replace_all === true) {
526+
content = content.split(input.tool_input.old_string)
527+
.join(input.tool_input.new_string);
528+
} else {
529+
content = content.replace(input.tool_input.old_string,
530+
input.tool_input.new_string);
531+
}
526532
}
527533
const dir = path.dirname(input.tool_input.file_path);
528534
if (!fs.existsSync(dir)) {
@@ -550,7 +556,8 @@ async function _runQuery(requestId, prompt, projectPath, model, signal, locale,
550556
const edit = {
551557
file: input.tool_input.file_path,
552558
oldText: input.tool_input.old_string,
553-
newText: input.tool_input.new_string
559+
newText: input.tool_input.new_string,
560+
replaceAll: input.tool_input.replace_all === true
554561
};
555562
editCount++;
556563
let editResult;

0 commit comments

Comments
 (0)