Description
When switching between projects in the web UI, the terminal displays mixed output from the previous project's PTY session. The backend correctly creates a new PTY with the correct CWD, but the frontend terminal component retains stale persisted buffer content from the previous workspace.
Steps to Reproduce
- Open OpenCode web UI (
opencode web)
- Open a terminal in Project A (e.g., a Python project directory)
- Run some commands (e.g.,
source .venv/bin/activate && python)
- Switch to Project B (a different directory)
- Open a terminal in Project B
Expected Behavior
A clean terminal showing only the new project's prompt:
user@host:/path/to/project-b$
Actual Behavior
Previous terminal content is mixed with the new prompt:
user@host:/path/to/project-b$ from-scratch$ python
Command 'python' not found...
user@host:/path/to/project-a$ source /path/to/project-a/.venv/bin/activate
python
Python 3.12.3 ...
Analysis
From server logs, the backend correctly creates a new PTY session with the correct CWD on each project switch:
INFO service=pty id=pty_xxx cmd=/bin/bash args=["-l"] cwd=/path/to/project-b creating session
The issue is in the frontend terminal context (packages/app/src/context/terminal.tsx). When switching to a different directory:
- The code calls
trimAll() on the PREVIOUS workspace (clearing its buffers)
- But it does NOT clear stale buffers on the NEW workspace that were persisted from a previous session
- The terminal component then restores from these stale persisted buffers, causing old output to appear before the new PTY's fresh output
Environment
- OpenCode version: 1.14.41
- Mode:
opencode web
- OS: Linux x86_64
- Browser: Chrome
Fix
When switching to a different directory, also call trimAll() on the new workspace to clear any stale persisted terminal buffers. See PR.
Description
When switching between projects in the web UI, the terminal displays mixed output from the previous project's PTY session. The backend correctly creates a new PTY with the correct CWD, but the frontend terminal component retains stale persisted buffer content from the previous workspace.
Steps to Reproduce
opencode web)source .venv/bin/activate && python)Expected Behavior
A clean terminal showing only the new project's prompt:
Actual Behavior
Previous terminal content is mixed with the new prompt:
Analysis
From server logs, the backend correctly creates a new PTY session with the correct CWD on each project switch:
The issue is in the frontend terminal context (
packages/app/src/context/terminal.tsx). When switching to a different directory:trimAll()on the PREVIOUS workspace (clearing its buffers)Environment
opencode webFix
When switching to a different directory, also call
trimAll()on the new workspace to clear any stale persisted terminal buffers. See PR.