BASHCAT
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    22
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: - ai-coding-assistant - open-source - terminal-tool - claude-code-alternative - 部落格 aliases: - OpenCode 介紹 - Claude Code 替代方案 created: 2025-01-08 updated: 2025-01-08 status: published --- # 從 Claude Code 轉移到 OpenCode:一個開發者的真實體驗 ![opencode-guide-cover](https://hackmd.io/_uploads/r13xKAnNZe.jpg) 月底又到了,我盯著 Claude 的訂閱帳單發呆。 說實話,Claude Code 真的很好用。那種在終端機裡直接跟 AI 對話、讓它幫你改程式碼的感覺,一旦習慣就回不去了。但每個月固定支出的費用,加上只能用 Claude 一家的模型,總讓我有種被綁住的感覺。 有天在 Reddit 上滑到一篇討論,有人說:「OpenCode 根本就是開源版的 Claude Code。」我心想,又是一個半成品吧?結果一試,欸,還真不是那麼回事。 --- ## OpenCode 到底是什麼? OpenCode 是一個開源的 AI 編程助手,專門為終端環境設計。你可以把它想成 Claude Code 的「自由版」——功能相似,但不被任何服務商綁定。 這個專案由 SST 團隊用 Go 語言開發,目前在 GitHub 上已經累積超過 50,000 顆星星,每個月有超過 65 萬開發者在使用。這數字讓我稍微放心了一點,至少不是那種三個月後就沒人維護的玩具專案。 讓我最驚訝的是它支援的 LLM 數量——75 種以上。OpenAI、Anthropic、Google Gemini、Groq、AWS Bedrock,甚至本地跑的 Ollama 都可以。換句話說,你可以今天用 GPT,明天換 Claude,後天試試看 Gemini,完全看你心情。 ![opencode-guide-architecture](https://hackmd.io/_uploads/Bk5ZFR34Wx.jpg) 更棒的是,OpenCode 提供了一個叫「Zen」的功能,裡面有團隊精選過的模型組合。這些模型都經過基準測試,專門針對程式碼任務最佳化。對於選擇障礙的人來說,這簡直是救星。 --- ## 安裝其實超簡單 我一開始還擔心開源工具的安裝會很麻煩,結果完全多慮了。 如果你用 macOS 或 Linux,一行指令搞定: ```bash curl -fsSL https://opencode.ai/install.sh | bash ``` 用 npm 也行: ```bash npm install -g opencode-ai ``` macOS 用戶還可以用 Homebrew: ```bash brew install opencode-ai/tap/opencode ``` 安裝完成後,進到你的專案目錄,輸入 `opencode` 就會啟動 TUI 介面。第一次執行會問你要用哪個 AI 提供商,跟著提示走就好。 ### 設定檔的位置 OpenCode 的設定檔叫 `opencode.json`,可以放在兩個地方: - **全域設定**:`~/.config/opencode/opencode.json` - **專案設定**:專案根目錄的 `opencode.json` 專案設定會覆蓋全域設定,這點跟 Claude Code 的邏輯一樣。 一個基本的設定檔長這樣: ```json { "$schema": "https://opencode.ai/opencode.schema.json", "model": "anthropic/claude-sonnet-4-20250514", "provider": { "anthropic": { "apiKey": "${ANTHROPIC_API_KEY}" } } } ``` 如果你本來就有設定 `ANTHROPIC_API_KEY` 環境變數,OpenCode 會自動偵測到,連設定檔都可以省略。 --- ## 從 Claude Code 轉移:沒想到這麼順 這是我最在意的部分。畢竟在 Claude Code 上累積了不少自訂設定,如果轉移過去要全部重來,那也太痛苦了。 好消息是,兩者的概念幾乎一一對應。 ![opencode-guide-migration](https://hackmd.io/_uploads/ryiEFC2Nbg.jpg) ### 目錄結構對照 | Claude Code | OpenCode | 用途 | |-------------|----------|------| | `.claude/` | `.opencode/` | 專案設定目錄 | | `CLAUDE.md` | `AGENTS.md` | 專案指令檔 | | `~/.claude/` | `~/.config/opencode/` | 全域設定目錄 | | `.claude/commands/` | `.opencode/command/` | 自訂命令 | ### CLAUDE.md 直接改名就能用 這是讓我最意外的地方。`AGENTS.md` 是一個開放標準,被超過 60,000 個開源專案採用,而且它跟 `CLAUDE.md` 的格式完全相容。 我直接把 `CLAUDE.md` 複製一份改名成 `AGENTS.md`,內容一個字都沒改,OpenCode 就正常讀取了。 ```bash cp CLAUDE.md AGENTS.md ``` 如果你想保持兩邊都能用,建個 symlink 也行: ```bash ln -s AGENTS.md CLAUDE.md ``` ### 自訂命令的轉移 Claude Code 的自訂命令放在 `.claude/commands/`,OpenCode 則是放在 `.opencode/command/`。格式基本相同,都是 Markdown 檔案加上 YAML frontmatter。 原本在 Claude Code 的命令: ```markdown --- description: "執行測試並產生覆蓋率報告" --- 請執行完整的測試套件,並產生覆蓋率報告。 如果有測試失敗,請分析原因並提供修復建議。 $ARGUMENTS ``` 搬到 OpenCode 完全不用改。`$ARGUMENTS` 這個變數兩邊都支援。 ### MCP 設定需要小調整 這是唯一需要動手改的地方。Claude Code 的 MCP 設定在 `claude_desktop_config.json`,OpenCode 則是直接寫在 `opencode.json` 裡面。 Claude Code 的格式: ```json { "mcpServers": { "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path"] } } } ``` OpenCode 的格式: ```json { "mcp": { "filesystem": { "type": "stdio", "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path"] } } } ``` 差別在於 OpenCode 需要指定 `type`(`stdio` 或 `sse`),其他基本一樣。 --- ## 核心功能體驗 用了幾個禮拜後,我對 OpenCode 的幾個功能特別有感。 ### Agent 系統比想像中強大 OpenCode 內建兩種主要 Agent: - **Build**:預設模式,可以讀寫檔案、執行命令,全功能 - **Plan**:規劃模式,只能分析不能修改,適合先想清楚再動手 按 `Tab` 鍵可以在兩者之間切換。這個設計很聰明,有時候你只是想讓 AI 幫你分析問題、規劃步驟,不希望它真的動手改東西。 除了內建的,你也可以自己定義 Agent。我建了一個專門做 Code Review 的: ```markdown --- description: "專注於程式碼審查,不做任何修改" temperature: 0.3 permissions: edit: deny bash: deny --- 你是一個嚴格的程式碼審查員。請仔細檢查程式碼中的: - 潛在的 Bug 和邏輯錯誤 - 安全性問題 - 效能瓶頸 - 可讀性和維護性 只提供建議,不要直接修改程式碼。 ``` 把這個檔案存到 `.opencode/agent/review.md`,之後在對話中輸入 `@review` 就能呼叫它。 ### TUI 反應速度明顯較快 這點很主觀,但我個人感覺 OpenCode 的 TUI 比 Claude Code 順暢不少。輸入文字、切換模式、顯示 diff,都有種「更跟手」的感覺。 另一個我很喜歡的設計是即時 diff 顯示。當 AI 要修改檔案時,你可以直接在 TUI 裡看到改動的內容,不用等它全部寫完才能確認。 ### 權限詢問沒那麼煩人 用過 Claude Code 的人應該都有經驗,每次執行命令或修改檔案都要確認。OpenCode 預設比較寬鬆,大部分操作不會打斷你。 當然,如果你想要更嚴格的控制,可以在設定裡調整: ```json { "permissions": { "edit": "ask", "bash": "ask" } } ``` --- ## 說說真實的優缺點 用了一段時間,我覺得可以比較客觀地評價了。 ### 優點 **省錢**是最直接的。如果你本來就有 OpenAI 或 Anthropic 的 API Key,直接拿來用就好,不用額外訂閱。而且 OpenCode 還提供免費的 Zen 模型可以試用。 **自由度高**這點不用多說。今天 Claude 表現不好,明天換 GPT 試試看,後天可能 Gemini 更適合某個任務。這種彈性在 Claude Code 上是不可能的。 **社群活躍**也是加分項。GitHub 上的 issue 回覆很快,新功能持續在推出。看得出來這不是一個人的玩票專案,背後有認真在經營。 **MCP 相容**讓我能繼續用原本的工具鏈。之前在 Claude Code 設定好的 MCP server,稍微調整一下格式就能用了。 ### 缺點 **需要自己設定**是最明顯的。Claude Code 開箱即用,OpenCode 多少要花點時間搞懂設定檔怎麼寫。對於不喜歡折騰的人可能是個門檻。 **文件比較分散**。官方文件夠用,但有些進階功能要去 GitHub issue 或社群討論才找得到答案。 **模型品質取決於你的選擇**。OpenCode 本身只是個介面,實際表現完全看你用哪個模型。選錯模型,體驗可能比 Claude Code 差很多。 --- ## 適合什麼樣的人? 說實話,OpenCode 不是要取代 Claude Code,而是提供另一種選擇。 如果你符合以下條件,我覺得值得試試看: - 想降低 AI 工具的月費支出 - 喜歡開源、可控制的工具 - 想要嘗試不同 LLM 的彈性 - 本來就習慣在終端機工作 - 不怕花一點時間研究設定 相反地,如果你希望開箱即用、不想碰任何設定,或者對 Claude 的品質非常滿意,那繼續用 Claude Code 也完全沒問題。 --- ## 寫在最後 從 Claude Code 轉移到 OpenCode 的過程,比我預期的順利很多。大部分設定都能直接沿用,學習曲線也不陡峭。 對我來說,最大的收穫是重新拿回了選擇權。我不再被綁定在單一服務商,可以根據任務需求選擇最適合的模型,也能更靈活地控制成本。 如果你也對 AI 編程工具有興趣,但一直在觀望,不妨抽個空試試看 OpenCode。反正是免費的,不喜歡隨時可以切回去。 ```bash # 就這一行,試試看吧 curl -fsSL https://opencode.ai/install.sh | bash ``` --- ## 參考資料 - [OpenCode 官方網站](https://opencode.ai) - [OpenCode GitHub](https://github.com/sst/opencode) - [OpenCode 官方文件](https://opencode.ai/docs/) - [AGENTS.md 開放標準](https://agents.md/) - [freeCodeCamp - How to Integrate AI into Your Terminal Using OpenCode](https://www.freecodecamp.org/news/integrate-ai-into-your-terminal-using-opencode/)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully