bmb-refactoring
BMB refactoring session — parallel analysis, cross-model review, and merge.
/BMB-refactoring
Refactoring session with parallel planning, cross-model execution, and review.
YOUR ABSOLUTE RULES
- NEVER explore codebases, read source files, or research anything directly
- NEVER write or edit code — not a single line
- NEVER create files except inside
.bmb/directory - ONLY read files in
.bmb/directory andCLAUDE.md - Your job is DECISIONS, ORCHESTRATION, and RELAY only
- NEVER use the Agent tool — ALL agents spawn via tmux
Prerequisites
- Must be in tmux
.bmb/config.jsonshould exist
Cross-Model Invocation
ALL cross-model invocations MUST use:
~/.claude/bmb-system/scripts/cross-model-run.sh [--profile PROFILE] 'prompt'
Phase 0: Parallel Analysis
-
Spawn Consultant
-
Read config for cross-model provider and timeouts
-
Source auto-learning:
source "$HOME/.claude/bmb-system/scripts/bmb-learn.sh" -
Create worktrees:
mkdir -p .bmb/worktrees git worktree add .bmb/worktrees/refactor-exec refactor-exec-$(date +%s) 2>/dev/null || true -
Track A — Claude analysis (in-process): Lead reads the codebase scope from user's description, spawns bmb-architect to analyze:
CLAUDE_PLAN=$(tmux split-pane -h -d -P -F '#{pane_id}' \ "CLAUDECODE= claude --agent bmb-architect --permission-mode dontAsk \ 'Analyze the codebase for refactoring opportunities. Focus on: {user scope}. \ Write refactoring PLAN (markdown only, no code) to .bmb/handoffs/refactor-plan-claude.md'") -
Track B — Cross-model analysis (independent):
CROSS_PLAN=$(tmux split-pane -h -d -P -F '#{pane_id}' \ "~/.claude/bmb-system/scripts/cross-model-run.sh --profile council \ 'Analyze the codebase for refactoring opportunities. Focus on: {user scope}. \ Write refactoring PLAN to .bmb/handoffs/refactor-plan-cross.md'") -
Poll both with separate timeouts.
Phase 0.5: Synthesis
- Read both plans
- Auto-confirm agreement points
- Present conflicts to user via Consultant
- Consultant explains tradeoffs
- Write final
refactor-plan.md
Phase 1: Execution
Spawn cross-model executor in worktree:
EXEC_PANE=$(tmux split-pane -h -d -P -F '#{pane_id}' \
"~/.claude/bmb-system/scripts/cross-model-run.sh --profile exec-assist \
'Read .bmb/handoffs/refactor-plan.md. Execute the refactoring in .bmb/worktrees/refactor-exec/. \
Write results to .bmb/handoffs/refactor-exec-result.md'")
Poll with cross_model timeout.
Phase 2: Cross-Review
Spawn bmb-verifier (Claude) to review the diff:
REVIEW_PANE=$(tmux split-pane -h -d -P -F '#{pane_id}' \
"CLAUDECODE= claude --agent bmb-verifier --permission-mode dontAsk \
'Review the refactoring diff in .bmb/worktrees/refactor-exec/. \
Check architecture, security, intent fidelity. \
Write review to .bmb/handoffs/refactor-review.md'")
If review finds issues: bmb_learn MISTAKE "refactor-review" "{issue description}" "{preventive rule}"
Phase 3: Fix + Simplify
- If review has issues: spawn executor to fix in worktree
- Optional: spawn bmb-simplifier for cleanup
- Re-verify after fixes
- If fix attempt fails:
bmb_learn MISTAKE "refactor-fix" "{what failed}" "{lesson}"
Phase 4: Merge + Commit + Push
- Read git config from
.bmb/config.json - Merge worktree changes:
cd .bmb/worktrees/refactor-exec && git add -A && git commit -m "refactor: {description}" cd {project_root} git merge refactor-exec-{timestamp} git worktree remove .bmb/worktrees/refactor-exec - Git push based on config (yes/no/ask)
- Kill Consultant pane
- Present summary