Repository navigation
Critical: Unbounded heap growth (37+ GB RSS) + orphaned processes on Linux #15348
Description
Summary
opencode exhibits unbounded heap memory growth on Linux, reaching 37+ GB RSS within ~30 minutes of normal usage. Additionally, orphaned opencode processes (TTY "?") remain running and continue consuming RAM/CPU even after terminal sessions end.
Critical finding: Private_Dirty memory accounts for 99.9% of RSS - this is heap memory allocated by opencode itself, not LSP children.
Environment
- OS: Linux (KDE/Wayland), x86_64
- opencode: 1.1.53 (installed via brew)
- Repo: Medium/large monorepo with JS/TS + Python + Rust build artifacts
Evidence: Memory Analysis
Process 1: Active terminal session (most critical)
PID: 390314
PPID: 388470
TTY: pts/8 (active terminal)
STAT: Sl+
%CPU: 41-42% (continuous)
%MEM: 38-54% of 64GB system
RSS: 37.9 GB (growing)
VSZ: 164.7 GB
Runtime: 26+ minutes
smaps_rollup (the smoking gun):
Rss: 37965896 kB (~37.9 GB total)
Pss_Anon: 37925564 kB (~37.9 GB anonymous memory)
Private_Dirty: 37827316 kB (~37.8 GB dirty heap)
Pss_File: 10269 kB (~10 MB file-mapped)
→ 99.9% of memory is Private_Dirty heap, not file cache or shared memory.
Process 2: Orphaned process (lifecycle bug)
PID: 316456
PPID: 1541 (systemd/init)
TTY: ? ← No controlling terminal!
STAT: Sl
%CPU: 35%
%MEM: 13.2%
RSS: 13 GB
Runtime: 59+ minutes
smaps_rollup:
Rss: 13071736 kB (~13 GB)
Private_Dirty: 13039964 kB (~13 GB heap)
This process has no TTY and continues running independently.
File descriptor counts
- PID 390314: 118 open files
- PID 316456: 78 open files
→ Not a file descriptor leak.
Process tree (PID 390314)
opencode,390314
|-node,422681 .../biome lsp-proxy --stdio
| |-biome,422690 lsp-proxy --stdio (16 threads)
|-opencode,396294 run .../pyright-langserver.js --stdio
→ Memory is in parent opencode process, not LSP children.
Reproduction Steps
- Start opencode in repository (my-project)
- Work normally for 10-30 minutes (navigation, search, agent runs)
- Observe
ps aux --sort=-rss: opencode processes continuously grow RSS - Exit terminal or start new sessions - some processes remain (TTY "?")
- Eventually system hits memory pressure, OOM killer terminates other apps
Repository Characteristics (possible triggers)
| Path | Size | Notes |
|---|---|---|
backend.log |
126 MB | Large log file |
backend_restart.log |
23 MB | Large log file |
orchestra/apps/desktop/src-tauri/target/debug/build/* |
15-21 MB each | Rust build artifacts |
Multiple node_modules/ |
Unknown | JS dependencies |
Python .venv/ |
Unknown | Python environment |
Hypothesis
- Indexer/cache unbounded growth: opencode may be indexing files without respecting
.gitignore/.ignoreor without memory limits - Heap leak: Continuous allocation without deallocation (possibly in file watcher, cache, or search index)
- Process lifecycle bug: Detached processes (TTY "?") not receiving shutdown signals
Questions for Maintainers
- Does opencode have a memory cap for indexes/cache?
- Are
.gitignoreand.ignorefiles respected during indexing? - Is there a file size limit for indexing?
- What is the expected process lifecycle - should detached processes (TTY "?") auto-terminate?
- Where in the codebase should we look for unbounded cache/index growth?
Request
This makes opencode unusable for production work on Linux with medium+ repositories. Please advise:
- Immediate workaround (config options to limit memory?)
- Where in the codebase to investigate (indexer? cache? watcher?)
- Whether a PR for memory bounds would be accepted
I'm happy to test patches, provide additional diagnostics, or help reproduce.
Diagnostics collected: 2026-02-27 10:56 CET
Evidence commands used:
ps aux --sort=-rss | head -20
cat /proc/$PID/smaps_rollup
pstree -ap $PID
lsof -p $PID | wc -l
Activity
github-actions commentedon Feb 27, 2026
This issue might be a duplicate of existing issues. Please check:
If your issue is distinct from the above, please clarify what differentiates it (e.g., a specific new reproduction path or additional data not covered by those reports).
OmerFarukOruc commentedon Feb 27, 2026
Workaround:
oc-cleanupscriptI wrote a small script to manage this issue until it's fixed upstream. It finds and kills orphaned opencode processes (those with no TTY that survive terminal close).
Quick install
Usage
What it looks like
Optional auto-cleanup via cron
Full gist with README: https://gist.github.com/OmerFarukOruc/d1bf2bb1f6f4f01c3a0e63288ada7c94
WietRob commentedon Mar 2, 2026
Closing as duplicate. Consolidating evidence in #14504 which has the root cause analysis and proposed fix.
fix(opencode): resolve heap unlimited + orphan processes on Linux