guardrail by neatproxy join discord
tool: Claude Code env: C++ CMake Project

How to Stop Claude Code Loops in C++ CMake Project: Fix 'Recursive compilation loops on cyclic header dependencies'

avg. estimated token loss per run: $$5–$80 per incident (depending on project size, model, and retry depth) usd

what is happening

Claude Code can become stuck repeatedly running `cmake --build` when cyclic header dependencies prevent successful compilation. Instead of identifying the underlying include cycle, the agent repeatedly recompiles the same targets and reanalyzes compiler output, consuming tokens without making progress. Breaking the header dependency cycle, reducing the compilation scope, and limiting automatic retries prevents recursive compilation loops.

manual fix

Inspect the first compiler error, identify the cyclic header inclusion, and resolve it using forward declarations, dependency inversion, or header refactoring before rebuilding. If Claude Code repeatedly executes the same `cmake --build` command without reaching a different compiler state, stop the session, reset context, and restart with a narrowly scoped compilation task.

check configuration: .claudeignore & .claude/settings.local.json

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 cmake --max-budget 12.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