Ghostty 1.3 Fixes Massive Memory Leak Caused by "Claude Code"


Ghostty Developer Fixes "Absurd" 37GB Memory Leak Triggered by AI Tools
Mitchell Hashimoto, creator of the Ghostty terminal emulator, has announced a definitive fix for the most significant memory leak in the project’s history. The bug, which remained dormant since version 1.0, was recently brought to light by the intensive output patterns of AI command-line tools like Claude Code.
In some extreme cases, users reported Ghostty consuming up to 37 GB of RAM after several days of uptime. The fix has been merged into the nightly builds and is scheduled for the stable 1.3 release in March 2026.
The Anatomy of the Leak: Metadata Desync
Ghostty manages terminal history using a "PageList," a doubly-linked list of memory pages allocated via mmap. To maintain high performance, Ghostty uses two types of allocations:
-
Standard Pages: Fixed-size blocks managed by a memory pool for fast reuse.
-
Non-Standard Pages: Larger, direct
mmapallocations used for lines with heavy emoji usage, complex styles, or deep hyperlinks.
The leak occurred during a "scrollback optimization" where the terminal reuses the oldest page in history as the newest page to avoid new allocations.
The "Claude Code" Catalyst
While the bug existed for years, it was rarely triggered because non-standard pages are typically uncommon. However, the rise of Claude Code—Anthropic’s CLI tool for AI-driven coding—created a "perfect storm."
Claude Code produces high volumes of multi-codepoint graphemes and rapid scrollback updates. This forced Ghostty to allocate non-standard pages at an unprecedented rate, which were then incorrectly recycled and leaked.
| Allocation Type | Management Method | Cleanup Logic |
|---|---|---|
| Standard Page | Memory Pool | Returned to pool (No syscall) |
| Non-Standard | Direct mmap | Must call munmap |
| Leaked Page | Metadata Desync | Ignored by munmap |
Visualizing the Impact: Memory Consumption
Before the fix, the memory footprint grew linearly with the number of non-standard pages generated by high-intensity CLI tools.
Diagnostic Breakthrough with VM Tags
To confirm the fix, Hashimoto implemented Virtual Memory (VM) Tags on macOS. This allows the Mach kernel to label specific memory allocations, making them visible in system diagnostic tools. By tagging the PageList allocations, the developers could distinguish Ghostty's internal terminal memory from general application overhead, proving that the leaked memory was indeed tied to the scrollback buffer.
The AI Stress-Test for Legacy Software
The Ghostty memory leak is a prime example of how the next generation of AI tools is stressing existing software infrastructure. Tools like Claude Code do not just change how we code; they change the workload of the tools we use to code.
By pushing terminal emulators to handle complex, high-bandwidth data streams that were previously the exception rather than the rule, AI is inadvertently acting as a massive, real-world fuzzing suite for edge cases. This fix ensures Ghostty remains a viable high-performance option as "agentic" workflows become the industry standard.
References

Comments (0)
Please login to comment
Sign in to share your thoughts and connect with the community
Loading...