loop-breaker

Cap recursion depth in Cloudflare Workers with middleware and headers.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/littlebearapps/cloudflare-engineer --skill loop-breaker
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: loop-breaker
Source: https://github.com/littlebearapps/cloudflare-engineer/tree/main/skills/loop-breaker
Command: npx skills add https://github.com/littlebearapps/cloudflare-engineer --skill loop-breaker

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Protect Cloudflare Workers from self-recursion and runaway loops that can balloon costs and cause denial-of-wallet scenarios.

Core Features & Use Cases

  • Recursion Depth Middleware to cap nested fetches and worker calls.
  • createRecursionHeaders to propagate loop depth across outbound requests.
  • Durable Object Loop Protection to avoid long-lived timers and unnecessary billing.
  • Queue- and service-bindings aware patterns for safe inter-workflow communications.

Quick Start

Install the skill and apply the recursionGuard middleware to your app, then use createRecursionHeaders for outbound calls.

Frequently Asked Questions about loop-breaker

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stop Cloudflare Worker recursion and runaway loops?

To stop Cloudflare Worker recursion, apply a max-depth recursion guard middleware to your app and propagate loop depth headers across outgoing requests to safely halt looping behavior.

What is a recursion depth guard and how does it work for outgoing requests?

A recursion depth guard is a middleware that caps nested fetches and worker calls. It works by propagating loop depth headers via outgoing requests to track and limit recursive invocations.

How do I prevent loops in Cloudflare Durable Objects and queue handlers?

To prevent loops in Durable Objects and queue handlers, implement queue- and service-bindings aware patterns that apply loop protection, avoiding long-lived timers and unnecessary billing.

Can I use loop protection middleware for event-driven Cloudflare Worker webhooks?

Yes, you can use loop protection middleware for event-driven Cloudflare Worker webhooks. It applies during inter-worker calls and event handlers where recursive invocations can occur.

Why does my Cloudflare Worker self-recursion cause denial-of-wallet scenarios?

Cloudflare Worker self-recursion causes denial-of-wallet scenarios because runaway loops balloon costs through uncontrolled nested fetches and repeated invocations across inter-worker calls.

What's the best way to limit nested fetches in inter-worker calls?

The best way to limit nested fetches in inter-worker calls is applying a recursion depth middleware that caps nested worker calls and propagates depth headers across outbound requests.