exit code is not non-zero when using opencode run #1652

Closed
opened 2026-02-16 17:31:57 -05:00 by yindo · 1 comment
Owner

Originally created by @astrolox on GitHub (Sep 8, 2025).

Originally assigned to: @rekram1-node on GitHub.

Bug

When using opencode run, I sometimes run into an error.

I expect that in such cases the return code from the application to be non-zero, as per convention in unix/linux world.

Unfortunately the exit code often appears to be zero when an error occurred. This leads makes it hard to detect failure in my scripts.

Steps to reproduce

  1. setup an invalid API key for openrouter

  2. attempt to use an openrouter model via opencode run

$ opencode run -m openrouter/qwen/qwen3-coder "Test"; echo $?
Error: AI_APICallError: No auth credentials found

0

This is not just limited to auth errors; I originally noticed this problem when I received the following error message;

Error: AI_APICallError: prompt token count of 129923 exceeds the limit of 128000                                                     

Exit code was zero.

I presume the reason for this is because in the TUI such an error would not cause the application to exit (you could send a new message, switch models, etc). However in the CLI the application exits immediately.

Related observation

I notice that having no auth setup at all correctly produces a non-zero exit code, hence the first step in my above instructions is required to reproduce the problem.

$ opencode run -m openrouter/qwen/qwen3-coder "Test"; echo $?
Error: Unexpected error, check log file at /home/brian/.local/share/opencode/log/2025-09-08T091808.log for more details
1
Originally created by @astrolox on GitHub (Sep 8, 2025). Originally assigned to: @rekram1-node on GitHub. ## Bug When using `opencode run`, I sometimes run into an error. I expect that in such cases the return code from the application to be non-zero, as per convention in unix/linux world. Unfortunately the exit code often appears to be zero when an error occurred. This leads makes it hard to detect failure in my scripts. ## Steps to reproduce 1. setup an invalid API key for openrouter 2. attempt to use an openrouter model via `opencode run` ```bash $ opencode run -m openrouter/qwen/qwen3-coder "Test"; echo $? Error: AI_APICallError: No auth credentials found 0 ``` This is not just limited to auth errors; I originally noticed this problem when I received the following error message; ``` Error: AI_APICallError: prompt token count of 129923 exceeds the limit of 128000 ``` Exit code was zero. I presume the reason for this is because in the TUI such an error would not cause the application to exit (you could send a new message, switch models, etc). However in the CLI the application exits immediately. ## Related observation I notice that having no auth setup at all correctly produces a non-zero exit code, hence the first step in my above instructions is required to reproduce the problem. ```bash $ opencode run -m openrouter/qwen/qwen3-coder "Test"; echo $? Error: Unexpected error, check log file at /home/brian/.local/share/opencode/log/2025-09-08T091808.log for more details 1 ```
yindo closed this issue 2026-02-16 17:31:57 -05:00
Author
Owner

@rekram1-node commented on GitHub (Sep 9, 2025):

will be fixed in next release

@rekram1-node commented on GitHub (Sep 9, 2025): will be fixed in next release
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1652