Skip to main content

Real-time AI coding agent loop detector for Claude Code

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loopguardian-0.1.1.tar.gz (92.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loopguardian-0.1.1-py3-none-any.whl (66.9 kB view details)

Uploaded Python 3

File details

Details for the file loopguardian-0.1.1.tar.gz.

File metadata

  • Download URL: loopguardian-0.1.1.tar.gz
  • Upload date:
  • Size: 92.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for loopguardian-0.1.1.tar.gz
Algorithm Hash digest
SHA256 69d33b92d8f51634499c8e3579bd41b3e6ca5f81ae6a35c2a2f9f2c5ee09fbdb
MD5 ba5b858d7e544bf99f5193150a5c9466
BLAKE2b-256 4aedd5318de2cfc604cde86d5c12c1b7185e690301f5f1bbc7119a2e7d33ffda

See more details on using hashes here.

File details

Details for the file loopguardian-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: loopguardian-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 66.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for loopguardian-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f9fa10b9fe363d309b76a9be52aa568af604df65b8486d309a7bf5116e713ac1
MD5 5d251966208916798cca34cf2f9c620b
BLAKE2b-256 d48f766b0bbe93d5679fc565be6860c97ce93b512f7374f3f6d898d19696e31b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page