GrepBoard/Manuals
605 manuals ·

Gemini CLI: "JavaScript heap out of memory" crash

·Tested on Node.js 22.23.4 (Docker) · Gemini CLI official docs and repo · 2026-10·Test scope ↓·6 steps

Gemini CLI dies with JavaScript heap out of memory after long sessions as history piles up in the heap. Delay it with /compress, /clear and .geminiignore.

text
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

The heap of the Node.js process running Gemini CLI hit its limit and V8 killed the process. In an issue filed on 2026-10-19 (0.64.0, Windows 11), one session in a repository full of large test reports and JSON ran for about 9.3 hours before the heap stopped at about 8.3 GB. The issue is still open and no fixed version exists. What you can do today is slow the build-up in each session.

[1] Confirm it is this crash. The CLI drops back to the prompt, and just above you see <--- Last few GCs ---> and Mark-Compact ... allocation failure lines. Plain Node.js shows the same shape: cap the heap at 96 MB and keep growing an array.

console
$ NODE_OPTIONS=--max-old-space-size=96 node -e "const a=[];for(;;)a.push(new Array(1e5).fill(1))"
output
<--- Last few GCs --->FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memoryAborted (core dumped)exit=134

The issue author reports that the in-memory session history could not be recovered after the crash. For long tasks, having the agent write intermediate results to files is the most reliable safeguard.

[2] Shrink the session regularly. Per the official command docs, /compress replaces the entire chat context with a summary, and /clear clears the conversation context and starts a new session. The issue's temporary procedure was also to /clear or start a new session every few hours. A comment on the issue points out that automatic compression is driven by token counts, while binary and base64 data cost few tokens but a lot of heap. So do not rely on automatic compression alone.

[3] Exclude large output folders with .geminiignore. Create it in the project root with .gitignore syntax. The list from the issue author:

text
allure-results/playwright-report/test-results/dist/*.zip

The official docs say tools that support it honor this file (for example when you add files with @), and that you must restart the session for changes to apply. Shell command output is not affected by it, so trim large output with | head -n 200 or have the command write to a file.

[4] Check the heap limit. The startup code in the Gemini CLI repository (packages/cli/src/gemini.tsx, as of 2026-10) sets a target heap of 50% of total RAM when advanced.autoConfigureMemory (default true) is on, and relaunches with --max-old-space-size only if the current limit is smaller. On a 16 GB machine that is about 8 GB, close to the issue's 8,292 MB (the issue does not state the machine's RAM, and the author calls that value "the 64-bit default"). Check the limit Node gets in your shell, in MB, with no prefix:

console
$ node -e "console.log(require('v8').getHeapStatistics().heap_size_limit/1048576)"

That is the value for plain Node in your shell. With the automatic setting on, the CLI runs with the larger of this value and 50% of RAM. Passing a value through NODE_OPTIONS changes the limit to that value. The demo below passes 96 MB, so it prints about 99 regardless of your machine:

console
$ NODE_OPTIONS=--max-old-space-size=96 node -e "console.log(require(\"v8\").getHeapStatistics().heap_size_limit/1048576)"
output
99

Going by that code, a NODE_OPTIONS value larger than half your RAM means no relaunch, so your value stays. The issue author also listed $env:NODE_OPTIONS = "--max-old-space-size=12288" as a workaround. As a comment on the same issue says, though, a higher limit only moves the crash later, and a limit above your RAM pushes the machine into swap. Raise it only within real RAM.

[5] Watch memory as you work. Setting ui.showMemoryUsage to true shows memory usage in the UI. When it passes a few GB, treat it as the signal to shrink the session as in step 2.

[6] Follow the issue. As of 2026-10, #29830 is open and labeled effort/large, and the recent nightly and preview release notes have no entry fixing this leak. If you hit the same thing, add your version, OS and session length to that issue.

If you are stuck at install or login, see Fix Gemini CLI install and login errors. For where settings are read from, see Where Gemini CLI reads settings.json and which file wins.

#gemini-cli#nodejs#memory#troubleshooting