Skip to content

Commit d6f8783

Browse files
Adam Spiersclaude
andcommitted
feat(write): add external directory permission check
Without this patch, the write tool had a TODO comment for checking external directory permissions but the implementation was incomplete. This meant that write operations to paths outside the working directory would proceed without requesting user permission. This is a problem because write operations outside the project directory could be security-sensitive, and users should be informed and able to approve or deny such operations. This patch solves the problem by implementing the external directory permission check using `ctx.ask()` with the `external_directory` permission type, following the same pattern used in other tools like bash. The check includes the parent directory pattern and provides appropriate metadata for permission message formatting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent cefbfbd commit d6f8783

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/opencode/src/tool/write.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ export const WriteTool = Tool.define("write", {
2222
}),
2323
async execute(params, ctx) {
2424
const filepath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
25-
/* TODO
2625
if (!Filesystem.contains(Instance.directory, filepath)) {
2726
const parentDir = path.dirname(filepath)
28-
...
27+
await ctx.ask({
28+
permission: "external_directory",
29+
patterns: [parentDir],
30+
always: [parentDir + "/*"],
31+
metadata: {
32+
filepath,
33+
parentDir,
34+
},
35+
})
2936
}
30-
*/
3137

3238
const file = Bun.file(filepath)
3339
const exists = await file.exists()

0 commit comments

Comments
 (0)