claude-code - 💡(How to fix) Fix Agent repeatedly calls the same tool in an infinite loop during exploratory research tasks

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fix / Workaround

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.

RAW_BUFFERClick to expand / collapse

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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Agent repeatedly calls the same tool in an infinite loop during exploratory research tasks