Skip to content

Conversation

@ritoban23
Copy link
Contributor

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

@rekram1-node
Copy link
Collaborator

Going to check this out tmr

@rekram1-node
Copy link
Collaborator

This isn't quite the right approach, you wanna subscribe to the bus in the run command directly otherwise this will corrupt the tui.

I will make the tweaks to get it working

@rekram1-node rekram1-node merged commit a3ba740 into sst:dev Oct 30, 2025
3 checks passed
groeimetai added a commit to groeimetai/snowcode that referenced this pull request Oct 31, 2025
groeimetai added a commit to groeimetai/snowcode that referenced this pull request Oct 31, 2025
🔥 CRITICAL BUGFIXES:
- Fix hanging permission prompts in headless mode (sst#3522)
- Add doom loop detection (sst#3445)
- Fix MCP metadata preservation (sst#3573)
- Fix agent model selection priority (sst#3572)
- Fix TUI error display
- Fix parcel watcher issue (sst#3544)

🚀 NEW FEATURES:
- Add MCP server timeout configuration (sst#3558)
- Add positional arguments for slash commands (sst#3456)
- Add session ID to agent context metadata (sst#3559)
- Add session.started event hook (sst#3413)
- Add SNOWCODE_CONFIG_DIR support (rebranded from OPENCODE_CONFIG_DIR)

🔧 IMPROVEMENTS:
- Add Zod validation for tool inputs
- Fix MCP status() overwrite issue
- Add bash timeout validation
- Use stdout.write instead of console.log (sst#3508)
- Fix SSE buffer overflow (sst#3531)
- Make build script cross-platform (sst#3430)

🎨 UX ENHANCEMENTS:
- Fix editor paste functionality (sst#3489)
- Better frontmatter error messages
- Configurable provider timeout (sst#3443)

📝 CHANGES:
- 32 files changed, +1,668/-874 lines
- Merged from OpenCode production branch (week 44)
- Bun version check relaxed to 1.3.x

Co-authored-by: OpenCode Contributors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In opencode run mode, "permissions":{"bash": "ask"} hangs silently.

2 participants