You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
command: z.string().describe("The command to execute"),
92
91
timeout: z.number().describe("Optional timeout in milliseconds").optional(),
92
+
workdir: z
93
+
.string()
94
+
.describe(
95
+
`The working directory to run the command in. Defaults to ${Instance.directory}. Use this instead of 'cd' commands.`,
96
+
)
97
+
.optional(),
93
98
description: z
94
99
.string()
95
100
.describe(
96
101
"Clear, concise description of what this command does in 5-10 words. Examples:\nInput: ls\nOutput: Lists files in current directory\n\nInput: git status\nOutput: Shows working tree status\n\nInput: npm install\nOutput: Installs package dependencies\n\nInput: mkdir foo\nOutput: Creates directory 'foo'",
97
102
),
98
103
}),
99
104
asyncexecute(params,ctx){
105
+
constcwd=params.workdir||Instance.directory
100
106
if(params.timeout!==undefined&¶ms.timeout<0){
101
107
thrownewError(`Invalid timeout value: ${params.timeout}. Timeout must be a positive number.`)
Copy file name to clipboardExpand all lines: packages/opencode/src/tool/bash.txt
+18-11Lines changed: 18 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -7,31 +7,38 @@ Before executing the command, please follow these steps:
7
7
- For example, before running "mkdir foo/bar", first use List to check that "foo" exists and is the intended parent directory
8
8
9
9
2. Command Execution:
10
-
- Always quote file paths that contain spaces with double quotes (e.g., cd "path with spaces/file.txt")
10
+
- Always quote file paths that contain spaces with double quotes (e.g., rm "path with spaces/file.txt")
11
11
- Examples of proper quoting:
12
-
- cd "/Users/name/My Documents" (correct)
13
-
- cd /Users/name/My Documents (incorrect - will fail)
12
+
- mkdir "/Users/name/My Documents" (correct)
13
+
- mkdir /Users/name/My Documents (incorrect - will fail)
14
14
- python "/path/with spaces/script.py" (correct)
15
15
- python /path/with spaces/script.py (incorrect - will fail)
16
16
- After ensuring proper quoting, execute the command.
17
17
- Capture the output of the command.
18
18
19
19
Usage notes:
20
20
- The command argument is required.
21
-
- You can specify an optional timeout in milliseconds (up to 600000ms / 10 minutes). If not specified, commands will timeout after 120000ms (2 minutes).
21
+
- You can specify an optional timeout in milliseconds. If not specified, commands will timeout after 120000ms (2 minutes). Use the `timeout` parameter to control execution time.
22
+
- The `workdir` parameter specifies the working directory for the command. Defaults to the current working directory. Prefer setting `workdir` over using `cd` in your commands.
22
23
- It is very helpful if you write a clear, concise description of what this command does in 5-10 words.
23
24
- If the output exceeds 30000 characters, output will be truncated before being returned to you.
24
25
- VERY IMPORTANT: You MUST avoid using search commands like `find` and `grep`. Instead use Grep, Glob, or Task to search. You MUST avoid read tools like `cat`, `head`, `tail`, and `ls`, and use Read and List to read files.
25
26
- If you _still_ need to run `grep`, STOP. ALWAYS USE ripgrep at `rg` (or /usr/bin/rg) first, which all opencode users have pre-installed.
26
27
- When issuing multiple commands, use the ';' or '&&' operator to separate them. DO NOT use newlines (newlines are ok in quoted strings).
27
-
- Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of `cd`. You may use `cd` if the User explicitly requests it.
28
-
<good-example>
29
-
pytest /foo/bar/tests
30
-
</good-example>
31
-
<bad-example>
32
-
cd /foo/bar && pytest tests
33
-
</bad-example>
34
28
29
+
# Working Directory
30
+
31
+
The `workdir` parameter sets the working directory for command execution. Prefer using `workdir` over `cd <dir> &&` command chains when you simply need to run a command in a different directory.
0 commit comments