You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Massive memory use on opening opencode when there is a very large file #2585
Before trying out opencode, I had been experimenting which chunkhound, that indexes your source folder to allow searching later. It stores its database file(s) in the .chunkhound folder, and in my project that folder was around 27GB in size.
It seems like opencode was trying to load the files in that folder, because when I ran opencode the memory usage would shoot up, and opencode was using 29GB of RAM, and my computer was getting very slow.
Deleting that folder solved the problem. Unfortunately I didn't check what the sizes and filetypes of files in that folder were before I deleted it.
@rekram1-node, aha, very interesting thing. If my working folder has a backup subfolder with large .tar.gz files, the opencode executable starts to grow in size (virtual memory) and gets killed by the OOM Killer.
Is there anything special in backup or tar.gz handling?
That happens on application startup. I did not even enter anything.
I've identified the root cause of the high virtual memory consumption when large .tar.gz files are present in your working directory. Here's what happens during opencode startup:
Function: SystemPrompt.environment() calls Ripgrep.tree() during initialization
Process: This scans ALL files in your project directory to build a project tree structure that gets included in the system prompt
The Problem Chain:
File Scanning: Ripgrep.tree() → Ripgrep.files() → ripgrep binary with --files flag
No Archive Filtering: The default ignore patterns in FileIgnore don't include common archive extensions like *.tar.gz, *.zip, *.tar, etc.
Memory Allocation: When ripgrep encounters large files (even if it's just listing them), it can cause memory allocation issues, especially with compressed archives
Startup Execution: This happens before any conversation starts, during the system prompt preparation
Evidence from Code:
• src/session/system.ts:47-50: Calls Ripgrep.tree() with limit of 200 files during environment setup
• src/file/ignore.ts: Missing patterns for archive files (*.tar.gz, *.zip, *.tar, *.7z, etc.)
• src/file/ripgrep.ts:206-220: The files() function uses ripgrep's --files flag which scans the entire directory
Verification Checklist: ✅ Verified: File scanning occurs at startup via SystemPrompt.environment() ✅ Verified: No archive file patterns in default ignore list ✅ Verified: Ripgrep.files() scans
entire directory structure ❓ Inferred: Large archive files cause memory allocation during scanning
Next Steps to Confirm: You could verify this by temporarily moving your .tar.gz files out of the working directory and checking if the memory usage drops during opencode startup.
The fix would involve adding archive file patterns to the default ignore list in src/file/ignore.ts.
Before trying out opencode, I had been experimenting which chunkhound, that indexes your source folder to allow searching later. It stores its database file(s) in the .chunkhound folder, and in my project that folder was around 27GB in size.
It seems like opencode was trying to load the files in that folder, because when I ran opencode the memory usage would shoot up, and opencode was using 29GB of RAM, and my computer was getting very slow.
Deleting that folder solved the problem. Unfortunately I didn't check what the sizes and filetypes of files in that folder were before I deleted it.
Its reading my .venv folder as well, or there is something stored in session histories. I've been sitting at 5GB, but have been to 20GB+. Could we get a panel that displays a breakdown of memory usage, or some instructions on how to view what consumes it?
Activity
github-actions commentedon Sep 13, 2025
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
rekram1-node commentedon Sep 13, 2025
good to know thx for raising
zelenkovsky commentedon Sep 22, 2025
In my case, it's 72GB of memory that got committed right after start (for other repository it's 93GB):
rekram1-node commentedon Sep 22, 2025
@zelenkovsky can you tell me more about where you are running opencode is this a massive project or something?
zelenkovsky commentedon Sep 24, 2025
@rekram1-node, aha, very interesting thing. If my working folder has a
backupsubfolder with large .tar.gz files, theopencodeexecutable starts to grow in size (virtual memory) and gets killed by the OOM Killer.Is there anything special in
backuportar.gzhandling?That happens on application startup. I did not even enter anything.
zelenkovsky commentedon Sep 24, 2025
Actually,
backuphas nothing to do with it; it's largetar.gzfiles located anywhere in the project folder.zelenkovsky commentedon Sep 24, 2025
Analysis Summary
I've identified the root cause of the high virtual memory consumption when large .tar.gz files are present in your working directory. Here's what happens during opencode startup:
Primary Issue: File Tree Generation at Startup
The Problem Chain:
Evidence from Code:
• src/session/system.ts:47-50: Calls Ripgrep.tree() with limit of 200 files during environment setup
• src/file/ignore.ts: Missing patterns for archive files (*.tar.gz, *.zip, *.tar, *.7z, etc.)
• src/file/ripgrep.ts:206-220: The files() function uses ripgrep's --files flag which scans the entire directory
Verification Checklist: ✅ Verified: File scanning occurs at startup via SystemPrompt.environment() ✅ Verified: No archive file patterns in default ignore list ✅ Verified: Ripgrep.files() scans
entire directory structure ❓ Inferred: Large archive files cause memory allocation during scanning
Next Steps to Confirm: You could verify this by temporarily moving your .tar.gz files out of the working directory and checking if the memory usage drops during opencode startup.
The fix would involve adding archive file patterns to the default ignore list in src/file/ignore.ts.
ofriw commentedon Sep 28, 2025
Author of ChunkHound here. As a workaround, you can place the db file outside of your code's dir using the
--dbflag. See https://chunkhound.github.io/configuration/#database-optionsIlyaMaksheev commentedon Oct 2, 2025
I also experience same issue with
.parquetfiles.scarf005 commentedon Dec 25, 2025
hi @rekram1-node, could #2761 be taken a look? also getting 17GiB ram usage on repository with lots of image files
SPOOKEXE commentedon Jan 5, 2026
Its reading my .venv folder as well, or there is something stored in session histories. I've been sitting at 5GB, but have been to 20GB+. Could we get a panel that displays a breakdown of memory usage, or some instructions on how to view what consumes it?
aniel300 commentedon Jan 22, 2026
same issue
github-actions commentedon Mar 28, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.