Skip to content

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

@astrolox

Description

@astrolox

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions