Skip to main content

LoopGuard

Real-time AI coding agent loop detector for Claude Code that prevents wasted tokens and costs by alerting you when agents get stuck in repetitive loops.

The Problem

AI coding agents get stuck in repetitive loops — editing the same file over and over, hitting the same error repeatedly, hallucinating tool calls — burning your token quota and costing real money before you even notice.

LoopGuard monitors your Claude Code sessions in real-time and sends desktop notifications when it detects the agent is looping.

Features

  • Real-time Monitoring: Background service that auto-detects Claude Code sessions
  • Loop Detection: Identifies three types of loops:
    • Repeated identical tool calls (same tool + parameters)
    • Repeated identical error messages
    • No meaningful file changes during activity
  • Desktop Alerts: Native macOS notifications with actionable information
  • Configurable Thresholds: Customize detection sensitivity per project
  • Zero Friction: Install once, runs automatically on login

Quick Start

Installation

pip install loopguardian

Dependencies

# Install terminal-notifier for desktop notifications
brew install terminal-notifier

Usage

# Start LoopGuard service
loopguardian start

# Check status
loopguardian status

# Test notifications
loopguardian test

Configuration

Create a loopguardian.config.json file in your project root or ~/.loopguardian/config.json:

{
  "detection": {
    "tool_call_repeats": 3,
    "error_repeats": 2,
    "stagnation_minutes": 5
  },
  "notifications": {
    "enabled": true,
    "throttle_seconds": 30
  }
}

Detection Settings

  • tool_call_repeats: Number of identical tool calls before alerting (default: 3)
  • error_repeats: Number of identical errors before alerting (default: 2)
  • stagnation_minutes: Minutes of activity without file changes before alerting (default: 5)

Notification Settings

  • enabled: Enable/disable desktop notifications (default: true)
  • throttle_seconds: Minimum seconds between identical alerts (default: 30)

How It Works

  1. Process Detection: LoopGuard monitors for Claude Code processes starting up
  2. Log Monitoring: When Claude Code is detected, LoopGuard starts watching the session log files
  3. Pattern Analysis: Real-time analysis detects loop patterns using configurable thresholds
  4. Desktop Alerts: Immediate notifications when loops are detected with suggested actions

Example Alerts

🚨 LOOP DETECTED: Tool 'str_replace' repeated 3 times on auth.py.
   Session: a1b2c3d4e5f6...
   Severity: medium  
   Suggested: Interrupt the session and provide more specific context

Architecture

  • Process Monitor: Detects Claude Code startup via process monitoring
  • Log Monitor: File watching service for Claude Code session logs
  • Loop Detector: Pattern recognition engine with configurable thresholds
  • Notification Service: macOS desktop notification system
  • Configuration Manager: Handles settings and user preferences

Development

# Install development dependencies
pip install -r requirements.txt

# Run in development mode
python -m loopguard.cli start

License

MIT License - see LICENSE file for details.

Contributing

Contributions welcome! Please read the contributing guidelines and submit pull requests to the GitHub repository.

Metadata

Release files for loopguardian 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for loopguardian 0.1.1
File Size Uploaded
loopguardian-0.1.1.tar.gz 92.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for loopguardian 0.1.1
File Interpreter ABI Platform
loopguardian-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 159.3 kB

Release files / loopguardian-0.1.1.tar.gz

Download URL loopguardian-0.1.1.tar.gz
Size 92.4 kB
Tags Source
SHA-256 checksum
How to use checksums
69d33b92d8f51634499c8e3579bd41b3e6ca5f81ae6a35c2a2f9f2c5ee09fbdb
BLAKE2b-256 checksum
How to use checksums
4aedd5318de2cfc604cde86d5c12c1b7185e690301f5f1bbc7119a2e7d33ffda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / loopguardian-0.1.1-py3-none-any.whl

Download URL loopguardian-0.1.1-py3-none-any.whl
Size 66.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9fa10b9fe363d309b76a9be52aa568af604df65b8486d309a7bf5116e713ac1
BLAKE2b-256 checksum
How to use checksums
d48f766b0bbe93d5679fc565be6860c97ce93b512f7374f3f6d898d19696e31b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page