Agent repeatedly calls the same tool in an infinite loop during exploratory research tasks
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
- 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?")
- Claude begins scanning files across modules
- After collecting sufficient information, instead of stopping and synthesizing, Claude continues scanning additional modules
- Eventually gets stuck calling the exact same command repeatedly (observed: same
grepcommand called 30+ times in a row with identical arguments and identical output) - 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