Follow Discord
Sweep 22 Oct 2026 · 21:04Z Build v2.1.309 528 read Stable v2.1.308 Latest v2.1.309 Next v2.1.309 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

text-editor-tool changedagents-and-tools/tool-use/text-editor-tool

Nearest release: v2.1.309, published 3 hours before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+170added
Lines−170removed
From line 159 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits10to this page, all time

The whole hunk

from line 159, old and new numbered
/
lines
from line 159
159159 import com.anthropic.models.messages.ToolTextEditor20250728;
160160 // ...
161161 void main() {
162 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
162 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
163163 
164 ToolTextEditor20250728 editorTool =
165 ToolTextEditor20250728.builder()
166 .maxCharacters(10000L)
167 .build();
164 ToolTextEditor20250728 editorTool =
165 ToolTextEditor20250728.builder()
166 .maxCharacters(10000L)
167 .build();
168168 
169 MessageCreateParams params = MessageCreateParams.builder()
170 .model(Model.CLAUDE_OPUS_5_5)
171 .maxTokens(1024)
172 .addTool(editorTool)
173 .addUserMessage("There's a syntax error in my primes.py file. Can you help me fix it?")
174 .build();
169 MessageCreateParams params = MessageCreateParams.builder()
170 .model(Model.CLAUDE_OPUS_5_5)
171 .maxTokens(1024)
172 .addTool(editorTool)
173 .addUserMessage("There's a syntax error in my primes.py file. Can you help me fix it?")
174 .build();
175175 
176 Message message = client.messages().create(params);
177 IO.println(message);
176 Message message = client.messages().create(params);
177 IO.println(message);
178178 }
179179 ```
180180 
from line 182
182182 $client = new Client();
183183 
184184 $response = $client->messages->create(
185 model: 'claude-opus-5-5',
185 model: Model::CLAUDE_OPUS_5_5,
186186 maxTokens: 1024,
187187 tools: [ToolTextEditor20250728::with(maxCharacters: 10000)],
188188 messages: [
from line 504
504504 import com.anthropic.models.messages.ToolTextEditor20250728;
505505 // ...
506506 void main() {
507 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
507 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
508508 
509 ToolTextEditor20250728 editorTool =
510 ToolTextEditor20250728.builder().build();
509 ToolTextEditor20250728 editorTool =
510 ToolTextEditor20250728.builder().build();
511511 
512 MessageCreateParams params = MessageCreateParams.builder()
513 .model(Model.CLAUDE_OPUS_5_5)
514 .maxTokens(1024)
515 .addTool(editorTool)
516 .addUserMessage("There's a syntax error in my primes.py file. Can you help me fix it?")
517 .build();
512 MessageCreateParams params = MessageCreateParams.builder()
513 .model(Model.CLAUDE_OPUS_5_5)
514 .maxTokens(1024)
515 .addTool(editorTool)
516 .addUserMessage("There's a syntax error in my primes.py file. Can you help me fix it?")
517 .build();
518518 
519 Message message = client.messages().create(params);
520 IO.println(message);
519 Message message = client.messages().create(params);
520 IO.println(message);
521521 }
522522 ```
523523 
from line 525
525525 $client = new Client();
526526 
527527 $response = $client->messages->create(
528 model: 'claude-opus-5-5',
528 model: Model::CLAUDE_OPUS_5_5,
529529 maxTokens: 1024,
530530 tools: [new ToolTextEditor20250728()],
531531 messages: [
from line 885
885885 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
886886 
887887 MessageCreateParams params = MessageCreateParams.builder()
888 .model(Model.CLAUDE_OPUS_5_5)
889 .maxTokens(1024)
890 .addTool(ToolTextEditor20250728.builder().build())
891 .addUserMessage("There's a syntax error in my primes.py file. Can you help me fix it?")
892 .addAssistantMessageOfContentBlockParams(
893 List.of(
894 ContentBlockParam.ofText(
895 TextBlockParam.builder()
896 .text("I'll help you fix the syntax error in your primes.py file. First, let me take a look at the file to identify the issue.")
897 .build()
898 ),
899 ContentBlockParam.ofToolUse(
900 ToolUseBlockParam.builder()
901 .id("toolu_01AbCdEfGhIjKlMnOpQrStU")
902 .name("str_replace_based_edit_tool")
903 .input(
904 ToolUseBlockParam.Input.builder()
905 .putAdditionalProperty("command", JsonValue.from("view"))
906 .putAdditionalProperty("path", JsonValue.from("primes.py"))
907 .build()
908 )
909 .build()
910 )
888 .model(Model.CLAUDE_OPUS_5_5)
889 .maxTokens(1024)
890 .addTool(ToolTextEditor20250728.builder().build())
891 .addUserMessage("There's a syntax error in my primes.py file. Can you help me fix it?")
892 .addAssistantMessageOfContentBlockParams(
893 List.of(
894 ContentBlockParam.ofText(
895 TextBlockParam.builder()
896 .text("I'll help you fix the syntax error in your primes.py file. First, let me take a look at the file to identify the issue.")
897 .build()
898 ),
899 ContentBlockParam.ofToolUse(
900 ToolUseBlockParam.builder()
901 .id("toolu_01AbCdEfGhIjKlMnOpQrStU")
902 .name("str_replace_based_edit_tool")
903 .input(
904 ToolUseBlockParam.Input.builder()
905 .putAdditionalProperty("command", JsonValue.from("view"))
906 .putAdditionalProperty("path", JsonValue.from("primes.py"))
907 .build()
908 )
909 .build()
910 )
911 )
911912 )
912 )
913 .addUserMessageOfContentBlockParams(
914 List.of(
915 ContentBlockParam.ofToolResult(
916 ToolResultBlockParam.builder()
917 .toolUseId("toolu_01AbCdEfGhIjKlMnOpQrStU")
918 .content("1: def is_prime(n):\n2: \"\"\"Check if a number is prime.\"\"\"\n3: if n <= 1:\n4: return False\n5: if n <= 3:\n6: return True\n7: if n % 2 == 0 or n % 3 == 0:\n8: return False\n9: i = 5\n10: while i * i <= n:\n11: if n % i == 0 or n % (i + 2) == 0:\n12: return False\n13: i += 6\n14: return True\n15: \n16: def get_primes(limit):\n17: \"\"\"Generate a list of prime numbers up to the given limit.\"\"\"\n18: primes = []\n19: for num in range(2, limit + 1)\n20: if is_prime(num):\n21: primes.append(num)\n22: return primes\n23: \n24: def main():\n25: \"\"\"Main function to demonstrate prime number generation.\"\"\"\n26: limit = 100\n27: prime_list = get_primes(limit)\n28: print(f\"Prime numbers up to {limit}:\")\n29: print(prime_list)\n30: print(f\"Found {len(prime_list)} prime numbers.\")\n31: \n32: if __name__ == \"__main__\":\n33: main()")
919 .build()
920 )
913 .addUserMessageOfContentBlockParams(
914 List.of(
915 ContentBlockParam.ofToolResult(
916 ToolResultBlockParam.builder()
917 .toolUseId("toolu_01AbCdEfGhIjKlMnOpQrStU")
918 .content("1: def is_prime(n):\n2: \"\"\"Check if a number is prime.\"\"\"\n3: if n <= 1:\n4: return False\n5: if n <= 3:\n6: return True\n7: if n % 2 == 0 or n % 3 == 0:\n8: return False\n9: i = 5\n10: while i * i <= n:\n11: if n % i == 0 or n % (i + 2) == 0:\n12: return False\n13: i += 6\n14: return True\n15: \n16: def get_primes(limit):\n17: \"\"\"Generate a list of prime numbers up to the given limit.\"\"\"\n18: primes = []\n19: for num in range(2, limit + 1)\n20: if is_prime(num):\n21: primes.append(num)\n22: return primes\n23: \n24: def main():\n25: \"\"\"Main function to demonstrate prime number generation.\"\"\"\n26: limit = 100\n27: prime_list = get_primes(limit)\n28: print(f\"Prime numbers up to {limit}:\")\n29: print(prime_list)\n30: print(f\"Found {len(prime_list)} prime numbers.\")\n31: \n32: if __name__ == \"__main__\":\n33: main()")
919 .build()
920 )
921 )
921922 )
922 )
923 .build();
923 .build();
924924 
925925 Message message = client.messages().create(params);
926926 System.out.println(message);
from line 930
930930 $client = new Client();
931931 
932932 $response = $client->messages->create(
933 model: 'claude-opus-5-5',
933 model: Model::CLAUDE_OPUS_5_5,
934934 maxTokens: 1024,
935935 tools: [new ToolTextEditor20250728()],
936936 messages: [
from line 1317
13171317 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
13181318 
13191319 MessageCreateParams params = MessageCreateParams.builder()
1320 .model(Model.CLAUDE_OPUS_5_5)
1321 .maxTokens(1024)
1322 .addTool(ToolTextEditor20250728.builder().build())
1323 // Previous messages would go here
1324 .addAssistantMessageOfContentBlockParams(
1325 List.of(
1326 ContentBlockParam.ofText(
1327 TextBlockParam.builder()
1328 .text(
1329 "I found the syntax error in your primes.py file. In the `get_primes` function, there is a missing colon (:) at the end of the for loop line. Let me fix that for you."
1330 )
1331 .build()
1332 ),
1333 ContentBlockParam.ofToolUse(
1334 ToolUseBlockParam.builder()
1335 .id("toolu_01PqRsTuVwXyZAbCdEfGh")
1336 .name("str_replace_based_edit_tool")
1337 .input(
1338 ToolUseBlockParam.Input.builder()
1339 .putAdditionalProperty("command", JsonValue.from("str_replace"))
1340 .putAdditionalProperty("path", JsonValue.from("primes.py"))
1341 .putAdditionalProperty(
1342 "old_str",
1343 JsonValue.from(" for num in range(2, limit + 1)")
1344 )
1345 .putAdditionalProperty(
1346 "new_str",
1347 JsonValue.from(" for num in range(2, limit + 1):")
1348 )
1349 .build()
1350 )
1351 .build()
1352 )
1320 .model(Model.CLAUDE_OPUS_5_5)
1321 .maxTokens(1024)
1322 .addTool(ToolTextEditor20250728.builder().build())
1323 // Previous messages would go here
1324 .addAssistantMessageOfContentBlockParams(
1325 List.of(
1326 ContentBlockParam.ofText(
1327 TextBlockParam.builder()
1328 .text(
1329 "I found the syntax error in your primes.py file. In the `get_primes` function, there is a missing colon (:) at the end of the for loop line. Let me fix that for you."
1330 )
1331 .build()
1332 ),
1333 ContentBlockParam.ofToolUse(
1334 ToolUseBlockParam.builder()
1335 .id("toolu_01PqRsTuVwXyZAbCdEfGh")
1336 .name("str_replace_based_edit_tool")
1337 .input(
1338 ToolUseBlockParam.Input.builder()
1339 .putAdditionalProperty("command", JsonValue.from("str_replace"))
1340 .putAdditionalProperty("path", JsonValue.from("primes.py"))
1341 .putAdditionalProperty(
1342 "old_str",
1343 JsonValue.from(" for num in range(2, limit + 1)")
1344 )
1345 .putAdditionalProperty(
1346 "new_str",
1347 JsonValue.from(" for num in range(2, limit + 1):")
1348 )
1349 .build()
1350 )
1351 .build()
1352 )
1353 )
13531354 )
1354 )
1355 .addUserMessageOfContentBlockParams(
1356 List.of(
1357 ContentBlockParam.ofToolResult(
1358 ToolResultBlockParam.builder()
1359 .toolUseId("toolu_01PqRsTuVwXyZAbCdEfGh")
1360 .content("Successfully replaced text at exactly one location.")
1361 .build()
1362 )
1355 .addUserMessageOfContentBlockParams(
1356 List.of(
1357 ContentBlockParam.ofToolResult(
1358 ToolResultBlockParam.builder()
1359 .toolUseId("toolu_01PqRsTuVwXyZAbCdEfGh")
1360 .content("Successfully replaced text at exactly one location.")
1361 .build()
1362 )
1363 )
13631364 )
1364 )
1365 .build();
1365 .build();
13661366 
13671367 Message message = client.messages().create(params);
13681368 System.out.println(message);
from line 1372
13721372 $client = new Client();
13731373 
13741374 $response = $client->messages->create(
1375 model: 'claude-opus-5-5',
1375 model: Model::CLAUDE_OPUS_5_5,
13761376 maxTokens: 1024,
13771377 tools: [new ToolTextEditor20250728()],
13781378 messages: [
from line 1585
15851585 
15861586 ```java Java
15871587 static void handleEditorTool(Map<String, Object> input) {
1588 var command = (String) input.getOrDefault("command", "");
1589 var filePath = (String) input.getOrDefault("path", "");
1588 var command = (String) input.getOrDefault("command", "");
1589 var filePath = (String) input.getOrDefault("path", "");
15901590 
1591 if (command.equals("view")) {
1592 // Read and return file contents
1593 } else if (command.equals("str_replace")) {
1594 // Replace text in file
1595 } else if (command.equals("create")) {
1596 // Create new file
1597 } else if (command.equals("insert")) {
1598 // Insert text at location
1599 }
1591 if (command.equals("view")) {
1592 // Read and return file contents
1593 } else if (command.equals("str_replace")) {
1594 // Replace text in file
1595 } else if (command.equals("create")) {
1596 // Create new file
1597 } else if (command.equals("insert")) {
1598 // Insert text at location
1599 }
16001600 }
16011601 ```
16021602 
from line 1656
16561656 # Process tool use in Claude's response
16571657 for content in response.content:
16581658 if content.type == "tool_use":
1659 # Execute the tool based on command
1659 # Run the tool based on command
16601660 result = handle_editor_tool(content)
16611661 
16621662 # Return result to Claude
from line 1671
16711671 // Process tool use in Claude's response
16721672 for (const block of response.content) {
16731673 if (block.type === "tool_use") {
1674 // Execute the tool based on command
1674 // Run the tool based on command
16751675 const result = handleEditorTool(block);
16761676 
16771677 // Return result to Claude
from line 1719
17191719 ```java Java
17201720 // Process tool use in Claude's response
17211721 for (var block : response.content()) {
1722 if (block.type().equals("tool_use")) {
1723 // Execute the tool based on command
1724 var result = handleEditorTool(block);
1722 if (block.type().equals("tool_use")) {
1723 // Run the tool based on command
1724 var result = handleEditorTool(block);
17251725 
1726 // Return result to Claude
1727 var toolResult = Map.of(
1728 "type", "tool_result",
1729 "tool_use_id", block.id(),
1730 "content", result
1731 );
1732 }
1726 // Return result to Claude
1727 var toolResult = Map.of(
1728 "type", "tool_result",
1729 "tool_use_id", block.id(),
1730 "content", result
1731 );
1732 }
17331733 }
17341734 ```
17351735 
from line 1737
17371737 // Process tool use in Claude's response
17381738 foreach ($response->content as $block) {
17391739 if ($block->type === 'tool_use') {
1740 // Execute the tool based on command
1740 // Run the tool based on command
17411741 $result = handle_editor_tool($block->input);
17421742 
17431743 // Return result to Claude
from line 1920
19201920 
19211921 ```java Java
19221922 static void backupFile(String filePath) throws IOException {
1923 Path source = Path.of(filePath);
1924 Path backupPath = Path.of(filePath + ".backup");
1925 if (Files.exists(source)) {
1926 Files.copy(source, backupPath, StandardCopyOption.REPLACE_EXISTING);
1927 }
1923 Path source = Path.of(filePath);
1924 Path backupPath = Path.of(filePath + ".backup");
1925 if (Files.exists(source)) {
1926 Files.copy(source, backupPath, StandardCopyOption.REPLACE_EXISTING);
1927 }
19281928 }
19291929 ```
19301930 
from line 2038
20382038 
20392039 ```java Java
20402040 static String safeReplace(String filePath, String oldText, String newText) throws IOException {
2041 String content = Files.readString(Path.of(filePath));
2041 String content = Files.readString(Path.of(filePath));
20422042 
2043 int count = content.split(Pattern.quote(oldText), -1).length - 1;
2044 if (count == 0) {
2045 return "Error: No match found";
2046 } else if (count > 1) {
2047 return "Error: Found " + count + " matches";
2048 } else {
2049 String newContent = content.replace(oldText, newText);
2050 Files.writeString(Path.of(filePath), newContent);
2051 return "Successfully replaced text";
2052 }
2043 int count = content.split(Pattern.quote(oldText), -1).length - 1;
2044 if (count == 0) {
2045 return "Error: No match found";
2046 } else if (count > 1) {
2047 return "Error: Found " + count + " matches";
2048 } else {
2049 String newContent = content.replace(oldText, newText);
2050 Files.writeString(Path.of(filePath), newContent);
2051 return "Successfully replaced text";
2052 }
20532053 }
20542054 ```
20552055 
from line 2172
21722172 
21732173 ```java Java
21742174 static String verifyChanges(String filePath) {
2175 try {
2176 // For Python files, check for syntax errors
2177 if (filePath.endsWith(".py")) {
2178 Process proc = new ProcessBuilder("python3", "-m", "py_compile", filePath)
2179 .redirectErrorStream(true)
2180 .start();
2181 if (proc.waitFor() != 0) {
2182 return "Verification failed: " + new String(proc.getInputStream().readAllBytes());
2183 }
2184 return "Syntax check passed";
2175 try {
2176 // For Python files, check for syntax errors
2177 if (filePath.endsWith(".py")) {
2178 Process proc = new ProcessBuilder("python3", "-m", "py_compile", filePath)
2179 .redirectErrorStream(true)
2180 .start();
2181 if (proc.waitFor() != 0) {
2182 return "Verification failed: " + new String(proc.getInputStream().readAllBytes());
2183 }
2184 return "Syntax check passed";
2185 }
2186 return "No checks defined for this file type";
2187 } catch (IOException | InterruptedException e) {
2188 return "Verification failed: " + e.getMessage();
21852189 }
2186 return "No checks defined for this file type";
2187 } catch (IOException | InterruptedException e) {
2188 return "Verification failed: " + e.getMessage();
2189 }
21902190 }
21912191 ```
21922192 
Feedback