OpenCode安装指南2026

2026-08-01 约 4 分钟阅读

OpenCode是最火的开源编程智能体,但安装文档默认你懂生态。

OpenCode Install Guide 2026: Setup in 5 Minutes on Windows, Mac and Linux

OpenCode is an open-source AI coding agent for the terminal (191,500 GitHub stars). This guide walks through installation on all three platforms and connecting your first model.

Prerequisite: Node.js 20+

node --version

OpenCode is distributed via npm. Install Node.js LTS if missing.

Install

npm install -g opencode

That is the whole install. Verify:

opencode --version

Connect a Model

On first run, OpenCode asks which provider to use. Three fastest paths:

Path A - Anthropic (best quality):

opencode auth login
# follow the browser prompt to authorize

Path B - OpenRouter (one key, many models):

export OPENROUTER_API_KEY=sk-or-...
opencode --model openrouter/anthropic/claude-sonnet-4

Path C - Free local model via Ollama:

ollama pull qwen2.5-coder:7b
opencode --model ollama/qwen2.5-coder:7b

First Session

cd /path/to/your/project
opencode

Type a task: "explain the architecture of this repo and add a test for the auth module". OpenCode reads the repo, proposes changes, and asks for approval before editing.

Useful Flags

Flag Purpose
opencode --model Choose model per session
opencode --help All options
opencode sessions List previous sessions
opencode --print Non-interactive output (scripting)

FAQ

Does OpenCode work on Windows? Yes, native Windows via Node. Some MCP servers prefer WSL2, but core features work fine.

How much does it cost? The tool is free; you pay model API usage (a few cents per session with small models).

Can I use it with VS Code? Yes, there is a VS Code extension that embeds OpenCode.

相关文章
2026-06-29
高收益主线龙头策略——不花钱的数据,也能抓到龙头
2026-06-29
你笔记本里,藏着一个AI
2026-07-14
免费AI编程助手 2026 配置指南:VS Code 5分钟装 Continue、Copilot、Windsurf

💬 评论 (0)

暂无评论,来说两句吧~

登录后评论