ALL BELOW STUFF IS WRITTEN BY CLAUDE; IT'S JUST IDEA IN DEVELOPMENT TO MINISE LLM WORK WITHIN THE SYSTEM. THE IDEA IS TO IDENTIFY WHAT TRENDS IT LIKES TO DO THE MOST ALONG WITH WHAT TRIGGERS IT. AND ISNTEAD WE MAKE SCRIPTS THAT THE LLM CAN RUN ISNTEAD OF DOING THE GRUNT OF THE WORK. I built loop-sweep because I kept noticing the same patterns across my Claude Code sessions — same file reads, same setup prompts, same corrections I'd already solved. Instead of guessing what to automate, I wanted data. loop-sweep runs against your session logs nightly, clusters repeated patterns, ranks them by estimated token waste, and suggests concrete automations. It's a profiler for your AI workflow.
Profile your AI workflow like you profile your code
- Scans your
~/.claude/projects/JSONL session logs (all projects, last 7 days) - Extracts every bash command, file read, grep, agent spawn, edit, and user prompt
- Normalizes and deduplicates similar patterns (token-based Jaccard similarity)
- Ranks by estimated token cost (highest waste first)
- Generates a markdown report with:
- Why it was flagged — what's being repeated and why it matters
- What the automation does — plain-language description of the suggested fix
- Suggested implementation — starter code in Rust, Python, or Shell
- Cross-project tracking — patterns that appear across multiple projects
# Nightly SOP Recommendations — 2026-04-03
Scanned 1195 sessions across 16 projects, 32,091 entries over 7 days.
Found 115 automatable patterns (ranked by token cost, highest ROI first).
Estimated total token waste: ~748,850/week
Cross-project patterns: 29
---
## #1 — Repeated Pattern: Read
Occurrences: 579 times in the last 7 days
Estimated token cost: ~173,700 tokens/week
### Why this was flagged
The same file was read 579 times across sessions. Claude re-reads it
each time because it doesn't persist across conversations...
### What the automation does
A Rust script that pre-loads this file's contents at session start...
git clone https://github.com/HemangKumawat/loop-sweep.git
cd loop-sweep
# Run it
python3 sop_cycle.py
# Output appears in output/sop_latest.md(crontab -l 2>/dev/null; echo "0 4 * * * cd /path/to/loop-sweep && python3 sop_cycle.py >> output/cron.log 2>&1") | crontab -All config via environment variables:
| Variable | Default | Description |
|---|---|---|
SOP_PROJECTS_BASE |
~/.claude/projects |
Base directory containing Claude project folders |
SOP_SESSION_DIR |
(empty = scan all) | Override to scan a single project directory |
SOP_OUTPUT_DIR |
./output |
Where to write markdown reports |
SOP_MIN_OCCURRENCES |
3 |
Minimum repeats before flagging a pattern |
SOP_LOOKBACK_DAYS |
7 |
How many days of logs to scan |
# Example: scan only one project, require 5+ occurrences
SOP_SESSION_DIR=~/.claude/projects/-home-user-myproject SOP_MIN_OCCURRENCES=5 python3 sop_cycle.py- Multi-project scanning — scans all Claude project directories, not just one
- Pattern deduplication — merges similar commands (e.g.,
pytest tests/andpython -m pytest tests/) using token-based similarity - ROI-based ranking — highest token waste appears first, with tool-aware cost estimates (agent spawns cost more than mkdir)
- Cross-project detection — flags patterns that appear in multiple projects
- Progress message parsing — captures user-facing content from hook/progress messages
- Zero dependencies — stdlib only (json, re, collections, pathlib, datetime)
- Read-only — never modifies your code, configs, or session logs
- Idempotent — safe to run multiple times; overwrites same-day output only
If you have a web dashboard, symlink the output directory:
ln -s /path/to/loop-sweep/output /path/to/your-dashboard/sop_recommendationsThe output markdown uses a stable, regex-parseable format:
## #N — Repeated Pattern: ToolName**Occurrences:** N times**Estimated token cost:** ~N tokens/week**Cross-project:** Found in project-a, project-b
pip install pytest
python -m pytest tests/ -v16 tests covering parsing, normalization, deduplication, clustering, cost estimation, and output format.
~/.claude/projects/ loop-sweep output/
├── project-a/*.jsonl ──> ┌──────────────────┐ ──> sop_latest.md
├── project-b/*.jsonl ──> │ Parse → Normalize │ ──> sop_2026-04-03.md
├── project-c/*.jsonl ──> │ Dedup → Cluster → │
└── ... │ Rank → Generate │
└──────────────────┘
This started as a personal tool and it shows in places. Here's what would make it genuinely better:
- Smarter pattern detection. The current approach uses string similarity and frequency counting. It catches obvious repetitions but misses semantic duplicates — same intent, different wording. If you've worked with embeddings, LSH, or text clustering, there's real low-hanging fruit here.
- Context-aware suggestions. The suggestion engine is a static lookup table. It doesn't check your existing CLAUDE.md or installed tools, so it sometimes recommends automations you've already set up. Making this aware of your actual config would be a meaningful upgrade.
- Better reporting. Output is markdown right now. Structured output (JSON for tooling, HTML for humans) and a way to track whether your automations actually reduced waste over time are both wide open.
- Your data. Run loop-sweep against your own logs and tell us what it caught, what it missed, and what surprised you. False-positive reports and anonymized log samples are high-value contributions that don't require writing code.
The codebase is small enough to read in one sitting. No CLA, no templates, no ceremony — fork, branch, PR. If it's a big change, open an issue first so we don't duplicate effort. If you're not sure about something, just ask in the issue tracker.
MIT