Skip to content

fix: clear terminal buffers when switching between projects#26318

Open
lyy-pineapple wants to merge 2 commits into
anomalyco:devfrom
lyy-pineapple:fix/terminal-buffer-clear-on-project-switch
Open

fix: clear terminal buffers when switching between projects#26318
lyy-pineapple wants to merge 2 commits into
anomalyco:devfrom
lyy-pineapple:fix/terminal-buffer-clear-on-project-switch

Conversation

@lyy-pineapple
Copy link
Copy Markdown

@lyy-pineapple lyy-pineapple commented May 8, 2026

Issue for this PR

Closes #26316

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When switching between projects (directories) in the web UI, stale terminal buffers persisted from a previous session were being restored, causing old terminal output to appear mixed with new output.

The root cause: packages/app/src/context/terminal.tsx calls trimAll() on the previous workspace when navigating away, but does NOT clear stale buffers on the new workspace. When the terminal component mounts, it restores from persisted buffer data that belongs to an old PTY session, displaying garbage before the new PTY connection delivers fresh content.

The fix adds a workspace().trimAll() call when next.dir !== prev.dir, clearing persisted terminal buffers on the destination workspace when switching to a different directory. This is a targeted 3-line change in the existing createEffect that already handles workspace transitions.

How did you verify your code works?

  1. Ran opencode web, opened terminal in Project A, executed commands
  2. Switched to Project B — terminal now shows only the fresh prompt (no stale output from Project A)
  3. Switched between sessions within the same project — terminal state preserved correctly (no regression)
  4. Verified the trimAll() function correctly strips buffer, cursor, and scrollY while preserving terminal identity (id, title, titleNumber)

Screenshots / recordings

N/A — no UI component changes, only state management logic.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When switching to a different directory/project, stale terminal buffers
persisted from a previous session were being restored, causing old
terminal output to appear mixed with new output.

This adds a trimAll() call on the new workspace when the directory
changes, ensuring fresh terminal state on project switch.

Fixes anomalyco#26316
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels May 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@lyy-pineapple
Copy link
Copy Markdown
Author

@adamdotdevin Can you help review this?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal buffer not cleared when switching projects in web mode

1 participant