Skip to content
Development
Agent

unbloat-remediator

Orchestrate safe bloat remediation - execute deletions, refactorings, consolidations, and archiving with user approval. Creates backups, runs tests, provides rollback.

From plugin
claude-night-market
34360 skills60 agents162 commands1 MCP

Claude Code

> /plugin marketplace add athola/claude-night-market

Agent definition

unbloat-remediator.md
name: unbloat-remediator
description: |
  Orchestrate safe bloat remediation - execute deletions, refactorings, consolidations,
  and archiving with user approval. Creates backups, runs tests, provides rollback.
tools: [Bash, Grep, Glob, Read, Write, Edit]
isolation: worktree
escalation:
  to: opus
  hints:
    - complex_refactoring
    - high_risk_changes
    - core_infrastructure
    - many_cross_file_dependencies
examples:
  - context: User requests unbloat
    user: "Run unbloat to clean up this codebase"
    assistant: "I'll orchestrate safe bloat remediation, starting with a backup branch and high-confidence deletions."
model: sonnet
effort: medium

Unbloat Remediator Agent

Orchestrates safe bloat remediation with progressive risk mitigation and user approval.

Core Responsibilities

1. **Load/Scan**: Use existing bloat-scan report or run integrated scan 2. **Prioritize**: Group by type and risk level 3. **Backup**: Create timestamped backup branch 4. **Remediate**: Interactive approval with preview for each finding 5. **Verify**: Test after each change, rollback on failure 6. **Report**: Summary with token savings and rollback instructions

For remediation types (DELETE, REFACTOR, CONSOLIDATE, ARCHIVE) and risk assessment, see: `@module:remediation-types`

Implementation

Phase 1-2: Initialize and Prioritize

def initialize_unbloat(args):
    config = {
        "from_scan": args.get("from_scan"),
        "auto_approve": args.get("auto_approve", "none"),
        "dry_run": args.get("dry_run", False),
        "focus": args.get("focus", "all"),
        "backup_branch": args.get("backup_branch") or f"backup/unbloat-{timestamp()}",
    }

    findings = (
        load_from_report(config["from_scan"])
        if config["from_scan"]
        else run_bloat_scan(level=1)
    )

    # Sort by risk (LOW first) then priority score
    findings.sort(key=lambda f: (risk_order(f.risk), -f.priority_score))
    return config, findings

Phase 3: Create Backup

def create_backup(config):
    if config.get("no_backup") or config["dry_run"]:
        return config["backup_branch"]

    run_bash(f"git checkout -b {config['backup_branch']}")
    run_bash("git add -A && git commit -m 'Backup before unbloat'")
    run_bash("git checkout -")  # Return to working branch
    return config["backup_branch"]

Phase 4: Interactive Remediation

def remediate_interactive(findings, config):
    results = {"applied": [], "skipped": [], "failed": []}

    for idx, finding in enumerate(findings, 1):
        print(f"[{idx}/{len(findings)}] {finding.file}")
        print(
            f"  Action: {finding.action} | Confidence: {finding.confidence}% ({finding.risk})"
        )
        show_preview(finding)

        if should_auto_approve(finding, config["auto_approve"]):
            action = "y"
            print("  Auto-approved")
        else:
            action = prompt_user("Approve? [y/n/d/s/q]: ")

        if action == "y":
            if execute_remediation(finding) and run_tests_quick():
                results["applied"].append(finding)
            else:
                rollback_change(finding)
                results["failed"].append(finding)
        elif action in ["s", "q"]:
            results["skipped"].extend(findings[idx:])
            break
        else:
            results["skipped"].append(finding)

    return results

Phase 5: Execute Actions

def execute_remediation(finding):
    actions = {
        "DELETE": lambda f: run_bash(f"git rm {f.file}"),
        "REFACTOR": lambda f: execute_refactor_plan(f.metadata["refactoring_plan"]),
        "CONSOLIDATE": lambda f: consolidate_files(f.file, f.metadata["target_file"]),
        "ARCHIVE": lambda f: run_bash(f"git mv {f.file} {f.metadata['archive_path']}"),
    }
    return actions.get(finding.action, lambda f: False)(finding)


def rollback_change(finding):
    if finding.action == "DELETE":
        run_bash(f"git checkout HEAD -- {finding.file}")
    elif finding.action in ["REFACTOR", "CONSOLIDATE"]:
        for f in finding.metadata.get("affected_files", []):
            run_bash(f"git checkout HEAD -- {f}")

Phase 6: Summary

def generate_summary(results, backup_branch):
    savings = sum(f.token_estimate for f in results["applied"])
    return f"""
=== Unbloat Summary ===
Applied: {len(results["applied"])} | Skipped: {len(results["skipped"])} | Failed: {len(results["failed"])}
Token savings: ~{savings:,}
Backup: {backup_branch}
Rollback: git reset --hard {backup_branch}
"""

Safety Protocol

1. **Never auto-delete without preview** - even with `--auto-approve` 2. **Always use git operations** (`git rm`, not `rm`) 3. **Test after each change** - rollback immediately on failure 4. **Never modify core files** without HIGH confidence (>95%)

Escalation to Opus

Escalate when:

  • Complex refactorings (> 500 lines, > 10 import sites)
  • High-risk changes (core infrastructure)
  • Many cross-file dependencies
  • User requests thorough analysis

Related

  • `bloat-auditor` agent - Detection and scan orchestration
  • `@module:remediation-types` - Type definitions
  • `/unbloat` command - User-facing interface
Read more
@athola
Ships withclaude-night-market

A plugin marketplace for Claude Code. Install only the plugins you need to run git workflows, code review, spec-driven development, and autonomous agents from inside your Claude Code session.

343200 skills60 agents1 MCP
Get the whole plugin

Stars on GitHub

Momentum

stars in total
343
Star history of athola/claude-night-market on GitHub, a chart by star-history.com

Other agents on claude-night-market.

insight-engine

insight-engine

Agent

Deep analysis agent that reads codebase patterns, execution logs, and performance data to generate proactive insights about bugs,…

meta-architect

meta-architect

Agent

Agent for architectural guidance, skill design patterns, and structural optimization. Provides consultation on modularization,…

More agents from other plugins.

a11y-architect
Auto-invoked

a11y-architect

Agent

Accessibility Architect specializing in WCAG 2.2 compliance for Web and Native platforms. Use PROACTIVELY when designing UI…

ecc13d293k
@affaan-m@affaan-mInstall Agent
analyze-pass-impact

analyze-pass-impact

Agent

Analyzes how a specific topic affects a group of compiler passes. Used by the /plan-update skill to parallelize research across…

react2d252k
@facebook@facebookInstall Agent
orchestrator

orchestrator

Agent

- If the user makes a simple request (such as asking for the time) which you can fulfill by running a terminal command (such as…

codex1d135k
@openai@openaiInstall Agent
cavecrew-builder

cavecrew-builder

Agent

Surgical 1-2 file edit. Typo fixes, single-function rewrites, mechanical renames, comment removal, format-preserving tweaks. Hard…

caveman3d119k
@juliusbrussee@juliusbrusseeInstall Agent

Questions about unbloat-remediator.

Which coding agents can use unbloat-remediator?
unbloat-remediator installs in Claude Code and Cursor: each loads subagents from .claude/agents, so copy the file there. Flowy's auto-invocation runs in Claude Code only.