/tokenwise:undo — Restore from backup
Find TokenWise backups and restore one.
Steps
Find backups with Bash:
find ~/.claude -maxdepth 3 -name "*.tokenwise-backup-*" 2>/dev/null find . -maxdepth 3 -name "*.tokenwise-backup-*" 2>/dev/nullIf none found:
No TokenWise backups found. Backups are created automatically by /tokenwise:install before any file modification. If you've never run /tokenwise:install, there's nothing to undo. If you removed the backups manually, you'll need to restore from version control or recreate config by hand.If found, print a numbered list:
TokenWise backups found: 1. ~/.claude/CLAUDE.md.tokenwise-backup-20260511-143218 (target: ~/.claude/CLAUDE.md, created <relative time>) 2. ~/.claude/settings.json.tokenwise-backup-20260511-143219 (target: ~/.claude/settings.json, created <relative time>) Restore which? (1-N, or 'all', or 'cancel'):Parse user response:
- Single number → restore that one
all→ restore all backupscancel(or empty) → exit withNo changes made.
For each backup to restore:
- Derive target path: strip the
.tokenwise-backup-<ts>suffix - Confirm:
Restore <target> from <backup>? This will overwrite <target>. [Y/n] - If Y:
- Read current target file (if exists), back it up to
<target>.tokenwise-pre-undo-<ts>(so undo is reversible) - Copy backup over target:
cp <backup> <target> - Verify by reading target — confirm content matches backup
- Read current target file (if exists), back it up to
- If n: skip
- Derive target path: strip the
Optionally delete the consumed backup:
Delete the backup file <backup> now that it has been restored? [Y/n]Print summary:
Undo complete. Restored: <list> Pre-undo backups (in case you want to redo): <list>Remind user: "Restart Claude Code so the original CLAUDE.md / settings.json take effect."
Edge cases
- Multiple backups for the same target file: the user should pick which one. Print them sorted by timestamp descending (newest first).
- Backup file is empty: warn before restoring (
Backup is empty. Restoring will leave <target> empty. Continue?). - Target file no longer exists: that's fine — restore creates it.
Tools
Read, Write, Bash.