##Essential Keyboard Shortcuts
Master these shortcuts to dramatically speed up your workflow.
###Navigation
| Shortcut | Action |
|----------|--------|
| Ctrl+C | Cancel current operation |
| Ctrl+L | Clear screen |
| Ctrl+R | Search command history |
| Tab | Autocomplete commands |
| ↑/↓ | Navigate history |
###Editing
| Shortcut | Action |
|----------|--------|
| Ctrl+A | Move to line start |
| Ctrl+E | Move to line end |
| Ctrl+W | Delete word backward |
| Ctrl+U | Delete entire line |
| Ctrl+K | Delete to end of line |
###Session Control
| Shortcut | Action |
|----------|--------|
| Ctrl+D | Exit OpenCode |
| Ctrl+Z | Suspend to background |
| Esc | Cancel multi-line input |
##Effective Prompting Techniques
###Be Specific
Instead of:
fix the bug
Write:
Fix the null pointer exception in src/utils/parser.ts line 45
that occurs when parsing empty JSON arrays
###Provide Context
Instead of:
add validation
Write:
Add email validation to the signup form in components/SignupForm.tsx
using the existing validator utility in lib/validators.ts
###Use Step-by-Step Instructions
For complex tasks, break them down:
I need to add a caching layer to our API:
1. First, analyze the current API structure in src/api/
2. Design a caching strategy for GET endpoints
3. Implement using Redis with 5-minute TTL
4. Add cache invalidation on POST/PUT/DELETE
5. Write tests for the caching logic
##Slash Commands
Quick commands that boost productivity:
| Command | Description |
|---------|-------------|
| /help | Show all available commands |
| /clear | Clear conversation history |
| /model | Switch AI model |
| /compact | Summarize conversation |
| /cost | Show token usage and costs |
| /diff | Show pending file changes |
| /undo | Revert last file change |
###Custom Slash Commands
Create your own commands in ~/.config/opencode/commands.yaml:
commands:
/review:
description: "Code review current changes"
prompt: |
Review the current git diff for:
- Code quality issues
- Potential bugs
- Security concerns
- Performance problems
Provide specific suggestions for each issue found.
/commit:
description: "Generate commit message"
prompt: |
Analyze the staged changes and generate a conventional commit message.
Format: <type>(<scope>): <description>
/doc:
description: "Generate documentation"
prompt: |
Generate comprehensive JSDoc/TSDoc documentation for the selected code.
Include parameter descriptions, return types, and examples.
##Context Management
###Using @ Mentions
Reference specific files or symbols:
@src/components/Button.tsx add hover animation
@useAuth hook add token refresh logic
@package.json update React to latest version
###Directory Context
Work with entire directories:
@src/api/ refactor all endpoints to use async/await
@tests/ update all tests to use the new mock system
###Git Context
Reference git state:
@git:staged review these changes before commit
@git:branch:feature-auth show what's different from main
##Workflow Optimization
###Template-Based Development
Create reusable prompts for common tasks:
You: /template component
OpenCode: Creating new React component...
- Name: [UserProfile]
- Props: [user: User, onEdit: () => void]
- Style: [Tailwind CSS]
- Tests: [Yes]
###Iterative Refinement
Build complex features incrementally:
Step 1: "Create basic CRUD API for products"
Step 2: "Add pagination to the list endpoint"
Step 3: "Add filtering by category and price range"
Step 4: "Add caching for frequently accessed products"
Step 5: "Add comprehensive error handling"
###Parallel Tasks
Work on multiple things simultaneously:
While you implement the frontend form, also:
1. Create the API endpoint
2. Set up form validation schema
3. Write integration tests
##Configuration Tips
###Optimize for Your Stack
# ~/.config/opencode/config.yaml
context:
# Include relevant files automatically
auto_include:
- "package.json"
- "tsconfig.json"
- ".env.example"
# Exclude noise
exclude_patterns:
- "node_modules/**"
- "dist/**"
- "*.log"
# Stack-specific settings
presets:
react:
include: ["src/components/**", "src/hooks/**"]
api:
include: ["src/routes/**", "src/middleware/**"]
###Custom Model Presets
model_presets:
quick:
model: claude-3-5-haiku
max_tokens: 1000
thorough:
model: claude-opus-4-20250514
max_tokens: 8000
temperature: 0.1
creative:
model: gpt-4o
temperature: 0.8
##Performance Tips
###1. Use the Right Model
- Quick tasks: Use Haiku or GPT-4o-mini
- Complex analysis: Use Opus or GPT-4o
- Large codebases: Use Gemini with 2M context
###2. Minimize Context
# Only include necessary files
context:
max_files: 20
max_tokens: 50000
###3. Enable Caching
cache:
enabled: true
ttl: 3600 # 1 hour
max_size: 100MB
###4. Use Compact Mode
For long sessions, compress context:
/compact
##Debugging Tips
###Verbose Mode
See what OpenCode is doing:
opencode --verbose
# or
export OPENCODE_DEBUG=1
###View Token Usage
Monitor costs in real-time:
/cost
###Inspect Context
See what files are included:
/context show
##Best Practices
###1. Start with Understanding
Before making changes:
Analyze the authentication flow in this codebase and explain
how user sessions are managed.
###2. Review Before Accepting
Always review proposed changes:
/diff
###3. Commit Frequently
Use atomic commits:
/commit
git push
###4. Document As You Go
Generate docs alongside code:
After implementing this function, add JSDoc documentation.
###5. Test-Driven Approach
Write tests first:
First write failing tests for user registration, then implement
the feature to make them pass.
##Common Patterns
###Bug Fix Pattern
1. "Show me the error and relevant code around line X"
2. "What's causing this issue?"
3. "Fix the bug and add a test to prevent regression"
4. "/diff" to review
5. "/commit" with descriptive message
###Feature Development Pattern
1. "Analyze how similar features are implemented"
2. "Plan the implementation for [feature]"
3. "Implement step by step, starting with [component]"
4. "Add tests for the new feature"
5. "Update documentation"
###Code Review Pattern
1. "@git:staged review these changes"
2. "Focus on [security/performance/readability]"
3. "Suggest improvements"
4. "Apply the approved suggestions"