We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Undo and Redo

I like to think of my session contexts more as "resources" than "conversations." They're ultimately logs of text, so it's easy to build tools for manipulating them. Just like git makes manipulating code changes super powerful, some agent session management tools can edit session context in ingenious ways.

The /undo command rolls back the last response the model gave you. If OpenCode captured a matching filesystem snapshot, it also restores the files changed by that response!

After running /undo and before submitting another prompt, you can use /redo to restore the conversation and files to the state that you just rolled back from. That said, submitting a new prompt makes the undo permanent, so you can no longer redo it!

OpenCode's snapshot capture requires a Git repository and is on a best-effort basis. /undo can't reverse all side effects of shell commands, e.g., changes to databases or files outside the working repo, effects on running processes, and network operations. So, it's a convenience, but not a replacement for good Git hygiene and backups.

I actually use /undo quite a bit. If I get a "bad" output, and I can tell it was just a bad prompt, a quick undo + re-prompt is a lot faster than trying to explain to the AI what went wrong and how to get back on track.

Assignment

Undo and restore a small test addition.

Unary minus should reject a boolean, so this SlopLang program should produce a runtime error (the ✅ emoji is true in SlopLang):

hallucinate(-✅)✨

While this is okay:

hallucinate(-1)✨

Tell OpenCode to run and submit the CLI tests from the project root.