opencode icon indicating copy to clipboard operation
opencode copied to clipboard

App becomes unresponsive when executing commands requiring sudo password

Open delorenj opened this issue 1 year ago • 3 comments

Description

When opencode executes a command that requires a sudo password, the application becomes unresponsive and hangs indefinitely.

Root Cause

The bash tool in packages/opencode/src/tool/bash.ts spawns processes without stdin connected:

const process = Bun.spawn({
  cmd: ["bash", "-c", params.command],
  cwd: App.info().path.cwd,
  maxBuffer: MAX_OUTPUT_LENGTH,
  signal: ctx.abort,
  timeout: timeout,
  stdout: "pipe",
  stderr: "pipe",
  // stdin is not specified, defaults to null/closed
})

When a sudo command is executed, it waits for password input that can never be provided, causing the process to hang until the timeout (default 1 minute).

Expected Behavior

  • Detect commands that require sudo
  • Either:
    • Provide a clear error message explaining that sudo commands are not supported
    • Or implement a mechanism to handle password prompts safely

Steps to Reproduce

  1. Ask opencode to run any command requiring sudo (e.g., sudo apt update)
  2. The app becomes unresponsive while waiting for the password prompt that can't be answered

Proposed Solution

Add detection for sudo commands and provide appropriate error handling before execution.

delorenj avatar Jul 03 '25 14:07 delorenj

Still having this problem myself.

acsezen avatar Aug 15 '25 11:08 acsezen

happened today. looking to do some major changes on the system and app can't get through them due to this. Did this, but hasn't worked all the time.

  1. Pre-authenticate sudo before running OpenCode: sudo -v

Then run opencode

  1. This caches your sudo credentials for 15 minutes.
  2. Configure sudo to not require password for specific commands (use cautiously): sudo visudo
  3. Add a line like: yourusername ALL=(ALL) NOPASSWD: /usr/bin/apt, /usr/bin/apt-get
  4. Use a separate terminal for sudo commands: - Keep OpenCode in one terminal - Run sudo commands in another terminal when needed
  5. Check if OpenCode has a flag to handle sudo better: - Look for options like --no-sudo or --external-sudo - Check their documentation or --help

seheart avatar Aug 17 '25 01:08 seheart

[automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!

rekram1-node avatar Dec 28 '25 01:12 rekram1-node