Your First Session
After installing OpenCode, let's start your first coding session.
Starting OpenCode
Open your terminal and navigate to your project directory:
cd ~/projects/my-app
opencode
You'll see the OpenCode prompt:
OpenCode v0.1.0
Working directory: ~/projects/my-app
> How can I help you today?
Basic Commands
OpenCode understands natural language. Here are some things you can ask:
> Explain what this codebase does
> Find all TODO comments in the project
> Help me fix the bug in auth.ts
> Write a function to validate email addresses
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Ctrl+C | Cancel current operation |
Ctrl+D | Exit OpenCode |
Tab | Autocomplete |
↑/↓ | Navigate history |
Understanding the Interface
The Prompt
The default prompt shows:
- Current working directory
- Git branch (if in a git repository)
- Model being used
~/projects/my-app (main) [claude-3-5-sonnet]
>
Output Modes
OpenCode displays different types of content:
Code blocks - Syntax highlighted code:
function greet(name: string): string {
return `Hello, ${name}!`;
}
File operations - Shows files being read or modified:
Reading: src/utils/helpers.ts
Writing: src/components/Button.tsx
Thinking - Shows the AI's reasoning process:
Thinking: Analyzing the codebase structure...
Found 3 TypeScript files in src/components/
Working with Code
Reading Files
Ask OpenCode to read and explain code:
> Read src/App.tsx and explain its structure
OpenCode will:
- Read the file contents
- Analyze the code structure
- Provide a clear explanation
Modifying Files
Request code changes with natural language:
> Add error handling to the fetchUser function
OpenCode will:
- Show you the proposed changes
- Ask for confirmation before applying
- Apply the changes to your files
Creating New Files
Ask OpenCode to create new files:
> Create a new React component called UserProfile
Best Practices
Be Specific
More specific requests get better results:
❌ "Fix the bug" ✅ "Fix the TypeScript error in src/api/users.ts line 42"
❌ "Make it faster" ✅ "Optimize the database query in getUserById to use indexing"
Provide Context
Help OpenCode understand your needs:
> I'm building a REST API with Express.js.
> Create a middleware for JWT authentication.
Review Changes
Always review proposed changes before applying:
- OpenCode shows a diff of proposed changes
- Type
yto accept ornto reject - You can ask for modifications before accepting
Common Tasks
Code Review
> Review src/auth.ts for security issues
Refactoring
> Refactor the UserService class to use dependency injection
Documentation
> Add JSDoc comments to all exported functions in utils/
Testing
> Write unit tests for the validateEmail function
Tips for Success
- Start small - Begin with simple tasks to understand how OpenCode works
- Use context - Tell OpenCode about your project's tech stack and conventions
- Iterate - Don't expect perfect results on the first try; refine your requests
- Learn from responses - Pay attention to how OpenCode approaches problems
Next Steps
Ready to explore more advanced features? Check out:
- Agent Mode - Let OpenCode handle complex multi-step tasks
- Model Configuration - Choose the best model for your needs
- Tips & Tricks - Advanced usage patterns