OpenCode: OpenCode First Use
Last updated: 2026-08-31
After installation and configuration, let's start using OpenCode for the first time.
1. What You Will Learn
- Starting OpenCode and entering TUI
- First conversation experience
- AI code analysis
- AI code modification
- Undoing operations
2. Start OpenCode
Navigate to your project directory and run:
cd my-project
opencode
You'll see the TUI interface with an input box at the bottom and conversation area above.
3. First Conversation
In the input box, type:
Summarize this project's structure
OpenCode will read project files and provide a structural overview.
4. Reference Files for Analysis
Use @ to reference project files:
How is authentication implemented in this project? Check @src/auth/index.ts
Features:
- Fuzzy search for file paths
- Auto-reads file content
- No manual code copying needed
5. Let AI Modify Code
Give a modification instruction:
Replace all var declarations in src/utils/format.ts with const or let
OpenCode will:
- Read the file content
- Identify all var declarations
- Determine whether to use const or let based on context
- Directly modify the file
6. Execute Commands
Use the ! prefix to execute Shell commands:
!npm test
Results are automatically added to the conversation context for AI follow-up.
7. Undo Operations
If AI modifications are not as expected:
/undo
This will:
- Undo the last message
- Roll back code changes
Redo:
/redo
Important: Undo relies on Git. Ensure your project uses Git version control.
8. Switch Models
If the current model isn't performing well:
/model
Select another model from the list.
9. Session Management
New session: /new
View sessions: /sessions
Continue last session: opencode --continue
10. Exit OpenCode
/exit
Or use shortcut Ctrl + X → Q.
❓ FAQ
opencode run "your question" to get results directly without entering TUI. Great for quick questions and script integration.📖 Summary
- Run
opencodein your project directory to start - Use
@for file references,!for commands /undoto undo,/redoto redo/modelto switch models,/newfor new sessions- Ensure Git commits before important operations
📝 Exercises
-
Basic: Start OpenCode and have it analyze your current project structure.
-
Intermediate: Have OpenCode modify a file, then undo the change with /undo.
-
Advanced: Use non-interactive mode
opencode runfor code analysis and redirect output to a file.