Skip to content

opencode run hangs after completing tool calls — process never exits #17516

Description

@alephmelo

Description

opencode run hangs indefinitely after completing all tool calls. The model finishes its work (reads a file, writes a file), but the process never exits. It stays alive with no output, requiring a manual kill.

Reproduction

# Create a simple prompt that asks the model to edit a file
echo "Read compress.py and rewrite it with a better algorithm. Edit the file and exit." \
  | opencode run -m github-copilot/claude-sonnet-4.6

The agent:

  1. Reads the file (tool call completes, output shown)
  2. Writes the file (tool call completes, "Wrote file successfully." shown)
  3. Hangs indefinitely — no more output, process stays alive

Observed behavior

> build · claude-sonnet-4.6

→ Read compress.py

← Write compress.py
Wrote file successfully.

# <--- hangs here forever, no exit

Expected behavior

After the model finishes all tool calls and produces its final response, opencode run should exit with code 0.

Context

This was discovered while using opencode run as the agent command in a CLI optimization loop (ratchet). The loop spawns opencode run via sh -c with stdin redirection (< prompt.md), monitors try_wait() on the child process, and expects it to exit after the model completes. The process never terminates, causing the loop to freeze.

Simple prompts (e.g., "What is 2+2?") exit fine. The hang occurs specifically when the model uses tools (Read/Write) and then has nothing left to do.

Environment

  • opencode version: 1.2.26
  • macOS (darwin)
  • Model: github-copilot/claude-sonnet-4.6
  • Invocation: opencode run -m github-copilot/claude-sonnet-4.6 < prompt.md

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions