Skip to content

fix(cli): show help when the directory argument doesn't exist - #65262

Merged
rekram1-node merged 1 commit into
devfrom
fix/cli-missing-directory-help
Nov 20, 2026
Merged

rekram1-node merged 1 commit into
devfrom
fix/cli-missing-directory-help

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

opencode <arg> treats an unknown positional as the directory to start in, so a mistyped or missing command like opencode login crashed with a raw ENOENT: no such file or directory, chdir ... -> 'login' stack trace.

The default handler now stats the directory argument before chdir. If it's missing or isn't a directory, it fails with Effect CLI's ShowHelp carrying a ValidationError, so the runner prints the root help followed by:

ERROR
  No directory or command named "login"

and exits 1. Valid directories behave as before.

How did you verify your code works?

  • bun run src/index.ts login and bun run src/index.ts /path/to/a/file both print root help plus the error, exit 1
  • New packages/cli/test/default-directory.test.ts covers both cases; it fails without the fix and passes with it
  • bun run typecheck in packages/cli

Screenshots / recordings

N/A (CLI output shown above)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Requested by: @rekram1-node (Aiden Cline via Slack)


Added by the opencode bot (AI-generated).

Fixes #49663

Related: #47665

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I reproduced the raw ENOENT/ENOTDIR chdir stack trace on the base with opencode login and with a file passed as the directory. With this PR, both print the root help plus No directory or command named "…" and exit 1. A valid directory still gets past the check and starts as before.

Public API: unchanged. The only user-visible change is the error output for an invalid directory argument; the exit code stays 1.

The fix itself is small. The new test file spawns the full CLI twice (about 5s) and isn't needed for a change this size, so it can be dropped, or cut down to just the missing-directory case.

The directory is still checked locally even when --server is given (#47665). That is unchanged from before and out of scope here.

Fixes #49663
Related: #47665

@rekram1-node
rekram1-node enabled auto-merge (squash) November 20, 2026 20:13
@rekram1-node
rekram1-node merged commit 504a7b3 into dev Nov 20, 2026
13 checks passed
@rekram1-node
rekram1-node deleted the fix/cli-missing-directory-help branch November 20, 2026 20:14
@amrkmn amrkmn mentioned this pull request Nov 23, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli: invalid directory arg shows raw ENOENT chdir stack trace instead of friendly error

2 participants