Skip to content

High CPU (110%) and memory (2GB) with low context usage (16%) after long session #34226

Closed as not planned

Description

@aaabyf

Environment

  • OS: macOS 26.5.1 (ARM64, MacBook)
  • opencode: installed via Homebrew
  • Provider: deepseek/deepseek-v4-pro
  • Project: non-git Android Java project (~30 files)

Summary

After a ~3 hour coding session, opencode consumes 110% CPU and 2.0 GB physical memory while the context window is only 16% full.

Symptoms

  • CPU fluctuates 66%–110% even when idle between messages
  • Physical memory footprint: 2.0 GB (peak 2.3 GB)
  • opencode.db grew to 180 MB
  • Only one opencode process, no zombie subprocesses
  • Context usage shown in TUI: ~16%

Sample output (1ms interval)

Physical footprint:         2.0G
Physical footprint (peak):  2.3G

799 Thread_2169788   DispatchQueue_1: com.apple.main-thread
  799 start  (in dyld) + 6992
    799 ???  (in opencode)  load address 0x102bd0000 + 0x9bdd0c
      ...
      642 kevent64  (in libsystem_kernel.dylib) + 8       ← event loop idle (80%)
      131 ???  (in opencode)  ... multiple internal frames  ← active work (16%)

80% of samples are in kevent64 (event loop idle), but the 2GB memory footprint suggests significant GC pressure that causes CPU spikes.

Steps to reproduce

  1. Start opencode in a moderate-sized project
  2. Run a long session (~3 hours) with many tool calls (file edits, bash, subagents)
  3. Observe CPU and memory creep over time even when idle

Workaround

Quitting and restarting opencode resolves the issue (memory drops and CPU normalizes).

Notes

  • No plugins installed
  • Session persistence via opencode.db ensures no data loss on restart
  • This could be a GC issue from accumulated context objects not being cleaned up

Activity

  1. aaabyf commented on Jun 27, 2026

    @aaabyf
    Author

    Update: this is reproducible across multiple sessions, not just a one-off. The computer gets noticeably hot every time opencode runs, even in shorter sessions.

  2. github-actions commented on Jun 27, 2026

    @github-actions
    Contributor

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

    • Memory Megathread #20695: Memory Megathread — a dedicated thread for tracking and resolving memory growth issues in opencode. The maintainers are actively collecting heap snapshots there to diagnose exactly this kind of problem (high memory after long sessions). Consider following the instructions in that thread to capture and upload a heap snapshot, which would directly help the team investigate your report.
  3. aaabyf commented on Jun 27, 2026

    @aaabyf
    Author

    I've captured heap snapshots following the Memory Megathread instructions (manual Ctrl+P flow).

    Files generated:

    • server.heapsnapshot (100 MB)
    • tui.heapsnapshot (58 MB)

    Heap analysis summary:

    Metric server tui
    Total nodes 1,670,688 916,586
    Self size 154.7 MB 99.4 MB
    Objects 924k 342k
    Closures 388k 246k
    Strings 90k 106k

    Notable findings:

    • 2.6M total objects across both processes — each GC mark-sweep cycle must traverse this entire graph
    • 634k closures — closures retain enclosing scope references, a common leak source
    • 33.5 MB ArrayBuffer — single large buffer potentially leaked
    • Duplicate system prompts — same prompt strings stored multiple times (15-32 KB each)
    • Multiple 500KB+ WeakMaps — large key-value stores not being released

    This directly explains the CPU spikes: the massive object graph (2.6M nodes) means V8's concurrent GC threads are constantly working even when idle, and each GC pause grows longer as the heap accumulates.

    Will upload the snapshots to the Dropbox link shortly (network restrictions on my end). Let me know if there's an alternative upload method available.

  4. github-actions commented on Aug 27, 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