[PR #3522] fix: resolve hanging permission prompts in headless mode #10681

Closed
opened 2026-02-16 18:15:24 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/3522

State: closed
Merged: Yes


Fix: Resolve Hanging Permission Prompts in Headless Mode

Problem

When "permissions": { "bash": "ask" } is set in opencode.json and OpenCode is run in headless mode (e.g., opencode run), the application hangs silently when a bash command is requested. This happens because there is no handler to respond to the permission.ask hook, so the process waits forever for user input that never arrives.

Solution

This PR adds a built-in CLI permission handler that uses @clack/prompts to interactively prompt the user for permission in headless and run modes. The handler is always loaded as part of the plugin system, ensuring permissions can be confirmed or denied in all environments.

Key Changes

  • New: src/cli/permission-handler.ts

    • Implements createCliPermissionHandler using @clack/prompts
    • Handles permission.ask by showing a confirmation dialog and returning "allow" or "deny" based on user input
  • Modified: src/plugin/index.ts

    • Integrates the CLI permission handler into the plugin system so it is always available
  • New: test/cli/permission-handler.test.ts

    • Adds unit tests to verify the handler's structure and basic behavior

How It Works

  1. When a tool requests permission (e.g., for bash), the permission system triggers the permission.ask hook.
  2. The CLI handler prompts the user in the terminal with a clear message.
  3. The user can confirm or deny the request.
  4. The handler responds with "allow" or "deny", unblocking the process.

Closes #3503

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/3522 **State:** closed **Merged:** Yes --- ## Fix: Resolve Hanging Permission Prompts in Headless Mode ### Problem When `"permissions": { "bash": "ask" }` is set in `opencode.json` and OpenCode is run in headless mode (e.g., `opencode run`), the application hangs silently when a bash command is requested. This happens because there is no handler to respond to the `permission.ask` hook, so the process waits forever for user input that never arrives. ### Solution This PR adds a built-in CLI permission handler that uses `@clack/prompts` to interactively prompt the user for permission in headless and run modes. The handler is always loaded as part of the plugin system, ensuring permissions can be confirmed or denied in all environments. #### Key Changes - **New:** `src/cli/permission-handler.ts` - Implements `createCliPermissionHandler` using `@clack/prompts` - Handles `permission.ask` by showing a confirmation dialog and returning `"allow"` or `"deny"` based on user input - **Modified:** `src/plugin/index.ts` - Integrates the CLI permission handler into the plugin system so it is always available - **New:** `test/cli/permission-handler.test.ts` - Adds unit tests to verify the handler's structure and basic behavior #### How It Works 1. When a tool requests permission (e.g., for bash), the permission system triggers the `permission.ask` hook. 2. The CLI handler prompts the user in the terminal with a clear message. 3. The user can confirm or deny the request. 4. The handler responds with `"allow"` or `"deny"`, unblocking the process. --- **Closes #3503**
yindo added the pull-request label 2026-02-16 18:15:24 -05:00
yindo closed this issue 2026-02-16 18:15:25 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10681