Use Case: Refactoring

Refactoring changes structure, never behavior. The running example here is the option parsing duplicated across the CLI commands — surfaced by an architecture review, consolidated under a plan, and verified to have changed nothing but the structure.

  1. 1

    Structure

    Review the Architecture

    The code base is reviewed for package cohesion and inter-package coupling, which reports the duplication as a persisted PROBLEM finding with an id, next to an architecture diagram.

    Claude Code
    ❯/ase-arch-analyze --prefix cli src/
  2. 2

    Plan

    Choose the Refactoring Approach

    Refactoring follows its own tenets — behavior preservation, Boy Scout Rule, DRY, SRP — so alternative approaches with pros and cons are proposed, you pick one, and a persisted task plan is composed for it.

    Claude Code
    ❯/ase-task-edit --mode refactor --approach getopt: consolidate the option parsing of all CLI commands into src/ase-getopt.ts (finding cli-P1)
  3. 3

    Realization

    Draft, Then Implement

    The draft shows every call site the consolidation touches; only then does the implementation run, isolated in its own Git worktree.

    Claude Code
    ❯/ase-task-implement --draft getopt
    ❯/ase-task-implement --worktree consolidate getopt
  4. 4

    Behavior Preservation

    Check the Diff Stays Pure

    The staged diff is retold as an intent-grouped narrative with a coherence check, which is where a behavior change smuggled into a refactoring shows up.

    Claude Code
    ❯/ase-repo-diff --coherence --risk
  5. 5

    Direct Mode

    Or Refactor In One Shot

    For a rename-sized refactoring, the plan ceremony is skipped and the change applied in place; for anything in between, the fused editor refactors, grills, and verifies in a single call.

    Claude Code
    ❯/ase-code-edit --mode refactor rename parseArgs to parseOptions in src/ase-getopt.ts
    ❯/ase-code-edit --mode refactor --grill --verify --worktree option-table extract the shared option table of the CLI commands into src/ase-getopt.ts
npm install -g @rse/ase && ase setup install