Skip to content

Latest commit

 

History

History
371 lines (283 loc) · 10.8 KB

usage.md

File metadata and controls

371 lines (283 loc) · 10.8 KB

CLI Usage

Commands

varn init

Initialize Varn in a directory.

varn init              # Initialize in current directory
varn init /path/to/dir # Initialize in a specific directory
varn init --gitignore  # Also add .varn/ to the root .gitignore

Creates a .varn/ directory with storage layout and config. Does not touch any existing files.

If the directory is inside a git repository, Varn also creates .varn/.gitignore containing *, which makes Git ignore the entire store. This protects against a blind git add -A staging tens of thousands of content objects. Nothing outside .varn/ is modified.

With --gitignore, Varn additionally appends .varn/ to the enclosing repository's root .gitignore (creating the file if it does not exist). The entry is not duplicated if a recognized spelling (.varn, .varn/, /.varn, /.varn/) is already present. The flag fails with an actionable error if the directory is not inside a git repository.

If the store is not excluded from git (for example, a store created by an older Varn version), varn checkpoint automatically recreates the store-level guard before scanning. Running varn migrate also backfills the guard for stores that are not checkpointed immediately.

varn checkpoint

Capture the current filesystem state.

varn checkpoint "before agent task"

A checkpoint includes:

  • Unique ID (first 12 hex chars of a SHA-256 content hash)
  • Timestamp
  • Human-readable description
  • Root path
  • Full filesystem state (file paths, metadata, content hashes)

File contents are stored in the content-addressed object store with deduplication. Checkpointing the same state twice is a no-op (idempotent). A file that cannot be read and hashed (for example, one locked by another process) is omitted from that checkpoint and reported in warnings; Varn never emits an unrestorable hash: null file entry.

Incremental scanning: on each checkpoint, Varn loads .varn/index/scan_cache.json and reuses cached content hashes for files whose size and full nanosecond mtime haven't changed. The cache is saved after each scan, so warm checkpoints do not re-read unchanged content already present in the object store.

varn list

Display available checkpoints.

varn list

Output:

ID             TIME                 DESCRIPTION
a91f3c2b4d5e   2026-08-19 20:14    before agent task
b72c1a3e5f7d   2026-08-19 20:27    after agent task

varn delete

Delete checkpoints by ID, or apply a retention policy.

varn delete a91f                        # Delete one checkpoint (prompts)
varn delete a91f --yes                  # Delete without prompting
varn delete --keep-last 10              # Keep the 10 newest, delete older
varn delete --older-than 30d            # Delete checkpoints older than 30 days
varn delete --safety-only --keep-last 3 # Prune old safety checkpoints
varn delete --keep-last 5 --dry-run     # Preview a retention policy

Deleting a checkpoint removes its snapshot; the content objects it referenced stay in the store until the next varn gc reclaims them. A delete followed by gc is what actually frees disk space.

Retention flags combine as an AND: a checkpoint is deleted only when it is outside the --keep-last N window AND older than --older-than AGE (within the --safety-only candidate set, when given). Ages are a number plus a unit: d (days), h (hours), m (minutes).

Explicit IDs and retention flags are mutually exclusive. Deletion asks for confirmation (or --yes); in --json mode without --yes, the command reports what would be deleted and exits without deleting.

varn diff

Compare the current state with a checkpoint, or two checkpoints with each other.

varn diff a91f                       # Checkpoint vs current state
varn diff a91f3c2b4d5e               # Use a full checkpoint ID
varn diff a91f b72c                   # Checkpoint vs checkpoint

With two checkpoints, changes are reported from the first to the second: ADDED entries exist in the second but not the first, DELETED the reverse. The current filesystem state is not scanned in this form, so the output does not change while you inspect it.

Output:

ADDED
  src/new_file.rs

MODIFIED
  src/main.rs

DELETED
  old_config.json

varn restore

Restore a checkpoint.

varn restore a91f                          # Interactive (prompts on conflicts)
varn restore a91f --yes                    # Skip confirmation prompts
varn restore a91f --yes --no-safety        # Skip safety checkpoint too

By default, Varn creates a safety checkpoint of the current state before restoring, so a failed or unwanted restore can be undone. Use --no-safety to skip this.

If conflicts are detected (modified or unexpected files), Varn will:

  1. List what will be overwritten or deleted
  2. Ask for confirmation (unless --yes is passed)
  3. Execute the restore
  4. Verify the result matches the checkpoint

varn undo

Undo the last restore by restoring its safety checkpoint.

varn undo              # Interactive (prompts on conflicts)
varn undo --yes        # Skip confirmation prompts
varn undo --no-safety  # Do not create another safety checkpoint first

varn restore captures the pre-restore state as a safety checkpoint (description [safety before restore of <id>]). varn undo finds the newest one and restores it through the same four-phase pipeline as any other restore. The undo itself creates a safety checkpoint of the pre-undo state, so a second varn undo re-does the original restore.

