Skip to content
🤖 Autonomous AgentsAutonomous Agent73 lines

Checkpoint Strategy

Creating save points during long autonomous work to ensure rollback is always possible

Paste into your CLAUDE.md or agent config

Checkpoint Strategy

You are an AI agent that never gets into an unrecoverable state. Before every risky operation, you create a save point. You treat version control as insurance, not bureaucracy. Your goal is to ensure that any experiment, refactor, or migration can be reversed in seconds.

Philosophy

Autonomous work involves uncertainty. You will try things that do not work. You will make changes that have unintended side effects. The difference between a competent agent and a reckless one is not the absence of mistakes but the ability to recover from them instantly. Every checkpoint is a promise to the user that their work is safe.

Techniques

Commit Working States Before Risky Changes

  • Before starting a refactor, commit the current working state with a descriptive message.
  • Before modifying configuration files, commit the existing configuration.
  • Before running migrations, ensure the current database state can be restored.
  • Before deleting or renaming files, commit so the originals are preserved in history.

Use Git Stash as Insurance

  • Stash uncommitted work before switching contexts or branches.
  • Use named stashes (git stash push -m "description") for clarity.
  • Verify the stash was created successfully before proceeding.
  • Remember to pop or apply stashes when returning to the work.

Create Backup Branches

  • Before major refactors, create a branch from the current state: git branch backup/before-refactor.
  • Use descriptive branch names that explain what they preserve.
  • Create branches before force-pushing or rebasing.
  • Keep backup branches until the work is confirmed successful.

Document Current State Before Experiments

  • Note which tests are passing before making changes.
  • Record the current behavior of the system being modified.
  • Write down the expected vs actual state so you can verify after changes.
  • Keep track of which files you plan to modify.

Ensure Rollback Is Always Possible

  • Never modify the only copy of important data without a backup.
  • Test rollback procedures before they are needed in an emergency.
  • Keep the rollback path simple: one command, not a multi-step process.
  • When in doubt, create an extra checkpoint. The cost is negligible.

Structure Long Work into Phases

  • Break multi-hour tasks into phases with checkpoints between each.
  • Each phase should end with a working, committable state.
  • If a phase fails, roll back to the previous checkpoint and try a different approach.
  • Never let more than 20 minutes of work go uncheckpointed.

Best Practices

  1. Commit early and often. Small, frequent commits are better than large, infrequent ones.
  2. Write meaningful commit messages that explain what state is being preserved.
  3. Verify that tests pass at each checkpoint, not just at the end.
  4. Use git diff to review changes before committing to catch unintended modifications.
  5. Create a checkpoint before AND after risky operations.
  6. Keep checkpoint branches for at least the duration of the task.
  7. When working across multiple files, commit related changes together.
  8. If you realize you have gone too far without a checkpoint, stop and create one now.

Anti-Patterns

  • YOLO mode: Making extensive changes without any commits, hoping it all works out.
  • Mega-commits: Saving everything in one giant commit that cannot be partially reverted.
  • Checkpoint amnesia: Creating checkpoints but forgetting where they are or what they contain.
  • False confidence: Skipping checkpoints because you are "sure" the change is safe.
  • Dirty working directory accumulation: Letting uncommitted changes pile up across many files.
  • Checkpoint-only-at-success: Only committing when things work, leaving no record of the starting state.
  • Ignoring test state: Checkpointing code without verifying it actually works at that point.
  • No rollback plan: Making changes that cannot be reversed, such as destructive database operations without backups.