← Catalog

@jamiefutch/pi-backup

Pi package: Pi backup/restore scripts and TUI extension. Back up and restore all Pi config, skills, extensions, and memory; /pi-backup interactive manager.

Extension

Install

Install with PiG

pig install npm:@jamiefutch/pi-backup

Install with Pi

pi install npm:@jamiefutch/pi-backup
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./extensions"
  ]
}

README

Written by the package's publisher, shown as published in version 1.2.0 (README.md). PiG does not review it.

pi-backup — Pi Backup & Restore Utilities

Complete, cross-platform backup/restore for the Pi coding agent. Backs up everything needed to restore to an equivalent state after a clean reinstall, with an interactive /pi-backup manager and 7-Zip-first archive support.

Installation

# From npm (when published)
pi install npm:@jamiefutch/pi-backup@latest

# From git
pi install git:github.com/jamiefutch/pi-backup@master

# From local path
pi install /path/to/pi-backup

Manual (add to settings.json)

{
  "packages": ["npm:@jamiefutch/pi-backup"]
}

Then restart Pi or run /reload.

Developer documentation

Repository-specific agent guidance is available in:

  • .pi/agents.md — pi-backup project conventions and safety rules
  • .pi/agents/pi-development-expert.md — detailed Pi extension, package, SDK, TUI, provider, and resource-development guidance

Scripts

ScriptPurpose
backup-pi.sh / backup-pi.ps1Creates timestamped backup of all Pi config, skills, extensions, memory
pi-clean-reinstall.sh / pi-clean-reinstall.ps1Nuclear reinstall — wipes ~/.pi, uninstalls/reinstalls Pi (dangerous)
restore-pi.sh / restore-pi.ps1Restores backup after fresh Pi install
PlatformExtensions
macOS / Linux (bash)backup-pi.sh, restore-pi.sh, pi-clean-reinstall.sh
Windows (PowerShell)backup-pi.ps1, restore-pi.ps1, pi-clean-reinstall.ps1 (requires PowerShell 7 / pwsh)

Archive format and compression

External backups are compressed automatically:

  • If 7zz, 7z, or 7za is available on macOS, Linux, or Windows, Pi Backup uses 7-Zip and creates a .7z archive.
  • Otherwise it falls back to native platform tools and creates a .zip archive (zip/unzip on macOS/Linux, Compress-Archive/Expand-Archive on Windows).
  • Restoring a .7z archive requires 7-Zip to be installed and available on PATH.
  • The TUI uses the same preference for creating, restoring, copying, and viewing manifests.
  • Internal backups remain uncompressed directories for fast rollback.

The executable may be named 7zz, 7z, or 7za.

Usage

TUI Extension (after package install)

/pi-backup

Opens the Pi Backup Manager interactive menu:

Pi Backup Manager — 8 backups (1 internal, 7 external)
External dir: ~/pi-backups

 → 📦 Create internal backup  (~/.pi/backups/  — quick rollback)
   💾 Create external backup  (survives reinstall)
   📋 List all backups
   ⚙️  Configure external backup directory
   ❓ Help
   ← Exit
Main Menu Options
OptionDescriptionLocation
📦 Create internal backupFast uncompressed backup for quick rollback during normal use~/.pi/backups/
💾 Create external backupCompressed archive for disaster recovery — survives clean reinstallresolved per priority chain
📋 List all backupsBrowse, restore, copy, delete, or view manifests of all backupsBoth locations
⚙️ Configure external backup directorySet or reset the settings.json externalBackupDir valuesettings.json
❓ HelpFull documentation on backup locations, what's backed up, restore process—
← ExitClose the backup manager—
Backup List View
Backups (8 total)

 → 📁 pi-backup-20260812-112053  │  2026-08-12 11:20:53  │  1.6 MB  │  347 files
   💾 pi-backup-20260812-112019.7z  │  2026-08-12 11:20:19  │  1.6 MB  │  1 files • compressed
   💾 pi-backup-20260812-095402.zip  │  2026-08-12 09:54:02  │  1.6 MB  │  1 files • compressed
   ...
   🔄 Refresh
   ← Back

Columns: Location icon • Name • Timestamp • Size • File count • Compression status

Backup Actions (after selecting a backup)
Backup: pi-backup-20260812-112019.7z

 → 🔄 Restore this backup  (2026-08-12 11:20:19)
   📋 Copy to internal  (~/.pi/backups/)
   📄 View manifest
   🗑️ Delete
   ← Back
