@baublet/agent-looper
v1.1.1
Published
Autonomous AI agent execution with iterative planning - runs agents in a continuous loop
Maintainers
Readme
Agent Looper
Autonomous AI agent execution with iterative planning. Runs AI agents (like Claude CLI) in a continuous loop, enabling autonomous work through a planning document.
Features
- Autonomous Execution: Run AI agents in a continuous loop
- Plan-Driven: Agent works through a markdown planning document
- Real-Time Controls: Pause, kill, add notes, or quit at any time
- Token Tracking: Monitor token usage and costs across iterations
- Web UI: Remote monitoring and control via browser
- Cross-Platform: Works on Linux, macOS, and Windows
- Zero Runtime Dependencies: Pure Node.js implementation
Installation
# Using npx (no installation required)
npx @baublet/agent-looper ./plan.md
# Global installation
npm install -g @baublet/agent-looper
# Then run with any of these commands:
agent-looper ./plan.md
agentLooper ./plan.md
al ./plan.mdQuick Start
- Create a plan document (or use
--exampleto see the format):
# My Project Plan
## Overview
Building a new feature for the application.
## Tasks
- [ ] Research existing implementation
- [ ] Design the solution
- [ ] Implement core functionality
- [ ] Write tests
- [ ] Update documentation
## Completed
<!-- Tasks will be moved here -->
## Notes
- Important context goes here- Start the agent loop:
agent-looper ./my-plan.md- Use controls during execution:
p- Pause/Resume the loopk- Kill current agent (starts next iteration)n- Add a note for the next iterationq- Quit the loop
Usage
agent-looper <plan-document>
USAGE:
agent-looper <plan-document>
agent-looper --plan <plan-document>
agent-looper --example
OPTIONS:
-y, --yes Skip confirmation prompt
-q, --quiet Suppress non-essential output (errors and final stats still shown)
--dry-run Show configuration and exit without running
--max-iterations <n> Maximum iterations to run (0 = unlimited)
--max-time <minutes> Max time per iteration before considered failed (default: 60)
--planning-cmd <cmd> Command for planning mode (default: claude)
--agent-cmd <cmd> Command for agent execution
--log <file> Log file path (default: agentLoop.log)
--web-ui <secret> Enable web UI with the given secret
--completion-doc <file> Path to completion criteria document for auto-quit
--resume Resume from saved state if available
--example Show example plan structure
--version, -v Show version
--help, -h Show this help message
EXAMPLES:
agent-looper ./project-plan.md
agent-looper -y ./plan.md
agent-looper --dry-run ./plan.md
agent-looper --agent-cmd "claude -p --model opus" ./plan.md
agent-looper --max-iterations 5 ./plan.md
agent-looper --max-time 30 ./plan.md
agent-looper --completion-doc ./done-criteria.md ./plan.md
agent-looper --resume ./plan.mdHow It Works
Each iteration of the loop:
- Orient: Agent reads the plan and understands current state
- Refine: Agent updates the plan, promotes backlog items, removes stale tasks
- Execute: Agent completes one task fully
- Review: Agent verifies work and makes improvements
- Update: Agent records progress and prepares for next iteration
The human operator can:
- Watch progress in real-time
- Pause to review work
- Inject notes/guidance for the next iteration
- Kill stuck iterations
- Quit when satisfied
Plan Document Format
The plan document is a markdown file that serves as the agent's source of truth:
# Project Name
## Overview
What you're building and why.
## Goals
1. Primary objective
2. Secondary objectives
## Current Work
- [ ] Active task 1
- [ ] Active task 2
## Backlog
- [ ] Future task 1
- [ ] Future task 2
## Completed
- [x] Done task (moved here with notes)
## Notes
- Context and decisions
- Links and referencesConfiguration File
Create a .agentlooperrc file in your project directory or home directory to set default options:
{
"yes": true,
"maxIterations": 10,
"maxTime": 30,
"planningCmd": "claude",
"agentCmd": "claude -p --model opus --verbose --output-format json",
"log": "agent.log",
"webUi": "mysecret"
}Configuration precedence:
- CLI arguments (highest priority)
.agentlooperrcin current directory.agentlooperrcin home directory- Built-in defaults (lowest priority)
Available options:
| Config Key | CLI Flag | Description |
|------------|----------|-------------|
| yes | -y, --yes | Skip confirmation prompt |
| quiet | -q, --quiet | Suppress non-essential output |
| maxIterations | --max-iterations | Maximum iterations (0 = unlimited) |
| maxTime | --max-time | Max minutes per iteration (default: 60) |
| planningCmd | --planning-cmd | Command for interactive planning |
| agentCmd | --agent-cmd | Command for agent execution |
| log | --log | Log file path |
| webUi | --web-ui | Secret for web UI access |
See examples/agentlooperrc.example.json for a complete example.
Custom Agent Commands
By default, Agent Looper uses the Claude CLI. You can use any compatible agent:
# Use Claude with specific model
agent-looper --agent-cmd "claude -p --model opus" ./plan.md
# Use with additional flags
agent-looper --agent-cmd "claude -p --verbose --output-format json" ./plan.mdThe agent command receives the full prompt (plan document + instructions) as an argument.
Interactive Planning
Create a new plan interactively before starting the loop:
agent-looper --plan ./new-project.mdThis launches the planning command (default: claude) to help you create the initial plan.
Session Persistence
Agent Looper saves session state after each iteration, enabling resumption of interrupted loops:
# Start a loop
agent-looper ./plan.md
# (interrupted by Ctrl+C or quit)
# Resume from where you left off
agent-looper --resume ./plan.mdState includes:
- Iteration count and success/failure stats
- Total duration and per-iteration timings
- Token usage and cost estimates
- Peak memory usage
State file location: .agentlooper.<plan-name>.state.json adjacent to your plan document.
To start fresh (ignoring saved state), omit the --resume flag.
Token Usage & Cost Tracking
Agent Looper tracks token usage and estimated costs across iterations:
Stats: Iterations: 5 | Success: 5 | Failed: 0 | Time: 12m 34s | Tokens: 125.3K ($2.45)Token tracking requires --output-format json in the agent command (included by default).
Log Files
All agent output is logged to agentLoop.log (or custom path with --log):
# View logs in real-time
tail -f agentLoop.log
# Custom log path
agent-looper --log ./logs/session.log ./plan.mdAutomated Completion Detection
Use --completion-doc to specify a completion criteria document. After each successful iteration, a separate AI evaluation checks if the project meets the completion criteria:
agent-looper --completion-doc ./done-when.md ./plan.mdCompletion criteria document example (done-when.md):
# Done When
1. All tests pass
2. Documentation is updated
3. No TODO items remain in the plan
4. Build generates no errorsSee examples/completion-criteria.md for a more detailed example.
How it works:
- After each successful agent iteration, the completion evaluator runs
- It reads both the plan document and completion criteria
- If criteria are NOT met: logs why and continues to the next iteration
- If criteria ARE met: creates
PLAN.completionSummary.mdand exits the loop
Token tracking: Completion evaluator tokens are tracked separately and shown in final stats:
Completion Evaluator:
Tokens: 5.2K (in: 4.8K, out: 0.4K)
Cost: $0.12
Combined Totals:
Tokens: 130.5K
Cost: $2.57Web UI
Enable a web-based dashboard for remote monitoring and control:
agent-looper --web-ui mysecrettoken ./plan.mdWhen started, the CLI displays a URL like:
Web UI: http://127.0.0.1:54321/?secret=mysecrettokenThe web UI provides:
- Real-time Statistics: Iteration count, success/failure rates, duration, token usage, and costs
- Live Log Streaming: Watch agent output in real-time via Server-Sent Events
- JSON Log Explorer: Browse and inspect JSON log entries with smart formatting for dates, tokens, costs, and large text
- Remote Controls: Pause/resume, kill current agent, add notes, and quit
- Connection Status: Shows if the browser is connected to the server
Security: The secret token must be in the URL query parameter. Requests without the correct secret return 404. The server only binds to localhost (127.0.0.1).
Requirements
- Node.js 18+
- Claude CLI (or compatible agent command)
Development
# Clone the repository
git clone https://github.com/baublet/agent-looper.git
cd agent-looper
# Install dependencies
npm install
# Install pre-commit hook (recommended)
cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
# Or symlink: ln -sf ../../scripts/pre-commit .git/hooks/pre-commit
# Build
npm run build
# Type check
npm run typecheck
# Run locally
node dist/cli.js --helpBuild Artifacts
Build artifacts in dist/ are version controlled. The pre-commit hook automatically:
- Runs the build (
npm run build) - Stages the built files (
git add dist/)
This ensures NPM packages are published with pre-built artifacts and no build step is required during npm publish.
You can run type checking manually with npm run typecheck.
Versioning
This project follows Semantic Versioning (SemVer):
- MAJOR (1.0.0 → 2.0.0): Breaking changes
- MINOR (1.1.0 → 1.2.0): New features, backwards compatible
- PATCH (1.1.0 → 1.1.1): Bug fixes, backwards compatible
Pre-release versions use suffixes like 1.2.0-beta.1 or 1.2.0-rc.1.
Releasing
Prerequisites
- npm authentication: Run
npm loginor setNPM_TOKEN - Clean working directory: All changes committed and pushed
- Correct branch: Release versions require
main/masterbranch
Release Process
# 1. Ensure tests pass
npm run test:all
# 2. Update version in package.json manually
# Edit package.json to set the new version number
# 3. Update CHANGELOG.md
# Move items from [Unreleased] to new version section
# 4. Commit version bump
git add package.json CHANGELOG.md
git commit -m "Release v1.2.0"
git tag v1.2.0
# 5. Push to GitHub
git push && git push --tags
# 6. Publish to NPM (runs all checks automatically)
npm run publish:npmPublish Script
The publish script (npm run publish:npm) automatically:
- ✅ Verifies npm authentication
- ✅ Runs the build
- ✅ Checks for uncommitted changes
- ✅ Validates branch (release versions require main/master)
- ✅ Publishes to NPM
Use npm run publish:check to do a dry run without publishing.
Pre-release Versions
Pre-release versions (e.g., 1.2.0-beta.1) can be published from any branch:
# Edit package.json to set version like "1.2.0-beta.1"
git add package.json
git commit -m "Pre-release v1.2.0-beta.1"
npm run publish:npmVerifying the Release
After publishing:
# Check NPM
npm view @baublet/agent-looper
# Test installation
npx @baublet/agent-looper@latest --versionArchitecture
src/
├── cli.js # CLI entry point
├── main.js # Library exports
└── lib/
├── args.js # Argument parsing
├── colors.js # Terminal colors
├── completion.js # Completion evaluation
├── config.js # Configuration file loading
├── format.js # Formatting utilities
├── logger.js # Logging infrastructure
├── loop.js # Main agent loop
├── notes.js # Notes input screen
├── prompt.js # Prompt generation
├── spinner.js # Spinner animation
├── state.js # Session state persistence
├── status.js # Status display
├── terminal.js # Terminal control
├── tokens.js # Token extraction
└── webui/
└── server.js # Web UI HTTP serverLicense
MIT
