-
Notifications
You must be signed in to change notification settings - Fork 12k
Description
Description
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":
{
"$schema": "https://opencode.ai/config.json",
"permission": {
"*": "allow",
"doom_loop": "allow",
"external_directory": "allow"
}
}Then restart the server. The agent will process messages normally.
Suggested Fix
opencode serve should either:
- Automatically override "ask" permissions to "allow" when running in headless mode (since there is no interactive terminal to answer prompts), or
- Relay permission prompts to the attached remote client's TUI so they can be answered there, or
- Warn at startup that certain permissions are set to "ask" which will cause hangs in headless mode
Additional Context
The issue is specific to the opencode serve + opencode attach workflow. Running opencode locally (non-headless) is unaffected.