I got tired of Claude Code retrying a broken command 10 times in a row, so I built a fix for it

I got tired of Claude Code retrying a broken command 10 times in a row, so I built a fix for it

https://preview.redd.it/5w0wme402lbh1.png?width=1536&format=png&auto=webp&s=1bbf89e33d14d19a4c2ebddf2a2b1fac5b2195a7

I kept running into the same two problems with Claude Code on longer sessions: it'd get stuck retrying a failing command in a near-identical loop, and tool output (file listings, logs, diffs) would pile up in context even after it stopped being useful. Both quietly ran up the token bill.

So I built DedrooM a small middleware that sits in front of Claude Code (and a few other agents: Codex, Aider, Cursor, Cline, OpenCode) and does two things:

  • Stops loops before they compound. Tracks repeated tool calls with an adaptive window, tightens up automatically once error rate climbs, and blocks a call outright if it's clearly stuck.
  • Compresses redundant tool output before it hits the model — truncates repetitive stuff like long file listings, dedupes logs, keeps the parts that actually matter.

It's one command to try:

bash

pip install dedroom
dedroom wrap claude

dedroom unwrap claude puts things back to normal. It's Apache 2.0, source is here: https://github.com/Devaretanmay/dedroom

Being upfront about the numbers: the compression/savings figures in the README are from a handful of internal test scenarios, not a big benchmark suite real savings depend a lot on your workload (loop-prone sessions and repetitive tool output benefit a lot more than a clean session does). I'd rather you try it and tell me it doesn't do much for your setup than oversell it here.

Would genuinely like feedback from people running long Claude Code sessions especially if it either catches something useful or gets in your way. Happy to answer questions about how the loop detection or compression actually works under the hood.

reddit.com
u/Commercial2Toe — 20 hours ago

Built a no_std runtime safety library for AI agents looking for feedback on the architecture

I've been experimenting with autonomous AI agents over the last few months and kept running into the same problem.

Agents would repeatedly call the same tool, retry failed operations indefinitely, or get stuck in execution loops.

Instead of trying to solve it through prompt engineering, I built a small Rust library that sits between the agent and its tools and verifies every tool call before execution.

Current features:

• History-based trajectory tracking

• Loop detection

• JSON Schema validation

• Regex/exact policy rules

• Per-tool trajectory gates

• C ABI

• no_std core

• Python adapters for LangGraph, CrewAI, AutoGen and LangChain

Current benchmark:

~17 μs average verification

~375 ns fast reject for repeated loops

I'm mainly looking for feedback on:

  1. API design
  2. False positives
  3. Whether this belongs as middleware instead of framework-specific code

Repository: https://github.com/Devaretanmay/microloop

reddit.com
u/Commercial2Toe — 6 days ago
▲ 5 r/BuildWithClaude+3 crossposts

I analyzed why LangGraph agents burn $50 on infinite loops (and why recursion_limit is a blunt instrument)

>We've all been there: You leave your LangGraph agent running, it hits a 403 Forbidden or a bad SQL query, and instead of failing gracefully, it asks the LLM for help. It gets stuck in a ReAct loop, burning through your API credits until the native recursion_limit finally kills it.
The worst part? The native recursion_limit is a blunt instrument. It throws a GraphRecursionError, crashes the run, and wipes your checkpointed state. You lose whatever partial data the agent did gather, and your frontend user just gets a 500 error.
I spent the last week digging into why agents do this, especially with open-weight models (Qwen/Llama) that lack native self-correction. I realized that just throwing a raw RuntimeError or a "BLOCKED" string at an agent just confuses it, and it loops again.
I ended up building an open-source pre-model intervention hook to solve this, and I wanted to share the architecture for anyone building headless agent backends.
How it works under the hood:
Instead of wrapping the whole graph, it uses LangGraph's native pre_model_hook and ToolNode APIs.It turns a fatal crash into bounded degradation. The agent returns a partial summary instead of an error, and your state is preserved.
It runs 100% locally, uses tiktoken shingling for zero-dep semantic loop detection, and adds <20µs of overhead.
Repo: https://github.com/Devaretanmay/TokenCircut
PyPI: pip install "tokencircuit[langgraph]"
Curious what the weirdest infinite loop you've seen your agents get stuck in is? For me, it was a Databricks agent that kept retrying a REQUIRES_SINGLE_PART_NAMESPACE SQL error 20 times in a row.

u/Commercial2Toe — 20 hours ago