Skip to content

Does OpenCode suffer from memory leaks? A single window is consuming over 20 GB of memory. #20626

Closed

Description

@silent-night-no-trace

Description

I had three windows open in OpenCode on my 64GB M5 Pro, and the fan was whirring loudly. I suspected that a specific application was consuming an excessive amount of memory. Initially, I thought it might be Chrome; closing it did free up a small amount of memory, so I proceeded to close my other applications one by one. Finally, I closed just one of the OpenCode windows and discovered that it immediately released 20GB of memory. Why would it consume such a massive amount of memory?

I am using version 1.3.2 and am still encountering this issue.

Plugins

oh-my-opencode

OpenCode version

1.3.2

Steps to reproduce

When I leave the window open and running continuously—specifically, after keeping it open for several hours—I notice that the memory usage becomes extremely high.

Screenshot and/or share link

No response

Operating System

macos 26.3

Terminal

iterm2

Activity

  1. added
    perfIndicates a performance issue or need for optimization
    on Apr 2, 2026
  2. github-actions commented on Apr 2, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is distinct from the above, please add context explaining how it differs.

  3. silent-night-no-trace commented on Apr 2, 2026

    @silent-night-no-trace
    Author

    I am using version 1.3.2 and am still encountering this issue. How can I resolve it?

  4. max-flizpay commented on Apr 2, 2026

    @max-flizpay

    Lets just rewrite OpenCode in Rust?

  5. jwcrystal commented on Apr 2, 2026

    @jwcrystal

    This looks like a real long-running memory growth issue rather than a single one-off allocation.

    The most likely root causes are:

    1. Unbounded SSE/event buffering for long-lived windows

      • The app keeps long-lived event streams open.
      • If a client/window becomes slow or disconnect cleanup does not happen promptly, queued events can keep accumulating in memory.
      • This is especially bad for high-frequency events (message deltas, tool updates, etc.), and is much more likely to produce multi-GB growth than heartbeats alone.
    2. Shell/tool output retained in memory

      • Large stdout/stderr from bash/tool execution was being accumulated in memory instead of being capped/spilled early.
      • In a long-running session, a few large commands or repeated tool usage can compound badly.
    3. Session prompt subprocess output also had the same accumulation pattern

      • There was a second output-retention path in prompt/session execution, so the problem was not limited to one tool path.

    Why this matches the symptom: if one OpenCode window owns those queues/buffers, closing that single window would immediately release a very large amount of memory, which is exactly what was reported here.

    So the short version is: likely a combination of unbounded event queue growth + unbounded shell output retention over time.

  6. thdxr commented on Apr 2, 2026

    @thdxr
    Member

    Closing in favor of #20695 where we're collecting all memory-related problems. Please follow that issue for updates.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingperfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions