Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/opencode/src/tool/external-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ export async function assertExternalDirectory(ctx: Tool.Context, target?: string

if (options?.bypass) return

if (Instance.containsPath(target)) return
// Instance context may not be available in certain execution paths (e.g., MCP, plugins)
// Skip the containsPath check if context is missing - permission will still be requested
try {
if (Instance.containsPath(target)) return
} catch {
// Instance context not available - proceed to ask for permission
}

const kind = options?.kind ?? "file"
const parentDir = kind === "directory" ? target : path.dirname(target)
Expand Down
11 changes: 10 additions & 1 deletion packages/opencode/src/tool/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ export const ReadTool = Tool.define("read", {
if (!path.isAbsolute(filepath)) {
filepath = path.join(process.cwd(), filepath)
}
const title = path.relative(Instance.worktree, filepath)

// Instance context may not be available in certain execution paths (e.g., MCP, plugins)
// Gracefully handle missing context to avoid cryptic native binding errors
let worktree: string | undefined
try {
worktree = Instance.worktree
} catch {
// Instance context not available - fall back to basename for title
}
const title = worktree ? path.relative(worktree, filepath) : path.basename(filepath)

await assertExternalDirectory(ctx, filepath, {
bypass: Boolean(ctx.extra?.["bypassCwdCheck"]),
Expand Down