Skip to content

[Feature] Allow the user to run their favorite shell in opencode #3228

Closed as not planned

Description

@veracioux

How about we allow ! commands to run the user's preferred shell in interactive mode?

Idea demo

demo.mp4

Brainstorm:

  1. Introduce a config variable called shell or similar, which the user can set to any shell, e.g. bash, sh, fish
  2. When the user types ! we start that shell (spawn a pty and attach that shell process to it)
  3. The user types their commandline in that shell, presses enter, and the shell will execute the command
  4. We detect when the shell has finished running the command and kill it (see implementation idea below)
  5. The whole output is available to the LLM

Benefits:

  • The user can have their *rc files applied for custom prompts etc
  • The user can benefit from their shell's completions
  • OC can benefit from the user's shell history
  • I think this might be a panacea of a lot of potential feature requests (existing or future)

Bonus ideas:

  • For some commands we might be able to detect if they are TUI-like commands and for those we can make sure they are displayed over the entire terminal window instead of just the small prompt box. I'm thinking fzf.
  • We can even try to detect the PWD from the shell and when they cd in the shell, also change the PWD of the OC session

Implementation idea for item no. 4

The easiest way I can think of is this:

  • Introduce a command like opencode shell prompt-start or opencode shell done
  • Instruct the user to modify their shell prompt so that it runs opencode shell prompt-start when the prompt is displayed
    (or alternatively, run opencode shell done in the shell's post-exec hook if supported (I'm a fish user and there you can use the fish_postexec hook)
  • That command signals to the parent OC process that the shell command is done and opencode kills the shell

See also

This is heavily inspired by vterm.el and its handling of the shell. vterm.el (via libvterm) tracks the shell prompt and PWD through invisible OSC escape sequences printed by the shell itself, e.g. \e]51;Auser@host:/pwd\e\\. These sequences are injected at each prompt via a small shell function (like vterm_prompt_end) that’s called from the shell’s prompt hook (PROMPT_COMMAND in bash, fish_prompt in fish, etc.).
vterm.el listens for those sequences to precisely detect where the prompt ends and updates Emacs’ default-directory to match the shell’s current working directory.

Issues that could be addressed with this


I volunteer to implement this. TBH I'll prolly implement this in my fork in any case, but I'll wait for insights and ideas from the OC team :)

Activity

  1. rekram1-node commented on Oct 16, 2025

    @rekram1-node
    Collaborator

    @veracioux i thought we already do that? If you "!" it reads the $SHELL value doesnt it

  2. veracioux commented on Oct 16, 2025

    @veracioux
    ContributorAuthor

    @rekram1-node Not quite what I meant. See the demo I just attached to the description.

  3. rekram1-node commented on Oct 16, 2025

    @rekram1-node
    Collaborator

    Ahh i see yeah thats cool

  4. rekram1-node commented on Oct 16, 2025

    @rekram1-node
    Collaborator

    whoopsie

    it was literally your first sentence lmao:

    interactive mode?

  5. veracioux commented on Oct 16, 2025

    @veracioux
    ContributorAuthor

    @rekram1-node I added "interactive" after edit - so my fault :D

  6. ArabianCowboy commented on Mar 22, 2026

    @ArabianCowboy

    Feature Request: stdin Passthrough for Interactive Process Input (e.g., sudo passwords, SSH passphrases, confirmation prompts)
    I'd like to highlight a specific sub-feature within the broader PTY discussion that I think deserves explicit attention: stdin passthrough during agent-executed commands.
    Currently, when OpenCode runs a command that mid-execution requires user input — such as a sudo password prompt, an SSH passphrase, an npm login OTP, or a simple y/n confirmation — the process hangs and times out. There's no mechanism for the agent to detect that a process is waiting for input and hand control back to the user.
    What the ideal behavior looks like:

    Agent runs a command (e.g., sudo apt install ...)
    The process writes a prompt to the terminal (e.g., [sudo] password for user:)
    OpenCode detects the process is waiting for stdin
    It surfaces the prompt to the user and accepts masked/raw input
    The input is piped back to the running process and execution resumes

    Precedents in other CLIs:

    Gemini CLI implements this via node-pty + enableInteractiveShell, with a Ctrl+F to focus the interactive session
    OpenAI Codex CLI handles this with a dedicated write_stdin tool that feeds keystrokes to a running PTY session

    I also noticed that v1.2.21 already includes a fix(pty): pty session handle leak — which suggests PTY infrastructure is at least partially in the codebase. This might mean the remaining work to expose stdin passthrough is closer than it appears.
    This isn't just a convenience — it's a blocker for any agentic workflow that touches system administration, authentication, or package management. Would love to see this scoped and tracked explicitly, even if it lands after the broader PTY work.

  7. github-actions commented on May 22, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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