Overview
OpenCode provides/undo and /redo commands to navigate through your conversation history and revert unwanted changes. This is essential when:
- The assistant made an incorrect change
- You want to try a different approach
- You need to backtrack to an earlier state
- You made a mistake in your request
/undo Command
Revert the last assistant message and any changes it made.Usage
What Gets Undone
When you undo:- Message removed - The last assistant message is removed from history
- File changes reverted - Any file modifications are undone
- Tool executions canceled - Effects of tool calls are reversed
- State restored - Session returns to the previous state
Multiple Undo
You can undo multiple times to go further back:/undo steps back one assistant message.
Example
/redo Command
Reapply a previously undone message.Usage
When Redo Works
Redo is available when:- You’ve used
/undoat least once - You haven’t sent new messages since undoing
- The undone messages are still in history
Multiple Redo
Redo multiple times to reapply several undone messages:Redo Limits
You cannot redo after:- Sending a new message
- Closing and reopening the session
- Using
/forkto branch the conversation
Example
How It Works
Message History
OpenCode maintains a complete history of messages:File State
File changes are tracked:- Before undo: File has changes from assistant
- After undo: File restored to previous state
- After redo: Changes reapplied
Tool Effects
Some tool effects can’t be fully undone:- Bash commands: Side effects persist (use with caution)
- API calls: External changes not reverted
- Deleted files: Moved to trash, can be recovered
Use Cases
Correcting Mistakes
Exploring Alternatives
Recovering from Errors
Iterative Refinement
Best Practices
Undo immediately
Undo right away if you spot an issue
Review changes
Check what was changed before deciding to undo
Be specific next time
After undoing, give clearer instructions
Use /fork for experiments
Fork instead of undo/redo for major changes
Limitations
Cannot Undo User Messages
You can only undo assistant messages, not your own:External Side Effects
Some actions can’t be fully undone:Context Compaction
After context compaction, some undo history may be lost:- Recent messages remain undoable
- Very old messages may not be reversible
- Snapshots preserve key states
Alternatives to Undo/Redo
Fork Instead
Use/fork to branch without losing history:
Git for Recovery
Leverage git for file recovery:Snapshots
OpenCode creates automatic snapshots:Technical Details
Storage
Undo/redo state is maintained:- In-memory for the current session
- In the session database
- Not affected by closing/reopening TUI (when using same session)
Session Continuity
When continuing a session:Fork Impact
Forking clears redo stack:Troubleshooting
Undo Not Working
Problem:/undo doesn’t revert changes
Solutions:
- Check if there’s anything to undo
- Verify files aren’t read-only
- Ensure session database is writable
- Try undoing again (may need multiple undos)
Redo Not Available
Problem:/redo command fails
Solutions:
- You may have sent a new message (clears redo stack)
- Session was forked (clears redo)
- All undone messages already redone
Changes Persist
Problem: Some changes remain after undo Solutions:- External API calls can’t be undone
- Bash commands may have side effects
- File system operations outside project scope
- Use
git resetfor file recovery
Keyboard Shortcuts
In the TUI, you can also use:- Ctrl+Z (or Cmd+Z on macOS): Undo
- Ctrl+Shift+Z (or Cmd+Shift+Z): Redo
Related Topics
/fork
Branch conversations
Sessions
Managing sessions
Snapshots
Automatic state snapshots
Version Control
Using git with OpenCode