From 44dc124cdf50b911ca0f159360dd00f7ceaade5c Mon Sep 17 00:00:00 2001 From: zerone0x Date: Tue, 13 Jan 2026 15:35:40 +0800 Subject: [PATCH] fix(cli): skip local agent validation in attach mode When using `opencode run --attach` with the `--agent` flag, the CLI would crash with "No context found for instance" because Agent.get() requires the Instance context that is only available after bootstrap(). In attach mode, bootstrap() is never called since we're connecting to a remote server. This fix skips local agent validation in attach mode, allowing the remote server to handle agent validation instead. Fixes #6489 #8094 Co-Authored-By: Claude --- packages/opencode/src/cli/cmd/run.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts index 54248f96f3df..7bb61091f8d7 100644 --- a/packages/opencode/src/cli/cmd/run.ts +++ b/packages/opencode/src/cli/cmd/run.ts @@ -231,6 +231,8 @@ export const RunCommand = cmd({ // Validate agent if specified const resolvedAgent = await (async () => { if (!args.agent) return undefined + // Skip local agent validation in attach mode - the remote server handles it + if (args.attach) return args.agent const agent = await Agent.get(args.agent) if (!agent) { UI.println(