Skip to content

feat: Support for sudo and password-requiring commands in Bash tool #9808

@bernatfp

Description

@bernatfp

Problem

The Bash tool currently runs with stdio: ["ignore", "pipe", "pipe"], meaning stdin is disconnected. This breaks any command requiring interactive password input:

  • sudo apt install ...
  • ansible-playbook -K ... (ask-become-pass)
  • ssh -t user@host "sudo ..."
  • GPG passphrase prompts

Users working with system administration, deployment automation, or remote servers cannot use these common workflows through OpenCode.

Proposed Approach

Use PTY-based execution for commands that may require interactive input:

  1. Auto-detect interactive commands - Pattern match for sudo, ssh -t, ansible -K, etc.
  2. PTY execution - Spawn an ephemeral PTY for interactive commands
  3. Prompt detection - Detect password prompts via patterns ([sudo] password for, Password:, BECOME password:, etc.)
  4. SecureInput system - Event-based system that requests password from user when prompt detected
  5. Direct PTY write - Password goes directly to PTY, never stored or logged
  6. Output sanitization - Replace password prompts with [Password prompt - user input required] before sending to LLM

Security considerations

  • Password never logged or stored in memory beyond immediate use
  • Password never appears in conversation history or LLM context
  • UI uses type="password" input
  • 60s timeout, max 3 retry attempts

Why it belongs in OpenCode

This is a common pain point for DevOps/sysadmin workflows. The PTY infrastructure already exists for the terminal feature, so this leverages existing code. It's also how Claude Code handles similar scenarios.

Happy to share implementation details if there's interest.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions