---
name: cleanup-old-code
description: Update imports, delete old files/directories, and commit with hash tracking after a migration
disable-model-invocation: true
argument-hint: "<path_to_delete> e.g. feed_card_views, variant_screens/feed_details_screen"
---

# Cleanup Old Code After Migration

Delete old code at `$ARGUMENTS` after confirming all external references have been migrated.

## Step 1: Record the current commit hash

```bash
git rev-parse HEAD
```

Save this — it's the last commit that still contains the old files (recovery hash).

## Step 2: Find all external references

Grep for imports of the old path across the entire `lib/` directory:

```bash
# Find all files importing from the old path
grep -r "import.*<old_path>" lib/
```

Separate results into:
- **Self-references** (files inside the directory being deleted) — these are fine
- **External references** (files outside the directory) — these MUST be updated first

## Step 3: Update external imports

For each external reference:
1. Read the file
2. Update the import to point to the new path
3. Verify the new import path exists

## Step 4: Verify before deleting

Run `fvm flutter analyze` on all modified files to confirm zero new errors.

## Step 5: Delete old files

```bash
rm -rf <old_directory>
```

## Step 6: Full analysis

Run `fvm flutter analyze` on the entire project — confirm no new errors.

## Step 7: Commit

Stage all changes and commit with this format:

```
chore: Remove old <component_name> after migration to <new_location>

- Deleted <old_path>/ (<N> files)
- Updated <N> external imports to <new_path>
- Last commit with old files: <hash>

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
```

## Step 8: Update session_status.md

Record in `.claude/memory/session_status.md`:
- What was deleted
- The recovery commit hash
- Updated the "still remaining" lists

## Rules
- ALWAYS record the recovery commit hash BEFORE deleting
- ALWAYS update session_status.md with the hash
- NEVER delete if external references still exist
- Run full `fvm flutter analyze` after deletion to catch anything missed
- One deletion per commit for safe recovery
