CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096 causes infinite hang during context compaction
Resolved 💬 3 comments Opened Apr 3, 2026 by tksehd2 Closed Apr 6, 2026
Description
When CLAUDE_CODE_MAX_OUTPUT_TOKENS is set to 4096, the context compaction process hangs indefinitely with no output. The session becomes completely unresponsive and must be abandoned — there is no way to recover.
Environment
- OS: Windows 11 Pro for Workstations
- Environment variable:
CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096
Steps to Reproduce
- Set
CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096in your environment - Start a Claude Code session
- Continue working until the context window fills up and compaction is triggered
- Observe: the compaction process starts but never completes — infinite loading with no response
Expected Behavior
- Compaction should complete successfully regardless of the max output token setting, or
- If 4096 tokens is insufficient for compaction, a clear error message should be shown instead of hanging silently
Actual Behavior
- Compaction enters an infinite loading state
- No error message, no timeout, no output
- The session is permanently stuck and must be killed
- All unsaved conversation context is lost
Additional Context
- Users set low
MAX_OUTPUT_TOKENSto get more concise responses and save costs. This is a valid use case that should not break core functionality. - The hang appears to be because the compaction summary itself requires more than 4096 output tokens to generate, but instead of failing gracefully, it silently hangs forever.
- This is particularly frustrating because it happens after a long productive session — losing all that context with no warning.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