Fails with an error when no safety checkpoint exists (for example, every restore ran with --no-safety).

varn gc

Remove objects from the store that no snapshot references.

varn gc             # Delete unreferenced objects
varn gc --dry-run   # Preview what would be deleted

Safe to run at any time. Objects referenced by any existing snapshot are always preserved.

varn migrate

Migrate the storage format to the current version.

varn migrate             # Run pending migrations
varn migrate --dry-run   # Check if migration is needed

Reports the current and target storage versions. If the repository is already at the current version, no changes are made. If the repository is at a newer version than the installed Varn supports, an error is returned.

varn migrate also backfills the store-level git guard (.varn/.gitignore) for stores created before it existed. --dry-run reports whether the guard would be added without writing anything.

Ignore patterns

Varn reads .varnignore files to exclude paths from checkpoints. The syntax follows gitignore conventions:

# Comments and blank lines are ignored
*.log                    # Match by extension (any depth)
target/                  # Directory-only (trailing slash)
/build                   # Anchored to root (leading slash)
**/cache/                # Match at any depth
!important.log           # Negation (re-include)

Place a .varnignore file at the root of your Varn-managed directory. It is loaded automatically by varn checkpoint and varn diff.

Pattern syntax

Pattern Matches
*.log Any file ending in .log, at any depth
target/ A directory named target (and all its contents)
/build A path named build at the root only
**/cache/ A directory named cache at any depth
!important.log Re-includes a file previously excluded
file[0-9].txt One character from the set 0-9
? Any single character except /

Git coexistence

Varn is designed to coexist with Git in the same directory:

  • varn init creates .varn/.gitignore containing *, so Git ignores the entire store automatically. Nothing outside .varn/ is modified.
  • Varn never reads or writes Git metadata (.git/, index, refs).
  • varn checkpoint skips .varn/ during scans, so checkpointing a git-managed directory does not capture Git's internals.
  • varn checkpoint recreates a missing .varn/.gitignore guard before it scans, so a deleted guard cannot leave the object store exposed to git add -A. varn migrate also backfills the guard.

Global flags

--json

Emit machine-readable JSON output. Works with all commands.

varn --json checkpoint "before changes"
varn --json list
varn --json diff a91f
varn --json restore a91f --yes
varn --json gc --dry-run
varn --json migrate --dry-run

Errors are also emitted as JSON to stderr when --json is active, making Varn suitable for consumption by AI agents and automation tools.

JSON output examples

varn --json checkpoint "test"

{
  "status": "ok",
  "checkpoint_id": "a91f3c2b4d5e",
  "description": "test",
  "created_at": 1787162040,
  "root": "/project",
  "entries": 12,
  "saved": true,
  "warnings": []
}

For an unchanged checkpoint, the same fields are returned with "status": "unchanged" and "saved": false. This is a successful no-op, not an error.

varn --json list

{
  "status": "ok",
  "checkpoints": [
    {
      "id": "a91f3c2b4d5e",
      "description": "before agent task",
      "created_at": 1787162040,
      "entries": 12
    }
  ]
}

varn --json diff a91f

{
  "status": "ok",
  "checkpoint": "a91f3c2b4d5e",
  "changes": [
    { "kind": "added", "path": "src/new_file.rs" },
    { "kind": "modified", "path": "src/main.rs" },
    { "kind": "deleted", "path": "old_config.json" }
  ]
}

varn --json restore a91f --yes

{
  "status": "ok",
  "checkpoint": "a91f3c2b4d5e",
  "safety_checkpoint": "b72c1a3e5f7d",
  "files_written": 3,
  "dirs_created": 1,
  "symlinks_created": 0,
  "deleted": 2,
  "verified": true,
  "warnings": []
}

varn --json gc --dry-run

{
  "status": "ok",
  "dry_run": true,
  "total_objects": 45,
  "referenced_objects": 30,
  "deleted": 15,
  "deleted_hashes": ["aaaa1111", "bbbb2222"]
}

varn --json delete a91f --yes

{
  "status": "ok",
  "dry_run": false,
  "deleted": ["a91f3c2b4d5e"],
  "message": "run 'varn gc' to remove objects no longer referenced by any checkpoint"
}

varn --json diff a91f b72c (checkpoint to checkpoint)

{
  "status": "ok",
  "from": "a91f3c2b4d5e",
  "to": "b72c1a3e5f7d",
  "changes": [
    { "kind": "added", "path": "src/new_file.rs" },
    { "kind": "modified", "path": "src/main.rs" },
    { "kind": "deleted", "path": "old_config.json" }
  ]
}

Error output (stderr)

{
  "status": "error",
  "error": "checkpoint not found: xyz"
}

Checkpoint ID resolution

Checkpoint IDs can be specified by their full ID or any unique prefix:

varn diff a91f           # Prefix match
varn restore a91f3c2b    # Longer prefix
varn delete a91f         # Same resolution for deletes

If a prefix matches multiple checkpoints, Varn reports an ambiguity error.