From e61a4ad4dcaadee7fd589ff5d70a27c2e0aca1d1 Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Thu, 25 Jun 2026 21:49:30 +0200 Subject: [PATCH] Reject empty old_string in edit tool --- src/anthropic/lib/tools/agent_toolset.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/anthropic/lib/tools/agent_toolset.py b/src/anthropic/lib/tools/agent_toolset.py index d771996a..3eb0039e 100644 --- a/src/anthropic/lib/tools/agent_toolset.py +++ b/src/anthropic/lib/tools/agent_toolset.py @@ -557,6 +557,8 @@ async def edit(file_path: str, old_string: str, new_string: str, replace_all: Op target = resolve_path(ctx, file_path) except ValueError as e: raise ToolError(f"edit: {e}") from e + if old_string == "": + raise ToolError("edit: old_string must not be empty") try: # stat() before any open(): the size cap stops a multi-GB file from # OOM'ing the runner, and is_file() rejects FIFOs/devices/dirs