How to Use IOSM CLI Checkpoints Before a Risky Refactor
A checkpoint should be created before the risky action, not after the agent has already made the risk difficult to see.
That sounds obvious. In practice, AI-assisted refactoring often starts with a chat instruction and an optimistic Git diff. The conversation remembers the intention. Git may preserve committed history. Neither one necessarily gives me a named engineering moment that binds the agent's reasoning to the exact working tree—including uncommitted and untracked files.
IOSM CLI's /checkpoint and /rollback commands are useful because they join those two state planes. A checkpoint labels a point in the session tree and creates a filesystem snapshot. A rollback navigates the session back to that point and restores the associated files. This is not a replacement for Git, tests, or an IOSM improvement cycle. It is a short recovery boundary around exploratory work.
The smallest useful workflow
I use a checkpoint when the next instruction may change several files, when the refactor has more than one plausible design, or when validation is expensive enough that reverting by hand would be error-prone.
$ iosm
> Inspect the authentication boundary and propose the smallest safe refactor.
/checkpoint before-auth-refactor
> Apply the selected refactor. Do not change public API behavior.
The command accepts an optional name. A meaningful name is better than the generated cp-1 because recovery usually happens after context has become noisy.
/checkpoint list
/rollback before-auth-refactor
/checkpoint list shows named checkpoints newest-first. /rollback without an argument selects the latest checkpoint; it can also select by name or displayed index.
This gives the operator a compact transaction:
| Step | State being protected | Evidence to inspect |
|---|---|---|
| inspect | current repository and constraints | agent analysis, Git status |
| checkpoint | session position plus working files | checkpoint name and snapshot path |
| change | candidate refactor | diff, tests, static checks |
| decide | keep or restore | validation results |
| rollback | previous session and filesystem state | restored diff/status, rerun checks |
The checkpoint does not prove that the original state was correct. It proves only that IOSM CLI can return to the captured state.
What the implementation actually captures
At the inspected repository revision 6cb971ca9c23266d83bb86597c381dd83b2ace0d, IOSM CLI detects whether the current directory is inside a Git worktree. In a Git project, the snapshot file set comes from:
git ls-files -co --exclude-standard -z
That includes tracked and untracked, non-ignored files. Outside Git, the implementation walks regular files recursively. Snapshot contents and metadata are stored below .iosm/checkpoints/files/; the checkpoint subtree excludes itself to prevent recursive copies. The current implementation retains the newest 20 filesystem snapshots.
This detail matters. A checkpoint can preserve an uncommitted source file that a commit cannot yet represent. It does not include ignored files in a Git worktree, so it should not be treated as a database backup, secret-store backup, or complete machine image.
Rollback is also intentionally concrete. The implementation compares the current file set with the snapshot, removes files that did not exist at checkpoint time, and then copies the captured files back. The corresponding session operation moves the conversation tree to the checkpoint target. Recovery therefore changes both what the agent sees and what exists in the workspace.
That coupling is the mechanism I care about. Restoring files while leaving the agent after the failed attempt invites stale assumptions. Restoring the conversation while leaving modified files creates the opposite mismatch. A useful checkpoint returns both sides to one named boundary.
A refactor drill, not a magic undo button
Suppose I want an agent to split a large authorization module. I would make the recovery condition explicit before execution:
> Baseline:
> - npm test passes
> - npm run typecheck passes
> - public authorization API must not change
> - no new production dependency
/checkpoint before-auth-split
> Split policy evaluation from request adaptation.
> Stop if the public API changes or either baseline command fails.
After the patch:
npm test
npm run typecheck
git diff --check
git status --short
If the candidate fails the declared boundary, I can inspect the failure and then run:
/rollback before-auth-split
I still rerun the baseline checks after rollback. File restoration is an operation; restored correctness is a conclusion that needs evidence.
This is where the workflow differs from blindly running git reset --hard. The named checkpoint preserves untracked project files included by the snapshot, links the restore point to the session history, and avoids pretending that every working-tree change belongs to Git history. It also avoids using destructive Git commands as a generic escape hatch.
Where checkpoints stop
There are hard boundaries:
- External effects are outside the filesystem snapshot. A sent message, deployed container, database write, payment, or API mutation is not undone by
/rollback. - Ignored files are not captured in Git mode. That is usually correct for dependencies and secrets, but it means the snapshot is deliberately incomplete.
- Concurrent writers can invalidate the boundary. If another process changes the workspace after the snapshot, a rollback may remove files created later.
- A checkpoint is local operational state. It is not a durable release artifact or a substitute for remote version control and backups.
- Rollback needs verification. Tests, type checks, schema checks, and service probes remain authoritative.
For external side effects, use explicit effect identities and compensation rules rather than pretending a filesystem restore can reverse the world. The broader distinction is covered in Retry, Resume, Roll Back, or Compensate?. For deterministic artifact checks in a delivery pipeline, see How to Validate IOSM Artifacts in CI.
The rule I keep
Before a risky refactor, I want four things written down:
checkpoint:
name: before-auth-split
baseline:
- npm test
- npm run typecheck
rollback_if:
- public_api_changed
- baseline_failed
after_restore:
- npm test
- npm run typecheck
- git status --short
This YAML is a working convention, not an IOSM CLI input schema. Its value is the decision boundary: capture before change, define failure before evidence arrives, restore both session and files, then verify the restored state.
AI makes speculative refactoring cheap. That increases the value of cheap, named recovery. I do not need every experiment to succeed. I need failure to leave a workspace I can understand.