You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(core): add interactive pty tool for retained REPL, debugger, and EOF-driven terminal sessions #65017
OpenCode's shell tool handles one-shot commands and background jobs well, but agents currently have no native tool to drive an interactive pseudoterminal (PTY) across multiple steps — such as Python/Node REPLs, gdb/lldb/pdb debuggers, psql/redis-cli, interactive setup wizards, or programs that prompt for line input and canonical TTY EOF (Ctrl+D).
OpenCode already ships both PersistentPty.Service (backed by the embedded @opencode/pty daemon) and Pty.Service (#pty) for TUI terminals, but neither is exposed as an agent-callable tool.
Proposal
Expose a built-in pty tool (packages/core/src/tool/plugin/pty.ts) backed by PersistentPty.Service (with automatic fallback to local Pty.Service when the daemon is unavailable):
open: Launch a command (or login shell) in a retained PTY (cols/rows, TERM=xterm-256color, OPENCODE_SESSION_ID), enforcing the same ShellParse, FileAccess, and shell permission checks as ShellTool, returning { ptyID, status, exitCode, output, cursor, timedOut, matched }.
write: Send verbatim input (input, including \n when submitting a line), interrupt: true (Ctrl+C), or eof: true (Ctrl+D / \x04 canonical TTY EOF) to an owned ptyID and stream newly produced output.
read: Read or wait (waitFor substring or /regex/flags, bounded by timeout) for incremental output from the tracked session cursor.
close: Terminate and release a retained PTY session, returning any remaining unread output.
Session isolation & cleanup: Restrict write/read/close to the session that opened ptyID, and automatically tear down owned sessions on SessionEvent.Deleted.
You're asking for a built-in pty tool so the agent can keep an interactive terminal session (REPLs, debuggers, psql, setup wizards) open across steps. It would send input, Ctrl+C or Ctrl+D, and read new output as it arrives. Maintainers will consider it.
What I found in the current V2 code:
The shell tool (packages/core/src/tool/plugin/shell.ts) takes command, workdir, timeout and background. Background commands return immediately and notify the session when they finish, and foreground commands that run past their timeout move to the background. I didn't find any way in that tool to send input to a process that is still running.
Plugins can define tools, but the only terminal access they get is experimental.terminal.read (packages/core/src/plugin/host.ts). So a plugin can't open a PTY, write to it or close it yet, and I haven't written one. If the plugin API exposed opening, writing to and closing a session-scoped PTY, this could also be built as a plugin.
Thanks! Per CONTRIBUTING.md ("wait for design approval before opening the implementation PR"), we pushed a focused V2 reference implementation + test suite (11/11bun test covering both PersistentPty daemon and Pty fallback, tsc -b + oxlint clean) to TraceLite-AI:interactive-pty-tool in case it helps design review — happy to open a PR or adapt it to a PluginHost surface if maintainers prefer.
Activity
opencodejr commentedon Nov 19, 2026
Thanks for the detailed proposal, @zsicheng0214!
You're asking for a built-in
ptytool so the agent can keep an interactive terminal session (REPLs, debuggers,psql, setup wizards) open across steps. It would send input, Ctrl+C or Ctrl+D, and read new output as it arrives. Maintainers will consider it.What I found in the current V2 code:
packages/core/src/tool/plugin/shell.ts) takescommand,workdir,timeoutandbackground. Background commands return immediately and notify the session when they finish, and foreground commands that run past their timeout move to the background. I didn't find any way in that tool to send input to a process that is still running.experimental.terminal.read(packages/core/src/plugin/host.ts). So a plugin can't open a PTY, write to it or close it yet, and I haven't written one. If the plugin API exposed opening, writing to and closing a session-scoped PTY, this could also be built as a plugin.Related issues and PRs:
interactive_*tools that ran a process under a PTY. It was closed without merging when the branch moved to V2.zsicheng0214 commentedon Nov 19, 2026
Thanks! Per
CONTRIBUTING.md("wait for design approval before opening the implementation PR"), we pushed a focused V2 reference implementation + test suite (11/11bun testcovering bothPersistentPtydaemon andPtyfallback,tsc -b+oxlintclean) toTraceLite-AI:interactive-pty-toolin case it helps design review — happy to open a PR or adapt it to aPluginHostsurface if maintainers prefer.