Token loop/degeneration: model outputs infinite repeated tokens (spaces, 'and', closing parens)

Resolved 💬 3 comments Opened Apr 7, 2026 by yangfei222666-9 Closed Apr 11, 2026

Bug Description

During a long coding session using Claude Code (VS Code extension), the model repeatedly enters a degeneration loop where it outputs thousands of identical tokens instead of meaningful content.

Symptoms

  • Output degenerates into infinite repeated characters: spaces/newlines, and, closing parentheses ), or other single tokens
  • Happens mid-response, sometimes after a valid tool call result is returned
  • Requires manual interruption (Escape) to stop
  • Occurred 5+ times in a single session
  • The model appears unaware it is looping — no self-correction

Environment

  • Claude Code VS Code extension
  • Model: claude-opus-4-6
  • Platform: Windows 11 Pro 10.0.26100
  • Session: long conversation with multiple tool calls (file reads, edits, bash commands)

Reproduction

  1. Start a long coding session with many tool calls (file reads, edits, grep, bash)
  2. Continue working for 20+ exchanges
  3. At some point, the model response degenerates into repeated tokens

Observed Patterns

  • More likely to occur as the conversation gets longer (context pressure?)
  • Sometimes triggered right after reading a tool result
  • The repeated token varies: sometimes whitespace, sometimes words like and, sometimes )
  • Exit code and tool results before the degeneration are normal — the bug is purely in text generation

Impact

  • Wastes significant tokens/cost (thousands of repeated tokens before user can interrupt)
  • Breaks flow — user must interrupt and retry
  • In severe cases, happens multiple times in quick succession making the session unusable

Workaround

  • Interrupt immediately when loop starts
  • Start a new session if it happens repeatedly (suggests context-length correlation)

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