Agent repeatedly calls the same tool in an infinite loop during exploratory research tasks

Resolved 💬 3 comments Opened May 15, 2026 by bebeStudy Closed May 18, 2026

Problem

When performing open-ended research or codebase exploration tasks, Claude Code repeatedly calls the same tool (e.g., Bash with identical commands) dozens of times without terminating. This has been observed consistently across multiple sessions.

Steps to Reproduce

  1. Ask Claude Code an open-ended analysis question that requires scanning multiple files (e.g., "How should this project integrate with an external CLI tool?")
  2. Claude begins scanning files across modules
  3. After collecting sufficient information, instead of stopping and synthesizing, Claude continues scanning additional modules
  4. Eventually gets stuck calling the exact same command repeatedly (observed: same grep command called 30+ times in a row with identical arguments and identical output)
  5. Loop only terminates when the user manually interrupts

Expected Behavior

Claude should recognize when it has collected sufficient information to answer the question an issuing tool calls.

Actual Behavior

Claude issues the same Bash tool call repeatedly (30-50+ times) with identical arguments, receiving identical output each time, without terminating.

Environment

  • Claude Code version: 2.1.142
  • OS: macOS Darwin 25.4.0
  • Shell: zsh

Impact

  • Tasks that should take 2-3 minutes run for 1-2 hours
  • Wastes significant context window and compute
  • Requires manual user interruption every time

Notes

This appears to be a model-level termination issue in agentic loops — the model lacks a reliable stopping condition when doing exploratory work. A potential mitigation could be detecting repeated identical tool calls and auto-terminating or warning.

View original on GitHub ↗

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