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
Agent hangs indefinitely when using opencode serve + opencode attach if any permission is set to "ask" #16367
When running opencode serve and connecting remotely via opencode attach, the agent enters an infinite processing loop and never returns a response. The TUI connects and displays fine, but sending any message causes the agent to spin forever.
Version
1.2.20
Steps to Reproduce
Start a headless server: opencode serve --hostname 0.0.0.0 --port <port>
From a remote machine, attach to it: opencode attach http://<host>:<port>
Send any message to the agent in the remote TUI
Expected Behavior
The agent processes the message and returns a response, same as when running opencode locally.
Actual Behavior
The agent enters an infinite processing loop and never completes. The remote TUI shows the agent as permanently "thinking". No error is shown.
Root Cause
The default permission for doom_loop (and external_directory) is "ask", which triggers an interactive approval prompt in the TUI. When running in headless server mode (opencode serve), those prompts have no UI to surface them through — and opencode attach does not relay permission prompts from the server to the remote client. The server silently waits for input that never arrives, causing the agent to hang indefinitely.
This can be confirmed in the server logs: the agent loops through tool resolution steps repeatedly without ever completing or erroring.
Workaround
Create an opencode.json config (e.g. at ~/.opencode/opencode.json or the project-level equivalent) that sets doom_loop and external_directory to "allow":
This issue might be a duplicate of existing issues. Please check:
Bash permission 'ask' hangs forever in headless/server mode #14473: Same root cause — permission set to "ask" hangs forever in headless/server mode (opencode serve), including the same external_directory permission and the same workaround of setting permissions to "allow"
I recently faced this issue and I noticed (and also tested by removing it afterward) that having this in the opencode.json configuration just cause everything to slow/hang/not responsive. Removing it makes my OpenCode run fast again.
my innocent mind just want to allow opencode to read download directory freely 🥲
For headless/server mode, ask probably needs to become an explicit pending state with an approval channel, not an in-process prompt.
If no approval channel is attached, failing closed with a structured error seems safer than hanging and safer than forcing users to change config to allow.
The useful fields for a pending permission are tool/action, normalized target, session id, requested scope, and a resume token. That would let attach/TUI/web clients render the same pending decision and resume once approved or denied.
Activity
github-actions commentedon Mar 6, 2026
This issue might be a duplicate of existing issues. Please check:
"ask"hangs forever in headless/server mode (opencode serve), including the sameexternal_directorypermission and the same workaround of setting permissions to"allow"dhowe commentedon Mar 22, 2026
Still seeing this issue, and the workaround mentioned by @shaugupt doesn't fix it
namdien177 commentedon Apr 19, 2026
I recently faced this issue and I noticed (and also tested by removing it afterward) that having this in the
opencode.jsonconfiguration just cause everything to slow/hang/not responsive. Removing it makes my OpenCode run fast again.oleg-bk commentedon May 27, 2026
For headless/server mode,
askprobably needs to become an explicit pending state with an approval channel, not an in-process prompt.If no approval channel is attached, failing closed with a structured error seems safer than hanging and safer than forcing users to change config to
allow.The useful fields for a pending permission are tool/action, normalized target, session id, requested scope, and a resume token. That would let attach/TUI/web clients render the same pending decision and resume once approved or denied.
ashish16052 commentedon Jul 9, 2026
For API clients, the server-side flow that has worked for me is to handle permission events explicitly.
Listen for
permission.asked, show/decide the permission in the host app, then POST the reply back to the permission endpoint.Example:
https://github.com/ashish16052/opencode-runtime/blob/main/docs/streaming.md#handle-permission-requests
This does not fix the attach/TUI relay issue directly, but it may be useful as the expected headless/API behavior.
github-actions commentedon Sep 8, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.