guardrail by neatproxy join discord
tool: Claude Code env: Python FastAPI

How to Stop Claude Code Loops in Python FastAPI: Fix 'Recursive test-fix loops on async dependencies'

avg. estimated token loss per run: $$5–$60 per incident usd

what is happening

Claude Code can enter recursive test-fix loops in FastAPI projects when failing async fixtures or dependency injection errors prevent pytest from reaching a stable passing state. Instead of identifying the underlying fixture or event loop issue, the agent repeatedly edits code and reruns the same test suite, consuming tokens without making progress. Restricting test scope, fixing the root async dependency, and limiting automatic retries breaks the loop.

manual fix

Run only the failing test or module, verify async fixtures and event loop configuration manually, and resolve the underlying dependency or fixture error before rerunning the full suite. If Claude Code repeatedly executes the same pytest command without producing a different outcome, stop the session, reset context, and restart with a narrowly scoped debugging task.

check configuration: .claudeignore & CLAUDE.md

capping calls & killing loops automatically

if you want to prevent runaway background processes from burning through API credits, you can set budget caps and loop limits directly in terminal using guardrail.

npx @neatproxy/guardrail --preset claude-code --target fastapi --max-budget 8.00 --loop-cap 3

running into a different edge case? join us at neat to share logs or ask the team.

→ join the neat discord community