loop-detector

loop-detector is a skill for Claude Code from ihabkhaled/AI-Psychiatry. It costs 35 tokens per session (230 once invoked), scanned A, original, MIT.

A check for repeated work that detects when an agent keeps running similar commands, searches, edits, reviews, or plans without gaining new evidence.

In plain words
What is it for?
Grouping equivalent attempts, spotting retry or edit-revert patterns, and choosing a different recovery action.
Why use it?
It helps identify stalled work, including cycles where activity continues but requirements and tests do not improve.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the ai-psychiatry plugin — 55 skills shipped together

Good fit Grouping equivalent attempts, spotting retry or edit-revert patterns, and choosing a different recovery action.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ihabkhaled/ai-psychiatry/loop-detector
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add ihabkhaled/AI-Psychiatry --skill loop-detector
Clone the repo
git clone --depth 1 https://github.com/ihabkhaled/AI-Psychiatry

Made for: Claude Code.

Or install ai-psychiatry, the plugin that ships this one along with the rest of its 55 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for loop-detector

README.md
[![agentmods](https://agentmods.dev/badge/skills/ihabkhaled/ai-psychiatry/loop-detector.svg)](https://agentmods.dev/skills/ihabkhaled/ai-psychiatry/loop-detector)
Your own site
<a href="https://agentmods.dev/skills/ihabkhaled/ai-psychiatry/loop-detector"><img src="https://agentmods.dev/badge/skills/ihabkhaled/ai-psychiatry/loop-detector.svg" alt="Measured on agentmods" height="20"></a>
Per session 35 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 230 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00035 $0.00230
Opus 5 $0.00017 $0.00115
Sonnet 5 $0.00007 $0.00046
Haiku 4.5 $0.00003 $0.00023

Measured 8d ago against content hash 64f2a4cccd38, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

loop-detector scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.ai/skills/loop-detector/SKILL.md · 37 lines

What it actually says

Loop Detector

Core principle

Detect semantic repetition, not only identical syntax; high activity plus flat outcome is probable livelock.

Procedure

  1. List recent actions and their intended evidence.
  2. Group semantically equivalent actions.
  3. Compare completed requirements, removed blockers, and newly passing tests.
  4. Mark repeated actions that added no information.
  5. Identify retry, tool, edit-revert, critic, replan, context, or oscillation patterns.
  6. Trigger attention or strategy recovery at the configured threshold.

Required output

Loop type, repeated strategy, unchanged outcome, threshold, and recovery action.

Limits

Same strategy 3; critics 2; context reloads 2; stalled cycles 4.

Common mistakes

Do not call renamed commands or alternate tools meaningful novelty when they test the same hypothesis.

Stop condition

Stop when repetition is interrupted and a materially different bounded action is selected.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 37 lines · 35 tokens per session scan A 64f2a4cccd38

Subscribe to this mod's changes

loop-detector is a skill published in the GitHub repository ihabkhaled/AI-Psychiatry (3 stars, last pushed 24d ago), licensed MIT. It adds 35 tokens to every session and 230 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

cpp

Use when writing, reviewing, modernizing, building, or debugging C++ - RAII and resource lifetime, smart-pointer ownership, move semantics and the Rule of Zero/Five, target-based CMake with FetchContent, and killing undefined behavior with ASan/UBSan/TSan plus clang-tidy. NOT borrow-checker / Result-Option / cargo…

ericrisco/rsc-harness · 81 tokens

gamedev-physics

Use when working with a game engine's physics — rigid bodies, colliders, collision layers and masks, character controllers, joints, forces versus impulses, raycasts and shapecasts, or when a simulation is unstable (tunnelling, jitter, missed overlaps). Covers the Godot, Unity and Unreal equivalents. NOT rendering or…

ericrisco/rsc-harness · 102 tokens

observability

Use when instrumenting a service from the inside so an incident can be explained from telemetry alone — wiring OpenTelemetry logs, metrics and traces, standing up a Collector, exporting via OTLP, and defining telemetry-driven alerts. NOT outside-in uptime probes, on-call rotation, or who-gets-paged (that is…

ericrisco/rsc-harness · 70 tokens

angular

Use when building, refactoring, or debugging Angular (v20/21+): standalone components, signals, zoneless change detection, @if/@for/@defer control flow, inject() DI, resource()/httpResource(), RxJS interop, NgRx SignalStore, ng CLI. NOT React (that is react), NOT Next.js (that is nextjs), NOT a TypeScript language…

ericrisco/rsc-harness · 89 tokens

debug

Use when something is broken — a failing or flaky test, crash, wrong result or regression — and the root cause must be reproduced and proven before any fix. On-demand; callable mid-implement. NOT a feature to spec or build (that is specify/implement), NOT the lint/test gate (that is verify), NOT adversarial diff…

ericrisco/rsc-harness · 85 tokens

autonomous-bug-fix

Reproduces, diagnoses, fixes, and verifies bugs unaided.

andreaswasita/copilot-agents-dojo · 21 tokens