ActionDescription
🔄 RestoreAfter confirmation, shows (and copies, where possible) the exact restore command to run after you exit Pi. The TUI never restores in-process, because the running Pi owns the files being replaced
📋 Copy to internalExtracts/copies an external backup into ~/.pi/backups/ as an uncompressed directory (external only)
📄 View manifestOpens MANIFEST.txt in editor (extracts from compressed archives)
🗑️ DeletePermanently removes backup (requires confirmation)
Backup Location Summary
LocationPathSurvives Clean Reinstall?Format
Internal~/.pi/backups/❌ NO (wiped by rm -rf ~/.pi)Uncompressed dirs
External~/pi-backups/✅ YESCompressed (.7z/.zip)

Key point: Always create an external backup before a clean reinstall. Internal backups are for quick rollbacks during normal use only.

Command Line (scripts directly)

1. Backup (before reinstall)
./backup-pi.sh
2. Clean Reinstall
./pi-clean-reinstall.sh

The clean reinstall is rollback-safe: it checks that a backup exists in BACKUP_ROOT (and asks for an extra no backup confirmation if not), moves ~/.pi to ~/.pi.pre-reinstall-<timestamp>, uninstalls and reinstalls Pi, verifies pi --version, and only then deletes the moved copy. If any step fails, the original ~/.pi is moved back. Set KEEP_OLD=1 to keep the moved-aside copy.

3. Restore a directory, .7z archive, or .zip archive
./restore-pi.sh ~/pi-backups/pi-backup-20260811-143000.7z

Exit Pi first: the script warns (but does not block) if it detects a running Pi process, because files restored under a running Pi can be overwritten when it exits. Restore asks for confirmation; it needs an interactive terminal and otherwise stops with a message. For scripted use, set PI_BACKUP_ASSUME_YES=1:

PI_BACKUP_ASSUME_YES=1 ./restore-pi.sh ~/pi-backups/pi-backup-20260811-143000.7z

Temporary extraction directories are always removed, including when you answer n, the archive is damaged, or a copy fails part-way.

4. Reinstall npm deps + verify
cd ~/.pi/agent && npm install  # or bun install
pi --version
/ctx-doctor
/loop-police-status
/scoped-memory-status

Windows (PowerShell)

On Windows, use the .ps1 scripts from PowerShell 7 (pwsh). The backup data directory defaults to ~/pi-backups.

# 1. Backup (before reinstall)
.\backup-pi.ps1

# 2. Clean Reinstall (nuclear - wipes ~/.pi, uninstalls/reinstalls Pi)
.\pi-clean-reinstall.ps1

# 3. Restore
.\restore-pi.ps1 ~\pi-backups\pi-backup-20260811-143000

# 4. Reinstall npm deps + verify
cd ~\.pi\agent; npm install
pi --version
/ctx-doctor

Customize locations in PowerShell with environment variables (same names as the bash scripts):

$env:PI_ROOT='C:\Users\you\.pi'; $env:BACKUP_ROOT='D:\pi-backups'; .\backup-pi.ps1

Note: If the Execution Policy blocks scripts, run once: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned. With 7-Zip (7zz, 7z, or 7za) on PATH, backups are created as .7z; otherwise PowerShell's built-in Compress-Archive creates .zip files. restore-pi.ps1 prefers 7-Zip when available and uses Expand-Archive for ZIP fallback.

What Gets Backed Up

The list lives in one file, backup-manifest.txt, read by all four scripts; a test keeps this table in sync with it.

CategoryPaths
Core configsettings.json, auth.json, models.json, trust.json, keybindings.json, pix.json, optimizer.json, lmstudio.json.bak, hermes-memory-config.json, pi.code-workspace
Extension configspi-hermes-memory-cleanup/scoped-memory.json, loop-police.json, pi-rtk/config.json, context-mode/config.json, pi-timeout/config.json, pi-context-viewer/config.json, pix-optimizer/config.json, pi-nvidia-nim/config.json
Global skills~/.pi/agent/skills/
Project skills & memory~/.pi/agent/projects-memory/<project>/
Local extension source$LOCAL_EXT_ROOT/pi-timeout/, pi-chunk/, pi-hermes-memory-cleanup/, pi-context-docs/ (defaults to ~/projects/; node_modules, dist, build, .git, coverage and *.log are skipped)
npm manifestspackage.json, package-lock.json, npm-shrinkwrap.json, pnpm-lock.yaml from ~/.pi/agent/npm/ (never node_modules)
Hermes memory (active)MEMORY.md, USER.md, failures.md, retired-failures.md, retired-memory.md
Memory database & skillssessions.db in ~/.pi/agent/pi-hermes-memory/ (copied with sqlite3 .backup, so WAL changes are included), ~/.pi/agent/pi-hermes-memory/skills/, .skills-migrated-to-extension-storage
Extension statepi-subagents/last-seen-version.json, anti-stall.json, crashes.json, run-history.jsonl, models-store.json, ~/.pi/agent/missions/, ~/.pi/agent/extensions/
Optional: sessions~/.pi/agent/sessions/ (151 MB or more). Set PI_BACKUP_INCLUDE_SESSIONS=1
Optional: git packages~/.pi/agent/git/ (cloned git packages). Set PI_BACKUP_INCLUDE_GIT=1
Optional: bin~/.pi/agent/bin/ (bundled binaries such as fd). Set PI_BACKUP_INCLUDE_BIN=1
Cleanup backupsLast 5 timestamped (20*) directories from ~/.pi/agent/hermes-cleanup/

