Skip to main content
Clients & tools

OpenCode

Terminal AI coding assistant

OpenCode is a terminal-based AI coding assistant that helps you write, debug, and refactor code directly from the command line. Connect it to Qwen Cloud's pay-as-you-go API for intelligent coding assistance powered by Qwen models.

Quick start

Get running in a few minutes:
# 1. Install
npm install -g opencode-ai
opencode -v

# 2. Start in your project (run opencode and type /connect)
cd your-project
opencode
/connect

# 3. Configure (follow prompts)
Provider: Type "alibaba" and select "Alibaba"
API Key: sk-xxx
Model: Select "qwen3.5-plus" or "qwen3-coder-plus"

# 4. Test (type in OpenCode)
Ask: "Generate a README.md for this project"
You should see: OpenCode analyzes your project and creates a README

Configuration

Basic setup

Configure OpenCode to use Qwen Cloud:
  • Provider: Alibaba
  • Authentication: API key required
  • Model selection: Choose from available Qwen models
Free quota and billing:
  • First-time users get a free quota (valid for 90 days)
  • Enable Free quota only to prevent unexpected charges
For Coding Plan users: Use your exclusive base URL and API key instead. See Coding Plan for OpenCode.

Prerequisites

  • Node.js 18 or later (download)
  • API key
Verify Node.js version:
node -v  # Should be v18 or higher

Step-by-step setup

1

Install OpenCode

npm install -g opencode-ai
opencode -v
2

Navigate to project

cd your-project-folder
# Or create a new project:
mkdir my-project && cd my-project
3

Connect to Qwen Cloud

opencode
/connect
Then:
  • Search provider: Type alibaba
  • Select: Alibaba
  • Enter: Your API key
  • Choose: Model (e.g., qwen3.5-plus)

Model recommendations

TaskModelWhy
Quick editsqwen3.5-plusBalanced speed and quality
Code generationqwen3-coder-plusSpecialized for coding
Complex refactoringqwen3-coder-plusDeep code understanding
Architecture designqwen3-maxAdvanced reasoning

Limitations

  • Terminal only: No GUI interface
  • Project context: Works best when started in project root
  • Token usage: Large projects consume more tokens

Examples

Generate code

"Create a REST API with Express.js for user management"

Explain code

"Explain how the authentication middleware works"

Refactor existing code

"Refactor the database module to use async/await"

Write tests

"Write unit tests for the user service module"

Fix bugs

"Debug why the login function returns undefined"

Commands

CommandDescription
/connectConnect to API provider
/disconnectDisconnect from provider
/modelSwitch to different model
/clearClear conversation context
/helpShow available commands
/exitExit OpenCode

Advanced features

Context management

OpenCode automatically reads your project structure. For better results:
  • Start OpenCode in your project root
  • Keep project files organized
  • Use clear file and folder names

Multi-file operations

"Update all test files to use the new API endpoints"

Code review

"Review the security of our authentication module"

Documentation generation

"Generate JSDoc comments for all public functions"

Troubleshooting

"Cannot find module opencode-ai"
Solution: Ensure global npm installation:
npm list -g opencode-ai
npm install -g opencode-ai
"Invalid API key"
Solution:
  • Verify API key is correct
  • Check you selected "Alibaba" provider
  • Ensure API key has quota
"Model not available"
Solution:
  • Check model access permissions
  • Try a different model
  • See Model list
High token consumption
Solution:
  • Start OpenCode in specific subdirectories
  • Use /clear to reset context
  • Choose appropriate models for tasks
Connection timeout
Solution:
  • Check network connection
  • Verify API endpoint accessibility
  • Try reconnecting with /connect

Token optimization

Reduce usage by:
  1. Focused context: Start OpenCode in specific project subdirectories
  2. Clear prompts: Be specific about what you need
  3. Context clearing: Use /clear between unrelated tasks
  4. Model selection: Use lightweight models for simple tasks
  5. Batch operations: Combine related requests