Skip to content

Commit 29d3175

Browse files
authored
Add ReadTool & WriteTool alternate tools (RooCodeInc#3873)
* Added ReadTool and WriteTool alternate tool calls * claude4 system prompt - add read & write alt tools
1 parent 6001743 commit 29d3175

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

.changeset/ninety-candles-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Added alt readTool & writeTool tool calls

src/core/prompts/model_prompts/claude4.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import osName from "os-name"
44
import { McpHub } from "@services/mcp/McpHub"
55
import { BrowserSettings } from "@shared/BrowserSettings"
66

7-
import { createAntmlToolPrompt, createSimpleXmlToolPrompt } from "@core/prompts/model_prompts/jsonToolToXml"
8-
import {bashToolDefinition} from "@core/tools/bashTool"
7+
import { createAntmlToolPrompt, createSimpleXmlToolPrompt, toolDefinitionToSimpleXml } from "@core/prompts/model_prompts/jsonToolToXml"
8+
import { bashToolDefinition } from "@core/tools/bashTool"
9+
import { readToolDefinition } from "@core/tools/readTool"
10+
import { writeToolDefinition } from "@core/tools/writeTool"
911

1012
export const SYSTEM_PROMPT_CLAUDE4 = async (
1113
cwd: string,
@@ -14,7 +16,7 @@ export const SYSTEM_PROMPT_CLAUDE4 = async (
1416
browserSettings: BrowserSettings,
1517
) => `
1618
17-
${/* createAntmlToolPrompt([bashToolDefinition], true) */''}
19+
${/* createAntmlToolPrompt([bashToolDefinition, readToolDefinition, writeToolDefinition], true) */''}
1820
1921
You are Cline, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.
2022

src/core/tools/readTool.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const DEFAULT_LINE_LIMIT = 2000
2+
const MAX_LINE_LENGTH = 2000
3+
4+
const descriptionForAgent = `Reads a file from the local filesystem. You can access any file directly by using this tool.
5+
Assume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.
6+
7+
Usage:
8+
- The file_path parameter must be an absolute path, not a relative path
9+
- By default, it reads up to ${DEFAULT_LINE_LIMIT} lines starting from the beginning of the file
10+
- You can optionally specify a line offset and limit (especially handy for long files), but it's recommended to read the whole file by not providing these parameters
11+
- Any lines longer than ${MAX_LINE_LENGTH} characters will be truncated
12+
- Results are returned using cat -n format, with line numbers starting at 1
13+
- This tool allows Cline to read images (eg PNG, JPG, etc). When reading an image file the contents are presented visually as Cline is a multimodal LLM.
14+
- You have the capability to call multiple tools in a single response. It is always better to speculatively read multiple files as a batch that are potentially useful.
15+
- You will regularly be asked to read screenshots. If the user provides a path to a screenshot ALWAYS use this tool to view the file at the path. This tool will work with all temporary file paths like /var/folders/Temporary_Screenshots/2026-09-08/Screenshot.png
16+
- If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.`
17+
18+
export const readToolDefinition = {
19+
name: "Read",
20+
descriptionForAgent: descriptionForAgent,
21+
inputSchema: {
22+
type: "object",
23+
properties: {
24+
file_path: {
25+
type: "string",
26+
description: "The absolute path to the file to read",
27+
},
28+
offset: {
29+
type: "number",
30+
description: "The line number to start reading from. Only provide if the file is too large to read at once",
31+
optional: true,
32+
},
33+
limit: {
34+
type: "number",
35+
description: "The number of lines to read. Only provide if the file is too large to read at once.",
36+
optional: true,
37+
},
38+
},
39+
required: ["file_path"],
40+
},
41+
}

src/core/tools/writeTool.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const descriptionForAgent = `Writes a file to the local filesystem.
2+
3+
Usage:
4+
- The file_path parameter must be an absolute path, not a relative path
5+
- This tool will overwrite the existing file if there is one at the provided path.
6+
- If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.
7+
- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
8+
- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.`
9+
10+
export const writeToolDefinition = {
11+
name: "Write",
12+
descriptionForAgent: descriptionForAgent,
13+
inputSchema: {
14+
type: "object",
15+
properties: {
16+
file_path: {
17+
type: "string",
18+
description: "The absolute path to the file to write (must be absolute, not relative)",
19+
},
20+
content: {
21+
type: "string",
22+
description: "The content to write to the file",
23+
},
24+
},
25+
required: ["file_path", "content"],
26+
},
27+
}

0 commit comments

Comments
 (0)