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
{{ message }}
Repository navigation
Specify an agent when attaching to server fails #6489
This worked reliably until recently. I believe it might be related to this PR #5843.
The primary agent explore is only available in the server being connected to.
opencode run --print-logs --attach "http://ssds-meta-store-api:4096" --model "mercury-sa/Claude-4.5-Opus" --agent "explore" "lightning"
INFO 2025-12-30T23:37:29 +381ms service=default version=1.0.217 args=["run","--print-logs","--attach","http://ssds-meta-store-api:4096","--model","mercury-sa/Claude-4.5-Opus","--agent","explore","lightning"] opencode
ERROR 2025-12-30T23:37:29 +385ms service=default name=instance message=No context found for instance stack=instance: No context found for instance
at use (src/util/context.ts:16:21)
at directory (src/project/instance.ts:41:20)
at <anonymous> (src/project/instance.ts:50:31)
at <anonymous> (src/project/state.ts:14:19)
at get (src/agent/agent.ts:281:12)
at get (src/agent/agent.ts:280:29)
at <anonymous> (src/cli/cmd/run.ts:230:35)
at <anonymous> (src/cli/cmd/run.ts:228:48)
at <anonymous> (src/cli/cmd/run.ts:247:21)
at async <anonymous> (src/cli/cmd/run.ts:311:20)
at processTicksAndRejections (native:7:39) fatal
Error: Unexpected error, check log file at for more details
instance: No context found for instance
at use (src/util/context.ts:16:21)
at directory (src/project/instance.ts:41:20)
at src/project/instance.ts:50:31
at src/project/state.ts:14:19
at get (src/agent/agent.ts:281:12)
at get (src/agent/agent.ts:280:29)
at src/cli/cmd/run.ts:230:35
at src/cli/cmd/run.ts:228:48
at src/cli/cmd/run.ts:247:21
at src/cli/cmd/run.ts:311:20
at processTicksAndRejections (native:7:39)
OpenCode version
1.0.217
Steps to reproduce
opencode run --print-logs --attach "http://ssds-meta-store-api:4096" --model "mercury-sa/Claude-4.5-Opus" --agent "explore" "lightning"
I conducted additional tests. The latest release is 1.0.219, and it fails for any agent. It appears that specifying the agent when using run with attach is no longer possible.
This is a regression introduced in #5843. That PR added agent validation logic at run.ts:228-248 which calls Agent.get(args.agent). This function requires Instance context (via AsyncLocalStorage) that is established by bootstrap().
The problem: In attach mode (line 274), bootstrap() is never called - the code directly creates an SDK client and executes. Without bootstrap(), there's no Instance context, causing context.use() to throw NotFound.
Mode
bootstrap() called?
Instance Context?
Agent.get() works?
Normal
Yes
Available
Yes
Attach
No
Missing
Crashes
Fix
PR #6541 skips local agent validation in attach mode, letting the remote server handle it instead.
@rekram1-node As you can see, I've figured out how to reopen the issue. I wanted to ask if it would be possible to release this soon. Thanks again for everything you and your team are doing. This is great stuff!
@rekram1-node I tested this with version 1.1.8, and it seems to be fixed. It no longer errors when providing an agent, but it doesn't execute the request and simply returns to the client. However, if I don't use the --agent flag, it respects the default agent set on the server. So, that's a good workaround for now.
Yes, indeed. The code crashes with a fatal error, but it remains silent. You only see in the log:
INFO 2026-02-02T14:10:28 +165ms service=default version=0.0.0-dev-fork-202602021405 args=["run","--format","json","--attach","http://localhost:4096","--log-level","DEBUG","--model","google/gemini-2.5-flash","--agent","shell_cmd_generator","--title","shell assistant","<user>personal prompt here</user>"] opencode
ERROR 2026-02-02T14:10:28 +221ms service=default name=instance message=No context found for instance stack=instance: No context found for instance
at use (src/util/context.ts:16:21)
at directory (src/project/instance.ts:46:20)
at <anonymous> (src/project/instance.ts:67:31)
at <anonymous> (src/project/state.ts:14:19)
at get (src/agent/agent.ts:250:12)
at <anonymous> (src/cli/cmd/run.ts:234:35)
at <anonymous> (src/cli/cmd/run.ts:251:21)
at async <anonymous> (src/cli/cmd/run.ts:338:20)
at processTicksAndRejections (native:7:39) fatal
Activity
mschenk42 commentedon Dec 31, 2025
I traced this error to this version: https://github.com/sst/opencode/releases/tag/v1.0.181. The previous version, v1.0.180, worked perfectly.
mschenk42 commentedon Dec 31, 2025
I conducted additional tests. The latest release is
1.0.219, and it fails for any agent. It appears that specifying the agent when usingrunwithattachis no longer possible.anntnzrb commentedon Dec 31, 2025
Root Cause Analysis
This is a regression introduced in #5843. That PR added agent validation logic at
run.ts:228-248which callsAgent.get(args.agent). This function requiresInstancecontext (viaAsyncLocalStorage) that is established bybootstrap().The problem: In attach mode (line 274),
bootstrap()is never called - the code directly creates an SDK client and executes. Withoutbootstrap(), there's noInstancecontext, causingcontext.use()to throwNotFound.bootstrap()called?Agent.get()works?Fix
PR #6541 skips local agent validation in attach mode, letting the remote server handle it instead.
CC @rekram1-node
mschenk42 commentedon Jan 7, 2026
This was fixed in the 1.1.4 release. Thank you!
Darn, meant this for another issue, this one is still broken :(. @rekram1-node can you reopen this? Sorry about that.
mschenk42 commentedon Jan 7, 2026
@rekram1-node As you can see, I've figured out how to reopen the issue. I wanted to ask if it would be possible to release this soon. Thanks again for everything you and your team are doing. This is great stuff!
mschenk42 commentedon Jan 9, 2026
@rekram1-node I tested this with version 1.1.8, and it seems to be fixed. It no longer errors when providing an agent, but it doesn't execute the request and simply returns to the client. However, if I don't use the --agent flag, it respects the default agent set on the server. So, that's a good workaround for now.
koch-c commentedon Jan 11, 2026
I am on 1.1.12 and I am experiencing the same bug
fix(cli): skip local agent validation in attach mode
bpalomino5 commentedon Jan 28, 2026
i'm on 1.1.25 with the same issue
alberti42 commentedon Feb 2, 2026
Yes, indeed. The code crashes with a fatal error, but it remains silent. You only see in the log:
alberti42 commentedon Feb 2, 2026
I posted a PR #11812 with a fix to this issue.