---
name: archive
description: Archive completed MASTER_PLAN files to ~/archive/YYYY-MM-DD/
arguments: "[--all] [--dir=PATH]"
---

# /archive Command

Archive completed MASTER_PLAN*.md files from the project root to a dated archive directory. If archiving the active plan, reset the Active Phase to idle.

## Arguments

- `--all` — Skip confirmation and archive all found files
- `--dir=PATH` — Override archive base directory (default: `~/archive`)

## Behavior

### Step 1: Discover Files

Scan the project root for `MASTER_PLAN*.md` files.

If none are found, report that and stop.

### Step 2: Confirm with User

Unless `--all` was passed, use `AskUserQuestion` to confirm:

**Question**: "Which MASTER_PLAN files should be archived?"

**Header**: "Archive"

**Options**:
1. **"All files"** — Description: list all found filenames
2. **"Let me choose"** — Description: "I'll specify which files to archive"

If the user chooses "Let me choose", ask a follow-up multiSelect question listing each file as an option.

### Step 3: Execute Archive

Run the archive script with the selected files:

```bash
bash "${CLAUDE_PLUGIN_ROOT}/scripts/archive-plans.sh" {{args}} [FILES...]
```

Pass `--all` if the user confirmed all files. Pass `--dir=PATH` if the user specified a custom directory.

### Step 4: Update WORKFLOW_STATE.md

After archiving, read `WORKFLOW_STATE.md` in the project root.

**If the archived files include the active plan** (the file listed in `Plan:` under `## Active Phase`):
1. Move the active phase entry to `## Completed Phases` with its description and the latest commit hash
2. Reset the `## Active Phase` section to idle:
   ```
   ## Active Phase

   Phase: idle
   Plan: none
   ```

**Otherwise**, if any archived files are referenced elsewhere in WORKFLOW_STATE.md, annotate them with `(archived)`.

### Step 5: Report

Display a summary:
- How many files were archived
- The archive destination path
- Whether the active phase was reset
- Any WORKFLOW_STATE.md updates made

## Error Handling

- If no MASTER_PLAN files exist, say so clearly
- If the archive directory can't be created, report the error and suggest the user check permissions
- If a file collision occurs in the archive directory, the script auto-appends a `-N` suffix

## Example

```
/archive
```

Output:
```
Found 3 MASTER_PLAN files:
  MASTER_PLAN1.md
  MASTER_PLAN2.md
  MASTER_PLAN3.md

Archived to ~/archive/2026-02-12/
Active phase (MASTER_PLAN3.md) moved to Completed Phases and reset to idle.
```
