home / skills / zpankz / mcp-skillset / refactor

refactor skill

/refactor

This skill guides you through architecture refactoring and code optimization by validating components and auditing systems for efficiency and coherence.

npx playbooks add skill zpankz/mcp-skillset --skill refactor

Review the files below or copy the command above to add this skill to your agents.

Files (22)
SKILL.md
1.8 KB
---
name: refactor
description: |
  Meta-cognitive architecture optimization skill. Use when the user asks to
  "refactor the architecture", "optimize claude code", "evaluate components",
  or "run architecture audit". Also triggers automatically every 24 hours.
allowed-tools: Task, Read, Write, Edit, Grep, Glob, Bash, WebFetch, WebSearch, TodoWrite
model: opus
context: fork
agent: refactor-agent
user-invocable: true
---

# Refactor Skill

## Trigger Patterns

- "/refactor"
- "refactor the architecture"
- "optimize my claude code setup"
- "evaluate all components"
- "run architecture audit"
- "check for redundancies"
- "optimize token usage"

## Applicable Specialized Agents

- refactor-agent (primary orchestrator)
- component-architect-agent (validation)
- knowledge-domain-agent (learning integration)

## Infrastructure Dependencies

| Tool | Purpose | Health Check |
|------|---------|--------------|
| bv/bd | Graph orchestration | `bd --version` |
| tweakcc | System prompt editing | `ls ~/.tweakcc/` |
| claude-mem | Context optimization | `curl localhost:37777/health` |
| hookify | Validation hooks | `hookify --version` |

## Optimization Frameworks

1. **Homoiconic Renormalization** - Self-referential optimization
2. **BFO/GFO Ontology** - Formal type definitions
3. **Hegelian Dialectics** - Thesis-antithesis-synthesis
4. **Pareto Optimization** - Multi-objective efficiency

## 24-Hour Auto-Trigger

```xml
<!-- ~/.claude/launchd/com.claude.refactor.plist -->
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.claude.refactor</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>-c</string>
        <string>claude -p "/refactor --auto"</string>
    </array>
    <key>StartInterval</key>
    <integer>86400</integer>
</dict>
</plist>
```

Overview

This skill performs meta-cognitive architecture optimization for Claude-based systems, focusing on component evaluation, redundancy removal, and token-efficiency improvements. It orchestrates specialized agents to audit architecture, suggest refactors, and apply formal optimization frameworks for measurable gains. It also supports an optional 24-hour auto-audit to keep systems continuously optimized.

How this skill works

The skill runs a coordinated audit using a refactor orchestrator and supporting validation and knowledge agents. It inspects component interactions, prompt and memory usage, orchestration tooling health, and configuration patterns to identify bottlenecks and redundancies. Recommendations map to concrete changes: code-level refactors, prompt edits, memory tuning, or infrastructure fixes. Optionally, automated scripts can run on a daily schedule to surface regressions and incremental improvements.

When to use it

  • When you ask to refactor the architecture or optimize Claude code
  • Before major deployments to reduce runtime cost and token usage
  • If you suspect redundant or fragile components in the pipeline
  • When integrating new knowledge domains or changing orchestration tools
  • To run scheduled health and optimization audits (daily trigger)

Best practices

  • Start with automated scans to capture health signals from orchestration and memory tools
  • Prioritize changes by impact and effort using Pareto-style ranking
  • Validate proposed refactors with the component-architect agent before rollout
  • Keep system prompts and memory schemas minimal and version-controlled
  • Automate periodic audits but gate production changes behind tests and reviews

Example use cases

  • Audit a Claude orchestration to cut token usage and reduce latency
  • Identify and remove redundant validation hooks that add cost
  • Refactor component boundaries for clearer responsibility and easier testing
  • Tune context memory settings to improve relevance and reduce hallucinations
  • Run a daily auto-audit to detect drift after frequent model or prompt updates

FAQ

What does the automated 24-hour audit change automatically?

By default the daily audit only analyzes and reports findings; automatic changes require explicit approval or an opt-in setting.

Which infrastructure checks are performed?

The skill verifies common orchestration and validation tool health, memory service availability, and system prompt locations to ensure dependencies are functioning.

refactor skill by zpankz/mcp-skillset