Example output of ./backup-pi.sh (captured from a real run, abridged):

[INFO] ════════════════════════════════════════════════════════════
[INFO]   Pi Complete Backup
[INFO] ════════════════════════════════════════════════════════════
[INFO] Source:      ~/.pi
[INFO] Destination: ~/pi-backups/pi-backup-20261122-011819

[INFO] 1/8  Core configuration files...
[OK]     settings.json
[OK]     auth.json
[WARN]   auth.json holds your API credentials and is included in this backup.
[WARN]   Keep the backup private; set PI_BACKUP_EXCLUDE_AUTH=1 to leave it out.
[OK]     models.json
[WARN]   keybindings.json — not found, skipping
...
[INFO] 8/8  Recent hermes-cleanup backups (last 5)...
[OK]     20260107/
...
[INFO] 9/9  Compressing backup (zip)...
[OK]     ~/pi-backups/pi-backup-20261122-011819.zip

[INFO] ════════════════════════════════════════════════════════════
[OK]   Backup complete!
[INFO] Archive:  ~/pi-backups/pi-backup-20261122-011819.zip
[INFO] Size:     12K

[INFO] To restore after reinstall:
[INFO]   ./restore-pi.sh ~/pi-backups/pi-backup-20261122-011819.zip

An internal backup (KEEP_UNCOMPRESSED=1, what the TUI's Create internal backup runs) skips the compression step and prints Staging: <directory> instead of Archive:.

What Does NOT Get Backed Up (Regeneratable)

ExcludedWhy
~/.pi/agent/sessions/Session history — regenerated. Include it with PI_BACKUP_INCLUDE_SESSIONS=1
~/.pi/agent/context-mode/kb.sqliteKnowledge base — rebuilt from indexed sources
~/.pi/agent/npm/node_modules/Dependencies — reinstalled via npm install
~/.pi/agent/loop-police-detections.jsonlDetection logs — regenerated
~/.pi/agent/.pi-hermes-locks.sqlite*Lock files — recreated

Security

Backups contain auth.json, which holds your API keys and tokens. Treat every backup (directory, .zip, .7z) as a secret.

  • Backups are created private to your user: umask 077 on macOS/Linux, auth.json is chmod 600, and archives are 600 (on Windows, rely on your profile folder's ACLs and avoid shared drives).
  • Set PI_BACKUP_EXCLUDE_AUTH=1 to leave auth.json out entirely (you will need to sign in to providers again after a restore).
  • Restore sets a restored auth.json back to 600.
  • There is intentionally no built-in encryption: passing a password to 7z on the command line leaks it through ps. If you need encryption, encrypt the finished archive yourself (for example with age or gpg) or store backups on an encrypted volume.
  • Never commit or share backups. They are also in .gitignore (*.7z, *.zip, backups/).

Backup Location

~/pi-backups/
├── pi-backup-20260811-143000/
│   ├── MANIFEST.txt
│   ├── settings.json
│   ├── auth.json
│   ├── models.json
│   ├── skills/
│   ├── projects-memory/
│   ├── local-extensions/
│   ├── npm-manifests/
│   ├── pi-hermes-memory/
│   └── hermes-cleanup/
└── pi-backup-20260811-150000/
    ...

Each backup is self-contained with a MANIFEST.txt listing all files.


External Backup Directory Configuration

The external backup location is resolved in this priority order:

  1. BACKUP_ROOT environment variable (highest priority)
  2. externalBackupDir key in ~/.pi/agent/settings.json
  3. Default: ~/pi-backups/
// ~/.pi/agent/settings.json
{
  "externalBackupDir": "/custom/path/to/backups"
}

In the TUI

Use the ⚙️ Configure external backup directory option in /pi-backup to set or reset the settings.json value:

  • 📝 Change directory — prompt to type a path, saved to settings.json
  • 🔄 Reset to default — removes the settings.json value, falls back to env var / default

If settings.json is corrupt (not valid JSON), the manager never overwrites it: read-only screens fall back to the default directory with one warning, and changes are refused with an error. Successful saves are written atomically and keep the previous file as settings.json.bak-<timestamp> (last 3 kept).

When the prompt appears

The configure prompt only appears when creating an external backup if both of these are true:

  • No BACKUP_ROOT env var and no externalBackupDir in settings.json, AND
  • The default external directory is empty or missing

If the default directory already contains backups, it is treated as configured and used directly with no prompt. Restore never prompts (it uses the selected backup's direct path).


Environment Variables

VariableDefaultPurpose
PI_ROOT~/.piOverride Pi root directory
BACKUP_ROOT~/pi-backupsOverride backup destination (highest priority for the TUI too)
LOCAL_EXT_ROOT~/projectsOverride the directory containing local extension source repositories
KEEP_UNCOMPRESSED01 makes a plain, uncompressed staging directory and skips compression (no zip/7-Zip needed); the TUI sets this for internal backups. With 0 the staging directory is compressed and removed
PI_BACKUP_ASSUME_YESunsetSet to 1 to skip the restore confirmation prompt (scripted use). Without it, restore needs an interactive terminal and exits with a clear message otherwise
PI_BACKUP_EXCLUDE_AUTHunsetSet to 1 to leave auth.json (API credentials) out of the backup
PI_BACKUP_INCLUDE_SESSIONSunsetSet to 1 to include ~/.pi/agent/sessions/ (session history; large)
PI_BACKUP_INCLUDE_GITunsetSet to 1 to include ~/.pi/agent/git/ (cloned git packages)
PI_BACKUP_INCLUDE_BINunsetSet to 1 to include ~/.pi/agent/bin/ (bundled binaries)
KEEP_OLDunsetSet to 1 to keep ~/.pi.pre-reinstall-<timestamp> after a successful clean reinstall
PKG_MANAGERbunPackage manager used by the clean-reinstall scripts (bun, npm, etc.)
# Custom locations
PI_ROOT=/custom/.pi BACKUP_ROOT=/mnt/backups ./backup-pi.sh

# Include session history and cloned git packages
PI_BACKUP_INCLUDE_SESSIONS=1 PI_BACKUP_INCLUDE_GIT=1 ./backup-pi.sh

Automation (Cron)

# Daily backup at 3 AM
0 3 * * * ./backup-pi.sh >> ~/pi-backup.log 2>&1

# Keep last 30 backups
0 4 * * * find ~/pi-backups -maxdepth 1 -type d -name 'pi-backup-*' -mtime +30 -exec rm -rf {} \;

Troubleshooting

IssueFix
"Permission denied"chmod +x backup-pi.sh restore-pi.sh
"npm install fails"Check Node.js version (need ≥22), try bun install
"Skills not loading"Verify settings.json has correct packages paths after restore
"Models not found"Check models.json restored correctly, restart Pi
"Auth failed"Verify auth.json restored, API keys valid (it is absent if the backup was made with PI_BACKUP_EXCLUDE_AUTH=1)
Restore says "Cannot read a confirmation"stdin is not a terminal (cron, CI, pipe). Run it in a terminal or set PI_BACKUP_ASSUME_YES=1
Backup says "Compression ... failed"The staging directory is kept (it is intact). Fix 7-Zip/zip and re-run, or restore directly from the staging directory
TUI says settings.json could not be parsedThe file is never overwritten. Fix the JSON (or delete the file) and retry; settings.json.bak-* copies are kept from earlier saves

Manual Verify Checklist After Restore

  • pi --version shows correct version
  • /ctx-doctor shows all checks pass
  • /loop-police-status shows config loaded
  • /scoped-memory-status shows enabled + last injection stats
  • /memory-search "test" returns results
  • /context-stats shows context breakdown
  • /nim-status connects (if NVIDIA configured)
  • Local extensions load (check settings.json paths)
  • Run a simple task to verify end-to-end

License

MIT License

Copyright (c) 2025 Jamie Futch

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

See the LICENSE file for the full license text.