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
- Process Detection: LoopGuard monitors for Claude Code processes starting up
- Log Monitoring: When Claude Code is detected, LoopGuard starts watching the session log files
- Pattern Analysis: Real-time analysis detects loop patterns using configurable thresholds
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file loopguardian-0.1.0.tar.gz.
File metadata
- Download URL: loopguardian-0.1.0.tar.gz
- Upload date:
- Size: 91.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d702154663bec8f3a50c2353d3d537242e09077cf43db66f0e3f3b89398fd0b1
|
|
| MD5 |
f9058afa6f6c84abc94dd0e28aac06e3
|
|
| BLAKE2b-256 |
e6382fe9bb50ddd65631f798fbb14e6fb3f235d43ec331c79a7189d8410e3c9c
|
File details
Details for the file loopguardian-0.1.0-py3-none-any.whl.
File metadata
- Download URL: loopguardian-0.1.0-py3-none-any.whl
- Upload date:
- Size: 66.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28aa8b5fdf5ba8420035fddb8dda1ddb9def1666a5b63a4d261e4be853853cc3
|
|
| MD5 |
48ef38efa9cef140bf442c2be6d12ac3
|
|
| BLAKE2b-256 |
fee1c7c3ada0fa1cb35089360de25e96660f38fe85c209a13499c0ae556b6606
|