Unclear It is unclear whether the default cleanup schedule applies when the variable is not set.
mcp serve runs Claude Code as an MCP server, so other programs can use its tools. A new environment variable, CLAUDE_CODE_MCP_SERVE_GARBAGE_COLLECTIONS, controls garbage collection there, which is the step that frees memory the program no longer uses. It takes comma-separated parts:
first:listen,rest,skipornever, for the first collectionlater:youngorfull, for collections after thatrest_delay_ms: a delay in millisecondsmin_growth_mib: a minimum memory growth in MiBbetween_growth_mib: memory growth in MiB between collections
The defaults are first listen, later full, 1500 ms, 16 MiB and 8 MiB, and they apply only when a built-in check that is on by default passes. If a collection blocks for more than 250 ms, Claude Code stops running further ones. This needs Bun's JavaScriptCore support.
People running mcp serve for long stretches get a way to manage its memory use, with a safety stop if cleanup starts slowing the server down.
It is unclear whether the default cleanup schedule applies when the variable is not set.