AIFusionAIFusion
  • 平台教程
  • Claude Code 教程
  • OpenCode 教程
  • OpenClaw 教程
  • English
  • 简体中文
  • 平台教程
  • Claude Code 教程
  • OpenCode 教程
  • OpenClaw 教程
  • English
  • 简体中文
  • 指南

    • 平台教程
    • Claude Code 教程
    • OpenCode 教程
    • OpenClaw 教程

OpenCode 教程

什么是 OpenCode?

OpenCode 是一款基于 Go 的开源免费命令行编程工具(CLI),为开发者提供强大的 AI 协助。它最核心的优势在于打破了模型限制------你可以随意接入 Gemini、Claude、GPT 等任何一家的模型。

完全开源免费

基于 Go 开发,开源社区驱动

多模型自由切换

支持 OpenAI、Anthropic、Gemini 及本地模型

交互式终端界面

基于 Bubble Tea 的流畅 TUI 体验

LSP 集成

内置代码智能和诊断功能

安装方式

方式一:安装脚本(macOS / Linux)

curl -fsSL https://opencode.ai/install | bashSupported Environments & System Requirements
Supported Platforms
macOS 12+ (Recommended)
Ubuntu 20.04+ / Debian 11+
Windows (requires additional installation of Git for Windows)
System Requirements
Node.js 18.0 or higher version
npm or yarn package manager
Windows users need to install Git for Windows
4GB+ available memory
Stable network connection
Installation Steps
1. Install Node.js
If Node.js is not yet installed, we recommend using nvm for version management:nvm install 18nvm use 18
⚠ Note for Windows Users
Windows systems additionally require installing Git for Windows, otherwise Claude Code may not run properly. Keep default options during installation.
2. Install Claude Code CLI (Required)
This is the prerequisite for all subsequent configuration. You must first install the Claude Code CLI tool locally:
npm install -g @anthropic-ai/claude-code
Verify Installation
Run claude --version to confirm successful installation.
API Configuration (Key Step)
1. Get Token
Go to the SpritNest console to get your API Key. Free credits are given upon registration.
2. Configure Environment Variables
Edit the configuration file ~/.claude/settings.json:
{  "env": {    "ANTHROPIC_AUTH_TOKEN": "sk-your-api-key",    "ANTHROPIC_BASE_URL": "https://aifusion.network/",    "CLAUDE_CODE_MAX_OUTPUT_TOKENS": "64000",    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"  },  "permissions": {    "allow": [],    "deny": []  },  "alwaysThinkingEnabled": false}
💡 Tip
You can also configure via environment variables: export ANTHROPIC_BASE_URL=https://aifusion.network/ and export ANTHROPIC_AUTH_TOKEN="sk-xxx"
3. Configure .claude.json
Edit or create the ~/.claude.json file (on Windows: User Directory/.claude.json), add the following content to skip the initial onboarding flow:
{  "hasCompletedOnboarding": true}
❓ Why is this step needed?
After configuring this parameter, Claude Code will skip the official onboarding flow at startup and enter the ready-to-use state directly, avoiding getting stuck on the onboarding page due to network restrictions.
Basic Usage
1. Start Claude Code
# Start in the project directorycd your-projectclaude
2. First Startup Setup
On first startup, Claude Code will automatically scan the project structure. You can directly describe your requirements in natural language:
# Let Claude explain code> Explain the logic of src/auth/middleware.ts# Let Claude refactor code> Refactor this class component to hooks# Let Claude generate code> Create a CRUD template for a REST API
3. Basic Operation Examples
/compact [instructions]  # You can add instructions, telling Claude which important information to keep
Common Commands Reference
Common Commands in Interactive Mode
When the conversation is too long and tokens are approaching the limit, use the /compact command to compress the context:
/compact [instructions]  # You can add instructions, telling Claude which important information to keep
Resume Previous Conversation
Use /resume or add the –resume parameter at startup to resume a previous conversation:
claude --resume        # Resume last conversation at startupclaude --resume <id>   # Resume a specific conversation by ID
Handling Image Information
Claude Code supports passing images in conversations for analysis. You can directly drag images into the terminal or use path references.
MCP (Model Context Protocol)
MCP (Model Context Protocol) allows Claude Code to connect to external tools and services. Simply create a .mcp.json file in the project root directory to configure.
Best Practices for MCP
Place MCP configuration in the .mcp.json file in the project root directory, so team members can share the same tool configuration.
MCP Configuration Example
{  "mcpServers": {    "filesystem": {      "command": "npx",      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]    },    "github": {      "command": "npx",      "args": ["-y", "@modelcontextprotocol/server-github"],      "env": {        "GITHUB_PERSONAL_ACCESS_TOKEN": "your-token"      }    }  }}
Advanced Tips
Project Memory File (CLAUDE.md)
Create a CLAUDE.md file in the project root directory. Claude will automatically read it at each startup to understand the project context:
# Project Architecture- Frontend: React + TypeScript + Tailwind- Backend: Node.js + Express + Prisma- Database: PostgreSQL# Coding Standards- Use ESLint + Prettier- Components use functional style + Hooks- API responses use unified { code, data, message } format# Notes- Do not modify files in the migrations directory- Environment variables have templates in .env.example
IDE Integration
Claude Code can be used with mainstream IDEs:
VS Code: Run claude directly in the built-in terminal
Cursor: Can use both Cursor AI and Claude Code simultaneously
JetBrains: Start in the Terminal panel
VS Code Plugin: Claude Code for VS Code
Besides using it in the terminal, you can also install the official Claude Code for VS Code plugin in VS Code to get a graphical interactive experience.
💡 Prerequisites
Before using this plugin, you must first install and configure the Claude Code CLI locally (i.e., complete npm install -g @anthropic-ai/claude-code + configure settings.json and .claude.json). The plugin will
Installation Method: Search for Claude Code (published by Anthropic) in the VS Code extension store, then click Install.
Usage Notes:
After installation, the plugin will automatically detect the local Claude Code CLI and its configuration
If the CLI has been correctly configured with API Key and Base URL, the plugin will work directly without popping up a login page
If the plugin prompts for login, it means the local CLI has not been installed or configured completely. Please complete the installation and configuration steps above first
Usage Tips & Common Issues
Best Practices
Let Claude analyze the project structure first, then raise specific requirements
Break complex tasks into small steps and complete them gradually
Make good use of CLAUDE.md to provide project context
Regularly use /compact to compress context and avoid token overflow
5. Review generated code, don’t accept blindly Common Issues
Q: What to do about connection timeout?
Check whether the API address and Key in ~/.claude/settings.json are correct. If using environment variables, confirm that ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN are correctly set.
Q: How to switch models?
Enter /model in the conversation to view and switch available models.
Q: What to do when tokens are used up?
Use /compact to compress context, or /clear to clear the conversation and start over.
Reference Links
OpenCode Tutorial
What is OpenCode?
OpenCode is a free open-source command-line programming tool (CLI) based on Go, providing developers with powerful AI assistance. Its core advantage lies in breaking model restrictions — you can freely connect Gemini, Claude, GPT, and other models, or even local models, all through a unified interface.
Completely Open Source and Free
Based on Go, driven by the open-source community
Multi-model Free Switching
Supports OpenAI, Anthropic, Gemini, and local models
Interactive Terminal Interface
Smooth TUI experience based on Bubble Tea
LSP Integration
Built-in code intelligence and diagnostic features
Installation Methods
Method 1: Installation Script (macOS / Linux)
Method 2: NPM Installation (All Platforms, Recommended for Windows)
Install Node.js first, then run npm i -g opencode-ai@latest
Method 3: Homebrew Desktop Client (macOS)
Run brew install --cask opencode-desktop
Desktop Application — OpenCode also provides a desktop application and IDE extensions, which can be obtained from the official website.
API Configuration (Key Step)
1. Register Custom Provider
After installation, do not start OpenCode directly. Execute in the terminal: opencode auth login
Select "other" in the provider list (at the bottom, you can search directly). Then follow the prompts:
Provider ID: Enter a unique identifier, e.g., spritnestapi (must be consistent with subsequent configuration)
API Key: Enter the API Key obtained from the SpritNest console
2. Modify Configuration File
Open the configuration directory, create or edit opencode.json:
macOS / Linux: ~/.config/opencode/opencode.json
Windows: Users\YourUsername\.config\opencode\opencode.json
⚠ Important Note: The "spritnestapi" in the configuration must be exactly the same as the Provider ID entered in step 1. Anthropic-compatible spritnestapi uses https://aifusion.network/; OpenAI-compatible "spritnestapigpt" uses https://aifusion.network/v1. If you want to use Claude and GPT models simultaneously, you can create two providers.
3. Get API Token
Go to the SpritNest console to generate a token.
Token Group Recommendation: It is recommended to use the default group. After setting the token name, do not add any models in the "Restrict Model List". Keep everything else as default.
Basic Usage
1. Start OpenCode
After saving the configuration file, restart the terminal, then run: opencode
2. Select Model
Enter the command /models in the chat interface to view available models. In the model list, you can see your configured relay station and its models. Select one to start using normally.
3. Start Coding
Usage Tips
Best Practices: 1. Utilize session management features to save and switch conversations for different projects. 2. Improve efficiency by presetting common operations through custom commands. 3. Configure multiple models in models and switch as needed. 4. Make good use of LSP integration for code intelligent suggestions.
Common Issues: Q: Can't see custom models after startup? — Check whether the Provider ID in opencode.json is exactly the same as what you entered during opencode auth login. Q: Connection failed? — Confirm that baseURL and apiKey are correctly filled, and the token group uses default.
OpenClaw Tutorial
What is OpenClaw?
OpenClaw is a powerful AI programming assistant tool that supports interacting with AI models through Web UI or command line. It provides rich configuration options and a plugin system, and can connect to various AI model providers, making it an ideal choice for developers who need flexible configuration.
Web UI Interface
Provides a friendly Web interface for convenient viewing and managing conversations
Multi-model Support
Supports Claude, GPT, and other AI models
Plugin System
Rich plugin ecosystem, expanding more features
Highly Configurable
Supports custom contextWindow, maxTokens, and other parameters
Installation Steps
Prerequisites
Make sure Node.js ≥ 22 is installed. You can check the version with the following command: node --version
Install OpenClaw
Run the following command in the terminal to globally install OpenClaw: npm install -g openclaw@latest (or use pnpm add -g openclaw@latest). After installation, run openclaw onboard --install-daemon to start the initialization wizard.
Configuration Guide
1. Start Initialization Program
After installation, run the following command to start the initialization wizard: openclaw onboard --install-daemon
2. Configuration Wizard Steps
Follow the wizard prompts for configuration. Key steps: 1. Install daemon? - Select yes. 2. Onboarding mode - Select the first option. 3. Model/auth provider - Select Custom Provider. 4. API Base URL - Enter https://aifusion.network/. 5. API Key - Enter the API Key from the console. 6. Endpoint compatibility - Select Anthropic-compatible. 7. Model ID - Enter claude-opus-4-6-thinking. 8. Endpoint ID - Use default. 9. Model alias - Optional, e.g., opus4.6. 10. Skip QuickStart/Skills/Hooks for first use. 11. How do you want to hatch your bot? - Select Open the Web UI.
3. Get API Key
Go to the SpritNest console to create a token: 1. Click "Add Token". 2. Enter a name (any), select default for the group. 3. Leave the model restriction list and IP whitelist empty, click Submit directly. 4. Copy the generated Key and paste it into the OpenClaw configuration.
4. Optimize Configuration File
After initialization, edit ~/.openclaw/openclaw.json: Increase contextWindow from 4096 to 200000. Increase maxTokens from 4096 to 8192. Confirm baseUrl is https://aifusion.network/.
Basic Usage
After configuration is complete, OpenClaw will automatically open the Web UI interface. You can converse with AI in the browser for code writing, problem answering, and other operations. For first-time use, it is recommended to first conduct a simple conversation test to confirm the configuration is correct before engaging in complex programming tasks. You can also let AI help you configure other tools and plugins.

方式二:NPM 安装(全平台,推荐 Windows)

先安装 Node.js,然后运行:

npm i -g opencode-ai@latest

方式三:Homebrew 桌面客户端(macOS)

brew install --cask opencode-desktop

桌面应用

OpenCode 也提供桌面应用和 IDE 扩展,可从 官网下载页 获取。

API 配置(关键步骤)

1. 注册自定义服务商

安装后先不要直接启动 OpenCode,在终端执行:

opencode auth login

在服务商列表中选择 other(在最下面,可以直接搜索):

然后按提示操作:

  • Provider ID:输入一个唯一标识名,例如 spritnestapi(后续配置需一致)

  • API Key:输入你在 SpritNest 控制台获取的 API Key

2. 修改配置文件

打开配置目录,创建或编辑 opencode.json:

  • macOS / Linux:~/.config/opencode/opencode.json

  • Windows:Users\你的用户名\.config\opencode\opencode.json

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "spritnestapi": {  // 必须和上一步的 Provider ID 完全一致
      "npm": "@ai-sdk/anthropic",
      "name": "SpritNest-Api",  // UI 中显示的名称,可自定义
      "options": {
        "baseURL": "https://aifusion.network/"
        // "apiKey": "{cred:spritnestapi}"  // 可选:自动引用上一步存储的密钥
      },
      "models": {
        "claude-opus-4-5-20251101": {
          "name": "claude-opus-4-5-20251101"
        },
        "claude-sonnet-4-5": {
          "name": "claude-sonnet-4-5"
        },
        "claude-opus-4-6": {
          "name": "claude opus 4.6"
        }
        // 添加更多模型...
      }
    },
    "spritnestapigpt": {  // 另开一个 GPT 格式的服务商,可同时用 Claude 和 GPT
      "npm": "@ai-sdk/openai",
      "name": "SpritNest-gpt",
      "options": {
        "baseURL": "https://aifusion.network/",
        "apiKey": "sk-your-gpt-api-key"  // 统一使用 default 分组的令牌
      },
      "models": {
        "gpt-5.2-codex": {
          "name": "gpt-5.2-codex"
        },
        "gpt-5.3-codex": {
          "name": "gpt-5.3-codex"
        },
        "gpt-5.3-codex-spark": {
          "name": "gpt-5.3-codex-spark"
        }
        // 添加更多模型...
      }
    }
  }
}

