This article follows the official documentation. We haven’t tested this tool for a hands-on review.
When a coding agent edits files through a shell, restic can save a recoverable copy of the working directory before a risky change. Restic is a command-line backup tool: it stores files in a repository and records each backup as a snapshot, a record of the files backed up at a particular time. The agent runs restic commands directly; restic does not automatically track agent edits or roll them back.
A local repository makes a useful starting point because it keeps the example’s data on the same machine. Restic also supports remote storage. To use it, you need the storage provider's credentials, or access information, as well as the repository password. The commands below follow the official restic documentation; they have not been installed or tested for this article.
When a checkpoint helps
Ask an agent to create a snapshot before a broad refactor, generated-code update, or other change that could be hard to undo. Restic backs up files and directories, including work that Git has not committed, if those files are inside the selected directory. It does not capture an agent’s conversation or the state of a running service.
Restic deduplicates data: when it backs up unchanged files again, it reuses data already stored in the repository. You can take repeated snapshots to track workspace changes without storing the same data again. The first backup still needs to read the selected files. See the backup documentation for how snapshots and deduplication work.
Set up a local repository
Install restic using the instructions for your operating system in the official installation documentation. The example uses a repository in /tmp, so treat it as a disposable demonstration rather than durable backup storage.
Restic encrypts repository data using a password. Create a password file outside the agent prompt and restrict access to it. Replace /secure/path/restic-password with its actual path. The repository and password file are local; no network call is needed for this example.
export RESTIC_REPOSITORY=/tmp/restic-agent-demo
export RESTIC_PASSWORD_FILE=/secure/path/restic-password
restic init
restic backup ./project
restic init creates the repository. restic backup ./project stores a snapshot of the project directory. Both commands write to local disk. Keep the password file available somewhere separate from the repository: without the password, restic cannot decrypt the backup. The repository setup documentation covers repository passwords and configuration.
For remote repositories, restic also needs the storage provider’s credentials. Configure those outside the agent’s prompt, using the method documented for that backend. Give the shell process only the access it needs, because an agent running as the same user can read files and environment variables that user can access.
Inspect and restore a snapshot
After the backup, list snapshots as JSON:
restic snapshots --json
The command reads repository metadata and returns snapshot information, including IDs and backup paths, in a format software can read. An agent can use the returned snapshot ID to refer to a specific checkpoint. The scripting documentation describes JSON output for scripting; avoid having an agent assume a snapshot ID without reading the command’s output.
To restore the newest snapshot into a separate directory, run:
restic restore latest --target /tmp/agent-restore
Restic writes restored files under the target directory. This keeps the example’s recovery separate from the working copy. For an actual recovery, inspect the restored files before copying anything over the project.
Restic also provides restic check to check repository structure. That check reads the repository; it does not prove that the files you need can be restored successfully. Test recovery by restoring files to a separate location and opening or comparing them. The restore documentation describes restore options.
Give the agent a narrow task
A useful prompt names the directory and the checkpoint action, without including a password:
Before changing files under
./project, create a restic snapshot of that directory using the configured repository. Report the snapshot ID, then make the requested refactor. Do not restore or overwrite files unless I ask.
The agent needs shell access to the configured restic command and repository. The prompt should not contain the repository password; configure the password file and any backend credentials outside the prompt. If restic cannot access the repository, the agent should stop before editing rather than treating an uncreated snapshot as a checkpoint.
Restic protects files that it backs up, but a snapshot alone does not confirm that recovery works. Keep the repository password recoverable and test restores separately. For more command-line tools suited to agent shell access, see Awesome CLI.