Critical: Claude Code freezes with high CPU usage when typing long responses in interactive prompts (Intl.Segmenter infinite loop)
Claude Code Freeze: CPU Spin in Intl.Segmenter When Typing Long Custom Responses in Interactive Prompts
Summary
Claude Code freezes and consumes 15-35% CPU when typing long custom responses in interactive question prompts (the "Other" option in AskUserQuestion). The process enters an infinite/extremely long loop in V8's JSSegmentIterator::Next, part of the Intl.Segmenter API used for text segmentation.
Frequency
- 3 times in the last week
- Reproducible when typing lengthy custom responses in interactive prompts
- Affects normal usage significantly
Environment
- OS: Ubuntu 24.04.2 LTS (Noble Numbat)
- Kernel: Linux 6.8.0-79-generic
- Node.js: v22.19.0
- Architecture: x86_64
- Locale: en_US.UTF-8
Reproduction Steps
- Start Claude Code in a terminal
- Trigger an interactive question with multiple choice options (e.g., project configuration)
- Begin typing a long custom response (selecting "Other" option)
- Type approximately 200-500+ characters
- Mid-typing, Claude freezes and becomes unresponsive
- Terminal shows no output, cannot type
- Process consumes 15-35% CPU continuously
Expected Behavior
- Claude should process user input efficiently without freezing
- Text input should not trigger expensive segmentation operations in real-time
Actual Behavior
- Process freezes completely
- Main thread enters CPU spin loop
- Terminal becomes unresponsive
- Only recoverable by killing the process (SIGKILL)
Technical Analysis
Process State
Two frozen instances were analyzed:
- PID 3841575: Frozen for 9 minutes, 19.5% CPU
- PID 3810348: Frozen for 44+ minutes, 32% CPU
Both showed identical symptoms:
- State:
R (running)- not blocked on I/O - Main thread spinning in CPU loop
- Worker threads idle
- Low context switch count (indicating tight loop)
Root Cause: Intl.Segmenter Infinite Loop
Performance profiling (via perf record) revealed:
Process 3810348 (longer-running freeze):
34.21% CPU in v8::internal::Builtin_SegmentIteratorPrototypeNext
33.72% CPU in v8::internal::JSSegmentIterator::Next
Process 3841575 (recent freeze):
6.36% CPU in v8::internal::JsonStringify
Main activity in timer callbacks and JSON serialization
Stack Trace (from gcore)
Process 3810348:
0x00000000016bf07a in v8::internal::LookupIterator::WriteDataValue(...)
Process 3841575:
0x000078897d929f10 in epoll_pwait()
System Call Analysis (via strace)
% time syscall
82.62% futex (545 calls, 46 errors)
13.24% wait4 (4 calls)
1.17% epoll_pwait (1222 calls, 1 error)
The process is not blocked on I/O - it's spinning in user-space JavaScript code.
Root Cause Hypothesis
Claude Code appears to be using Intl.Segmenter for real-time text processing as users type custom responses in interactive prompts. The segmenter is designed to break text into graphemes, words, or sentences.
Problem: When processing long text input character-by-character or with certain Unicode sequences, the segmentation iterator enters an extremely long or infinite loop, causing the main thread to freeze.
Likely code pattern causing the issue:
// Hypothetical problematic code
const segmenter = new Intl.Segmenter(locale, { granularity: 'grapheme' });
const segments = segmenter.segment(longUserInput);
for (const segment of segments) { // <-- Gets stuck here
// Process each segment
}
Impact
- Severity: High - Renders Claude Code unusable, requires process kill
- Frequency: 3 occurrences in 1 week for this user
- Workaround: None - must kill process and restart
Diagnostic Data Available
Core dumps and performance profiles have been generated:
/tmp/core.3841575(32GB sparse file)/tmp/core.3810348(32GB sparse file)/tmp/perf-3841575.data(1.362 MB, 4838 samples)/tmp/perf-3810348.data(4.065 MB, 12470 samples)
These files can be provided if needed for deeper analysis.
Suggested Fixes
- Remove real-time segmentation: Don't process user input with Segmenter as they type
- Add timeout/limits: If Segmenter is necessary, add iteration limits or timeouts
- Debounce processing: Only run text processing after user pauses typing
- Use simpler text splitting: For basic use cases, use
String.split()instead of Segmenter - Background processing: Move text segmentation to worker threads
Additional Context
User's exact activity when freeze occurred:
I was typing a long custom response to an interactive question about project configuration. The prompt was asking about how to identify project roots, and I was explaining a detailed multi-condition logic. Mid-sentence (around "We could use a single s..."), it froze completely.
The text being typed was approximately 450 characters, discussing project root detection logic with multiple file markers (.git, composer.json, package.json, etc.).
Questions for Maintainers
- Is
Intl.Segmenterintentionally used for processing user input in interactive prompts? - If yes, what is the expected use case - grapheme counting, word breaking, sentence detection?
- Are there known issues with Segmenter performance on long strings in Node.js v22?
- Would you like the core dumps and perf data for deeper analysis?
---
Reporter: Via automated bug report from frozen Claude Code instance
Date: 2025-10-30
Node Version: v22.19.0
Claude Code Invocation: Standard CLI execution
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