⚠ 重要提示

配置中的 "spritnestapi" 必须和第 1 步输入的 Provider ID 完全一致。Anthropic 兼容的 spritnestapi 使用https://aifusion.network/;OpenAI 兼容的 "spritnestapigpt" 使用 https://aifusion.network/。想同时使用 GPT 模型,需要另建一个 "spritnestapigpt" 服务商,也使用 default 分组的令牌。

3. 获取 API 令牌

前往 SpritNest 令牌页面 生成令牌。

令牌分组建议

建议使用 default 分组,设置好令牌名称后,不要在下面的「限制模型列表」中添加任何模型,其他全部保持默认即可。

基本使用方法

1. 启动 OpenCode

保存配置文件后,重启终端,然后运行:

opencode

2. 选择模型

在聊天界面输入命令查看可用模型:

/models

在模型列表中可以看到你配置的中转站及其模型(如 "claude-opus-4-6"),选择后即可正常使用。

3. 开始编程

> 帮我分析这个项目的架构
> 给这个函数添加错误处理
> 优化这段代码的性能

使用技巧

最佳实践

1. 利用会话管理功能,保存和切换不同项目的对话

2. 通过自定义命令预设常用操作,提升效率

3. 在 models 中配置多个模型,按需切换

4. 善用 LSP 集成获取代码智能提示常见问题

