~/content/getting-started-with-opencode

Getting Started with OpenCode

Learn OpenCode basics in minutes. Master chat, file editing, and AI assistance. Practical tips to boost your coding productivity immediately.

last_updated: "2025-01-19"

##Your First Session

After installing OpenCode, let's start your first coding session.

###Starting OpenCode

Open your terminal and navigate to your project directory:

bash
cd ~/projects/my-app
opencode

You'll see the OpenCode prompt:

bash
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:

bash
> 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
bash
~/projects/my-app (main) [claude-3-5-sonnet]
>

###Output Modes

OpenCode displays different types of content:

Code blocks - Syntax highlighted code:

bash
function greet(name: string): string {
  return `Hello, ${name}!`;
}

File operations - Shows files being read or modified:

bash
Reading: src/utils/helpers.ts
Writing: src/components/Button.tsx

Thinking - Shows the AI's reasoning process:

bash
Thinking: Analyzing the codebase structure...
Found 3 TypeScript files in src/components/

##Working with Code

###Reading Files

Ask OpenCode to read and explain code:

bash
> Read src/App.tsx and explain its structure

OpenCode will:

  1. Read the file contents
  2. Analyze the code structure
  3. Provide a clear explanation

###Modifying Files

Request code changes with natural language:

bash
> Add error handling to the fetchUser function

OpenCode will:

  1. Show you the proposed changes
  2. Ask for confirmation before applying
  3. Apply the changes to your files

###Creating New Files

Ask OpenCode to create new files:

bash
> 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:

bash
> I'm building a REST API with Express.js.
> Create a middleware for JWT authentication.

###Review Changes

Always review proposed changes before applying:

  1. OpenCode shows a diff of proposed changes
  2. Type y to accept or n to reject
  3. You can ask for modifications before accepting

##Common Tasks

###Code Review

bash
> Review src/auth.ts for security issues

###Refactoring

bash
> Refactor the UserService class to use dependency injection

###Documentation

bash
> Add JSDoc comments to all exported functions in utils/

###Testing

bash
> Write unit tests for the validateEmail function

##Tips for Success

  1. Start small - Begin with simple tasks to understand how OpenCode works
  2. Use context - Tell OpenCode about your project's tech stack and conventions
  3. Iterate - Don't expect perfect results on the first try; refine your requests
  4. Learn from responses - Pay attention to how OpenCode approaches problems

##Next Steps

Ready to explore more advanced features? Check out:

Comments (Coming Soon)

Configure Giscus in environment variables to enable comments.