# Agent Settings Backup (asb)
[](./LICENSE)
A smart backup tool for AI coding agent configuration folders. Each agent type gets its own git repository, providing full version history and easy restoration.
Quick Install
```bash
curl -fsSL "https://raw.githubusercontent.com/Dicklesworthstone/agent_settings_backup_script/main/install.sh" | bash
```
---
## Features
- **Git-versioned backups**: Every backup is a git commit with full history
- **Multiple agent support**: Claude, Codex, Cursor, Gemini, Cline, Amp, Aider, OpenCode, Factory, Windsurf, and more
- **Efficient syncing**: Uses rsync for incremental backups
- **Easy restoration**: Restore to any point in history
- **Diff support**: See what changed since last backup
- **Restore preview & confirmation**: See changes before restoring
- **Config file support**: Persistent settings in `~/.config/asb/config`
- **Export/import archives**: Move backups between machines
- **Shell completion**: Bash, Zsh, and Fish completions
- **Dry-run mode**: Preview operations without changes
- **Scheduled backups**: Install cron or systemd timers with `asb schedule`
- **Hooks**: Run scripts before/after backup and restore
- **Named tags**: Label important backups for easy reference
- **Backup statistics**: See size, commit count, and activity metrics
- **Auto-discovery**: Scan for new AI coding agents
- **Structured output**: Machine-readable output for all commands (JSON/TOON)
## New in v0.3
- **Backup tags**: Name important backups with `asb tag claude v1.0`
- **Restore from tags**: Use `asb restore claude v1.0` instead of commit hashes
- **Statistics**: View backup stats with `asb stats` and `asb stats `
- **Auto-discovery**: Find new AI agents with `asb discover`
- **Custom agents**: Add discovered agents to your backup rotation
- **Structured output**: All commands support `--json` (and `--format toon`) for machine-readable output
## New in v0.2
- **Dry-run mode**: Preview changes with `--dry-run` or `-n`
- **Restore confirmation**: See exactly what will change before restoring
- **Configuration file**: Persistent settings in `~/.config/asb/config`
- **Export/Import**: Portable archives with `asb export` and `asb import`
- **Shell completion**: Tab completion for bash, zsh, and fish
## Installation
**Or install manually:**
```bash
git clone https://github.com/Dicklesworthstone/agent_settings_backup_script.git
cd agent_settings_backup_script
cp asb ~/.local/bin/
```
**Verify installation:**
```bash
asb version # Should output: asb version 0.3.8
asb help # Shows available commands
```
### Shell Completion
Enable tab completion for commands and agent names:
```bash
# Bash (~/.bashrc)
eval "$(asb completion bash)"
# Zsh (~/.zshrc — place after compinit is loaded)
eval "$(asb completion zsh)"
# Fish (~/.config/fish/config.fish)
asb completion fish | source
```
## Quick Start
```bash
# Initialize backup location
asb init
# Backup all detected agents
asb backup
# Check backup status
asb list
```
## Usage
```bash
asb [options] [args]
Global options:
-n, --dry-run Show what would happen without making changes
-f, --force Skip confirmation prompts (use with caution)
-v, --verbose Show detailed output
--json Output in JSON format (machine-readable)
--format Structured output format (implies JSON output; TOON uses toon_rust `tru`)
Commands:
backup [agents...] Backup agent settings (all if none specified)
restore [commit|tag] Restore agent from backup (commit or tag name)
export [file] Export backup as portable archive
import Import backup from archive
list List all agents and backup status
history Show backup history for an agent
diff Show changes since last backup
verify [agents...] Verify backup integrity (all if none specified)
prune [agents...] [--reinit] Drop data the backup policy excludes from existing backups
tag [name] Tag a backup (--list, --delete supported)
stats [agent] Show backup statistics
discover Scan for new AI agents (--auto, --list)
schedule [options] Set up automated scheduled backups
hooks --list List configured hooks
init Initialize backup location
config [init|show] Manage configuration
completion [bash|zsh|fish] Output shell completion script
help Show help message
version Show version
```
## Supported Agents
| Agent | Config Folder | Description |
|-------|--------------|-------------|
| `claude` | `~/.claude` | Claude Code |
| `codex` | `~/.codex` | OpenAI Codex CLI |
| `cursor` | `~/.cursor` | Cursor |
| `gemini` | `~/.gemini` | Google Gemini |
| `cline` | `~/.cline` | Cline |
| `amp` | `~/.amp` | Amp (Sourcegraph) |
| `aider` | `~/.aider` | Aider |
| `opencode` | `~/.opencode` | OpenCode |
| `factory` | `~/.factory` | Factory Droid |
| `windsurf` | `~/.windsurf` | Windsurf |
| `plandex` | `~/.plandex-home` | Plandex |
| `qwencode` | `~/.qwen` | Qwen Code |
| `amazonq` | `~/.q` | Amazon Q |
## Examples
### Backup Operations
```bash
# Backup all detected agents
asb backup
# Preview backup without changes
asb --dry-run backup
# Backup specific agents
asb backup claude codex
# Backup with verbose output
ASB_VERBOSE=true asb backup
```
### Restore Operations
```bash
# Restore from latest backup
asb restore claude
# Restore from specific commit
asb restore claude abc1234
# Restore without confirmation (scripting)
asb --force restore claude
# Preview restore without changes
asb --dry-run restore claude
# List available commits first
asb history claude
```
### Viewing History
```bash
# Show backup history
asb history claude
# Show last 50 backups
asb history claude 50
# Show changes since last backup
asb diff claude
```
### Tags
```bash
# Tag current backup
asb tag claude v1.0
# Tag with description
asb tag claude before-refactor
# List all tags
asb tag claude --list
# Restore from tag
asb restore claude v1.0
# Delete a tag
asb tag claude --delete v1.0
```
### Statistics
```bash
# Overview of all agents
asb stats
# Detailed stats for one agent
asb stats claude
# JSON output for scripting
asb --json stats
```
### Discovery
```bash
# List newly found agents
asb discover --list
# Interactively add found agents
asb discover
# Auto-add all found agents
asb discover --auto
# JSON output
asb --json discover --list
# TOON output (requires tru)
asb --format toon discover --list
```
### Structured Output (JSON/TOON)
All commands support `--json` for machine-readable output (or `--format toon` for TOON),
ideal for scripting and automation:
```bash
# Backup with JSON output
asb --json backup claude
# {"agent":"claude","name":"Claude Code","status":"success","commit":"abc1234","changes":5}
# Backup all agents
asb --json backup
# {"results":[...],"summary":{"backed_up":3,"skipped":2,"failed":0}}
# Restore with JSON (requires --force for non-interactive)
asb --json --force restore claude
# {"agent":"claude","name":"Claude Code","status":"success","source":"abc1234","destination":"/home/user/.claude"}
# Export with JSON
asb --json export claude
# {"agent":"claude","name":"Claude Code","status":"success","output":"/path/to/backup.tar.gz","size":"1.2M","size_bytes":1258291,"commits":15}
# Import with JSON
asb --json import backup.tar.gz
# {"status":"success","archive":"/path/to/backup.tar.gz","destination":"/home/user/.agent_settings_backups/.claude","agent_folder":".claude"}
# Diff with JSON
asb --json diff claude
# {"agent":"claude","name":"Claude Code","status":"success","has_changes":true,"added":["new_file.json"],"removed":[],"modified":["settings.json"]}
# List agents
asb --json list
# {"agents":[{"name":"claude","display_name":"Claude Code","installed":true,"backup_exists":true},...]}
# History
asb --json history claude
# {"agent":"claude","commits":[{"hash":"abc1234","date":"2024-01-15","message":"Backup..."},...]}
# Stats
asb --json stats claude
# {"agent":"claude","name":"Claude Code","backup_size":"2.5M","commits":42,"last_backup":"2024-01-15 10:30:00"}
```
## Portability
Export backups for transfer between machines:
```bash
asb export claude # Create archive
asb export claude my-backup.tar.gz # Custom filename
asb import claude-backup.tar.gz # Import on new machine
```
Pipe support for remote transfer or encryption:
```bash
asb export claude - | ssh remote "asb import -"
asb export claude - | gpg -c > backup.gpg
```
## Configuration
asb can be configured via config file or environment variables.
### Config File
```bash
asb config init # Create config file
asb config show # View current settings
```
Config file location: `~/.config/asb/config` (XDG-compliant).
Precedence: config file > environment variable > default.
Environment variables:
| Variable | Default | Description |
|----------|---------|-------------|
| `ASB_BACKUP_ROOT` | `~/.agent_settings_backups` | Backup location |
| `ASB_AUTO_COMMIT` | `true` | Auto-commit on backup |
| `ASB_VERBOSE` | `false` | Verbose output |
| `ASB_LOCK_WAIT` | `300` | Seconds a backup, restore, import, tag or prune waits while another asb writes the same agent's backup |
| `ASB_INCLUDE_CREDENTIALS` | `false` | Back up and restore login tokens and API key files too (see [FAQ](#faq)) |
| `ASB_EXCLUDE_PATHS` | empty | Additional literal paths to exclude from every agent, separated by newlines |
### Path Exclusions
Known credential filenames are excluded by default, including `.credentials.json`
and `auth.json` at any depth. Add paths for other private files or directories in
`~/.config/asb/config`:
```bash
# Apply to every built-in and custom agent.
ASB_EXCLUDE_PATHS=$'private/token.txt\nprofiles/work/account.json'
# Add exclusions for one agent. Use its built-in name or custom-agent key.
ASB_AGENT_EXCLUDE_PATHS[claude]=$'mcp/private.env\nlocal accounts'
ASB_AGENT_EXCLUDE_PATHS[work]='account-token.json'
```
`ASB_AGENT_EXCLUDE_PATHS` is an associative array supplied by asb; assign its
entries directly in the config file. The global list can also be set in the
environment for one invocation:
```bash
ASB_EXCLUDE_PATHS=$'private/token.txt\n.env.production' asb backup claude codex
```
Each path is relative to that agent's source directory. For example,
`profiles/work/account.json` excludes that exact path below `~/.claude` for
Claude, and below the mapped profile directory for a custom agent. A directory
entry excludes its entire subtree. Paths are literal: spaces and characters such
as `*`, `?`, and `[` are part of the filename, not wildcard syntax. Use newlines
between entries; blank lines are ignored and a trailing `/` is optional.
Absolute paths, `.` or `..` components, repeated `/`, tabs, carriage returns,
and `.git` or `.gitignore` components are rejected before an operation proceeds.
These lists extend the defaults. Setting `ASB_INCLUDE_CREDENTIALS=true` enables
the built-in credential filenames, but does not override an explicit path
exclusion. Put persistent exclusions in the config file so scheduled backups
load the same policy.
The policy applies before copying, including nested files in the `cp` fallback.
It also governs backup previews, `diff`, Git staging, `prune`, and restoration
from any commit or tag. Restore preserves excluded live files and directories;
it does not replace them with older copies from backup history. A type conflict
that would replace a directory holding excluded data is refused. Restore reads a
filtered snapshot without changing the backup repository's working tree or index.
Exclusions are based on paths, not file contents. A secret embedded in an otherwise
allowed settings file is still backed up; exclude that whole file if needed.
Adding a `.gitignore` rule alone does not prevent copying or protect a file
already tracked by Git. See the [credential FAQ](#faq) for existing backups.
## Hooks
asb can run user-defined scripts before and after backup/restore operations.
Hook directories (created by `asb config init`):
```
~/.config/asb/hooks/
pre-backup.d/ # Run before any backup
post-backup.d/ # Run after successful backup
pre-restore.d/ # Run before any restore
post-restore.d/ # Run after successful restore
```
Rules:
- Hooks run in alphabetical order (e.g., `01-*.sh`, `02-*.sh`)
- Scripts must be executable
- Pre-hook failure aborts the operation
- Post-hook failure logs a warning but continues
Environment variables passed to hooks:
| Variable | Description |
|----------|-------------|
| `ASB_AGENT` | Agent name (e.g., `claude`) |
| `ASB_SOURCE` | Source config path (e.g., `~/.claude`) |
| `ASB_BACKUP_DIR` | Backup directory path |
| `ASB_OPERATION` | `backup` or `restore` |
| `ASB_COMMIT` | Commit hash (post-backup) or restore target |
List active hooks:
```bash
asb hooks --list
```
## Backup Structure
```
~/.agent_settings_backups/
├── README.md
├── .claude/ # Git repo with Claude settings history
│ ├── .git/
│ ├── .gitignore
│ ├── settings.json
│ └── ...
├── .codex/ # Git repo with Codex settings history
│ ├── .git/
│ └── ...
└── ...
```
Each agent folder is a complete git repository. You can:
- `cd ~/.agent_settings_backups/.claude && git log` to see history
- `git diff HEAD~1` to see last changes
- `git checkout ` to view old state
## Automation
### Quick Scheduling (Recommended)
Use the built-in scheduler to install cron jobs or systemd timers:
```bash
# Install daily systemd timer
asb schedule --systemd --interval daily
# Install weekly cron job
asb schedule --cron --interval weekly
# Check status or remove
asb schedule --status
asb schedule --remove --systemd
```
### Cron Job
```bash
# Backup daily at midnight
0 0 * * * /home/user/.local/bin/asb backup >> /var/log/asb.log 2>&1
```
### Systemd Timer
```ini
# ~/.config/systemd/user/asb-backup.timer
[Unit]
Description=Daily agent settings backup
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
```
```ini
# ~/.config/systemd/user/asb-backup.service
[Unit]
Description=Agent Settings Backup
[Service]
Type=oneshot
ExecStart=%h/.local/bin/asb backup
```
```bash
systemctl --user enable asb-backup.timer
systemctl --user start asb-backup.timer
```
## Architecture
```
┌─────────────────────────────────────────────────────────────────┐
│ User Commands │
│ asb backup │ restore │ list │ history │ diff │ export/import │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ asb CLI │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────────────┐ │
│ │ Config │ │ Hooks │ │ Agent │ │ Commands │ │
│ │ Loader │ │ System │ │ Detect │ │ backup/restore/ │ │
│ │ │ │ pre/post │ │ │ │ export/history │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
┌────────────────────┼────────────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ ~/.claude │ │ ~/.codex │ │ ~/.cursor │
│ (source) │ │ (source) │ │ (source) │
└──────────────┘ └──────────────┘ └──────────────┘
│ │ │
│ rsync/cp │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────────────┐
│ ~/.agent_settings_backups/ │
│ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │
│ │ .claude/ │ │ .codex/ │ │ .cursor/ │ ... │
│ │ ┌─────────┐ │ │ ┌─────────┐ │ │ ┌─────────┐ │ │
│ │ │ .git/ │ │ │ │ .git/ │ │ │ │ .git/ │ │ │
│ │ │ (repo) │ │ │ │ (repo) │ │ │ │ (repo) │ │ │
│ │ └─────────┘ │ │ └─────────┘ │ │ └─────────┘ │ │
│ │ settings.json│ │ config.yaml │ │ prefs.json │ │
│ │ ... │ │ ... │ │ ... │ │
│ └───────────────┘ └───────────────┘ └───────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Configuration: ~/.config/asb/
├── config # Settings file
├── custom_agents # User-defined agents
└── hooks/
├── pre-backup.d/ # Run before backup
├── post-backup.d/ # Run after backup
├── pre-restore.d/ # Run before restore
└── post-restore.d/ # Run after restore
```
## Troubleshooting
### Common Issues
**Backup fails with "no changes to commit"**
This is normal behavior when there are no modifications since the last backup. The backup completes successfully; git just doesn't create a new commit for identical content.
**rsync not found**
asb falls back to `cp` if rsync isn't available. For better performance with large configs, install rsync:
```bash
# Ubuntu/Debian
sudo apt install rsync
# macOS
brew install rsync
```
**Permission denied during restore**
Ensure you have write permissions to the agent config folder. If files are owned by root, use sudo or fix permissions:
```bash
sudo chown -R $USER ~/.claude
```
**Git "dubious ownership" error**
This occurs when the backup directory is owned by a different user. Fix ownership or configure git:
```bash
# Fix ownership
chown -R $USER ~/.agent_settings_backups
# Or add safe directory (less secure)
git config --global --add safe.directory ~/.agent_settings_backups/.claude
```
**Schedule not running**
- For cron: Check `crontab -l` and verify the cron daemon is running
- For systemd: Check status with `systemctl --user status asb-backup.timer`
- Check logs: `journalctl --user -u asb-backup.service`
**Export fails with "no backup exists"**
Run `asb backup ` first to create the initial backup before exporting.
**Large backup size**
Certain agents store additional cache files or large binary data. Add their
paths to the agent's exclusions in `~/.config/asb/config` to prevent future
copies and commits:
```bash
ASB_AGENT_EXCLUDE_PATHS[claude]=$'large-cache\nmodels/downloads'
```
Then inspect existing tracked copies with `asb --dry-run prune claude`. A normal
`asb prune claude` removes excluded tracked files in a new commit; old history
still occupies space. See [Path Exclusions](#path-exclusions) and the pruning FAQ
before choosing whether to discard any history.
### Debug Mode
For detailed output, enable verbose mode:
```bash
ASB_VERBOSE=true asb backup claude
```
Or use dry-run to see what would happen without making changes:
```bash
asb --dry-run backup claude
asb --dry-run restore claude
```
### Getting Help
- Check existing issues: [GitHub Issues](https://github.com/Dicklesworthstone/agent_settings_backup_script/issues)
- Report bugs with debug output: `ASB_VERBOSE=true asb 2>&1`
## Requirements
- Bash 4 or later (required). On macOS install it with `brew install bash`; asb finds it even when cron or launchd start it with the system Bash 3.2.
- Git 2.26 or later (required for safe, NUL-delimited path lists when staging or pruning)
- `rsync` (recommended, falls back to `cp`)
- `curl` or `wget` (for installation)
- `sha256sum` or `shasum` (for release verification during installation)
- Perl with its core `Fcntl`, `File::Temp`, `File::Copy`, and `Digest::SHA` modules (for kernel locking and atomic installer publication)
## FAQ
**Q: Can I backup agents that aren't in the default list?**
A: Yes! Use `asb discover` to scan for and add new agents, or manually add them to `~/.config/asb/custom_agents` in `key=folder` format.
**Q: Where are my backups stored?**
A: By default in `~/.agent_settings_backups/`. Each agent has its own subdirectory with full git history. Override with `ASB_BACKUP_ROOT` environment variable.
**Q: How do I restore to a specific point in time?**
A: Run `asb history ` to see commits, then `asb restore ` or use named tags: `asb tag ` then `asb restore `.
**Q: Is rsync required?**
A: No. asb falls back to `cp` if rsync isn't available, though rsync provides more efficient incremental syncing.
**Q: How do I transfer backups between machines?**
A: Use `asb export backup.tar.gz` on the source machine, copy the file, then `asb import backup.tar.gz` on the destination.
**Q: What files are excluded from backups?**
A: asb backs up settings, not session data. Excluded everywhere: logs (`*.log`, rotated `*.log.1`… and `*.log.gz`), caches (`cache/`, `Cache/`, `.cache/`), session transcripts and edit history (`sessions/`, `archived_sessions/`, `file-history/`, `projects/`, `downloads/`, `shell-snapshots/`), SQLite write-ahead sidecars (`*.sqlite-wal`, `*.sqlite-shm`, `*.sqlite3-wal`, `*.sqlite3-shm`, `*.db-wal`, `*.db-shm`), Codex's session databases (`thread_history_*.sqlite`, `logs_*.sqlite`, `db-backups/`), and `node_modules/` (installed npm packages; `package.json` is kept). Excluded only at the top of an agent's folder: `tmp/` (Gemini CLI keeps per-project chats and logs there), Antigravity's `antigravity-cli/conversations/` and `antigravity-cli/brain/` under `~/.gemini`, and the server binaries Codex downloads for itself (`packages/app-server-daemon/`, `plugins/.plugin-appserver/`). Per agent: OpenCode's and Factory's `bin/` (their own installed binaries), Claude Code's `jobs/` (background-job state and scratch), and Codex's `computer-use/` (the macOS app it downloads). A `bin/` you keep in `~/.claude` is still backed up. Restore never deletes any of these from the live folder.
**Q: Are my login tokens and API keys backed up?**
A: Known credential files are excluded by default at any depth, for built-in and
custom agents alike: `.credentials.json` (Claude Code on Linux and WSL),
`auth.json` (Codex CLI), `oauth_creds.json` and `oauth_credentials.json` (Gemini
CLI, Qwen Code), `mcp-oauth-tokens.json` (Gemini CLI's MCP logins),
`application_default_credentials.json` (Google Cloud), `.env`, `*.keychain` and
`*.keychain-db`. The rule covers rsync and the `cp` fallback, and
`asb backup --dry-run` lists skipped credential paths without displaying their
contents. Restore preserves live credential files and does not restore their
older versions; when the chosen backup holds one, restore names it as not
restored. API keys embedded in an allowed settings file, such as an MCP
server's `env` block in `settings.json`, remain part of that file and are backed
up. Use [Path Exclusions](#path-exclusions) to exclude additional files or
directories. To deliberately include the default credential filenames, set
`ASB_INCLUDE_CREDENTIALS=true`; explicitly configured exclusions still apply.
Backups made by asb 0.3.6 or earlier may already track these files. Normal backup
leaves their existing committed versions unchanged and warns about them. It
unstages changes to excluded files, including newly staged credentials, without
removing their local copies. It does not rewrite existing commits. To remove
previously tracked excluded files from the current backup, first inspect
`asb --dry-run prune `, then run `asb prune ` and confirm. Prune
commits only the excluded deletions and leaves unrelated staged settings alone;
it refuses to discard a locally modified excluded file. Earlier commits and
exports can still contain the credentials. History is discarded only if you
explicitly request `asb prune --reinit` (see below). Rotate or revoke a
credential if a backup containing it has been exposed.
**Q: My backup folder is huge. How do I shrink it?**
A: Backups made before an exclusion existed still contain that data, and every earlier commit keeps its copies (re-committing a multi-GB database every night grows `.git` by gigabytes). `asb prune --dry-run` shows what the current policy excludes; `asb prune ` removes it in a new commit, which stops it being carried forward. To actually free the space, `asb prune --reinit` also resets that backup's history to a single commit and garbage-collects. That drops every earlier commit and tag, so `asb export` first if you need them. Both steps ask for confirmation unless you pass `--force`.
**Q: Can I run backups automatically?**
A: Yes! Use `asb schedule --systemd --interval daily` for systemd timers or `asb schedule --cron --interval weekly` for cron jobs.
**Q: How do I verify my backups are working?**
A: Run `asb verify ` to check backup integrity, or `asb verify` to check all agents.
## License
MIT License (with OpenAI/Anthropic Rider). See [LICENSE](LICENSE).
## Related Projects
- [repo_updater](https://github.com/Dicklesworthstone/repo_updater) - Multi-repo management tool
- [coding_agent_session_search (cass)](https://github.com/Dicklesworthstone/coding_agent_session_search) - Search agent session histories
- [mcp_agent_mail](https://github.com/Dicklesworthstone/mcp_agent_mail) - Agent coordination via MCP