Q: 启动后看不到自定义模型?

检查 opencode.json 中的 Provider ID 是否和 opencode auth login 时输入的完全一致。

Q: 连接失败?

确认 baseURL 和 apiKey 填写正确,令牌分组使用 default。

OpenClaw 教程

什么是 OpenClaw?

OpenClaw 是一款强大的 AI 编程助手工具,支持通过 Web UI 或命令行与 AI 模型交互。它提供了丰富的配置选项和插件系统,可以接入各种 AI 模型提供商,是开发者提升编程效率的利器。

Web UI 界面

提供友好的 Web 界面,方便查看和管理对话

多模型支持

支持 Claude、GPT 等多种 AI 模型

插件系统

丰富的插件生态,扩展更多功能

高度可配置

支持自定义 contextWindow、maxTokens 等参数

安装步骤

前提条件

确保已安装 Node.js ≥ 22。可以通过以下命令检查版本:

检查 Node.js 版本

安装 OpenClaw

在终端运行以下命令全局安装 OpenClaw:

安装命令

配置说明

1. 启动初始化程序

安装完成后,运行以下命令启动初始化向导:

初始化命令

2. 配置向导步骤

按照向导提示进行配置,关键步骤如下:

  1. Install daemon? - 选择 yes

  2. Onboarding mode - 选择第一个选项

  3. Model/auth provider - 选择 Custom Provider (Any OpenAI or Anthropic compatible endpoint)

  4. API Base URL - 输入 https://aifusion.network/

  5. API Key - 输入从控制台获取的 API Key(见下方说明)

  6. Endpoint compatibility - 选择 Anthropic-compatible (Uses /messages)

  7. Model ID - 输入 claude-opus-4-6-thinking(或其他模型)

  8. Endpoint ID - 使用默认值即可

  9. Model alias - 可选,例如输入 opus4.6

  10. 后续的 QuickStart、Skills、Hooks 等选项可根据需要选择,初次使用可全部跳过

  11. How do you want to hatch your bot? - 选择 Open the Web UI 方便查看

3. 获取 API Key

前往 SpritNest 令牌页面 创建令牌:

  1. 点击「添加令牌」

  2. 输入名称(随意),分组选择 default

  3. 模型限制列表和 IP 白名单留空,直接点击提交

  4. 复制生成的 Key,粘贴到 OpenClaw 配置中

4. 优化配置文件

初始化完成后,编辑配置文件 ~/.openclaw/openclaw.json,优化以下参数:

  • 将 contextWindow 从 4096 提升到 200000

  • 将 maxTokens 从 4096 提升到 8192

  • 确认 baseUrl 为 https://aifusion.network/

配置文件示例

基本使用

配置完成后,OpenClaw 会自动打开 Web UI 界面。你可以在浏览器中与 AI 进行对话,进行代码编写、问题解答等操作。

使用建议

首次使用建议先进行简单对话测试,确认配置正确后再进行复杂的编程任务。可以让 AI 帮助你配置其他工具和插件。

上次更新: 2026/7/2 10:50
贡献者: eric
Prev
Claude Code 教程
Next
OpenClaw 教程