Last updated: Sep 30, 2026最後更新:2026年9月30日
Set Up an AI Coding Agent安裝人工智能編程助手
There are two things to choose, and you can change your mind later about either one.
Which agent? OpenCode and GitHub Copilot both write and run code for you. OpenCode works in a terminal window; Copilot sits in a chat panel inside VS Code.
Where do you work? In your browser, using GitHub Codespaces, where nothing is installed on the computer you are using. Or on your own computer, using software you install once.
On a school or lab computer, use Codespaces: those machines usually don't let you install Python, Git or other software, and everything a Codespace needs is already inside it. On your own computer you can choose freely.
The options below are combinations of those two. Whichever you pick, you end up in the same place: an agent connected to your OpenRouter key.
School or lab computer
These machines often block installing software (Python, Git, VS Code and so on), and nothing is set up for you in advance. Use Codespaces: you only need a web browser and your GitHub account.
Codespaces: in the browser, nothing to install. Works with OpenCode or Copilot.
Your own computer (Mac or Windows)
You can install whatever you need.
Windows & Mac
OpenCode Desktop App: one download, no terminal.
VS Code + Copilot: in an editor, standard install.
Codespaces: in the browser, nothing to install. Works with OpenCode or Copilot.
Mac only
VS Code + OpenCode: run the agent in VS Code's terminal.
Most important, whichever setup you choose: commit and push your work to your GitHub repository at the end of every session. That is what preserves it. Anything left only in a Codespace or on a school computer will eventually be lost. You can ask your agent to commit and push for you.
Before you start
- Create a GitHub account. You need one in every case, because it is where your work is stored.
- Get your OpenRouter API key at keyreg.qhchina.org using the class code from your syllabus. Keep it private.
Browser: GitHub Codespaces
A Codespace is a computer that runs on GitHub's servers and that you use through your browser. Because the work happens there, nothing is installed on the computer in front of you, and Python and Git are already set up inside it. That makes it the right choice for school and lab computers, and it works just as well on your own.
- A Codespace runs on a GitHub repository, so make one first: go to the template qh-starter, click the green Use this template button, and create your own repository.
- Open your new repository → green Code button → Codespaces → Create codespace on main. The first start takes a few minutes.
You can also use a repository of your own instead of the template. Create one with a README.md so it isn't empty, then open a Codespace on it the same way. One difference: the template's Codespace comes with OpenCode already installed, and your own will not. To install it there, paste this line into the Codespace terminal and press Enter:
curl -fsSL https://opencode.ai/install | bash
Once the Codespace is running, pick one agent. Both work the same way in the browser, and you can switch later.
Using OpenCode
- In the terminal at the bottom of the window, type
opencodeand press Enter. - Type
/connect, select OpenRouter, and paste your API key. - Type
/modelsand select GLM-5.3-Flash.
Using Copilot
- Click the chat icon near the top of the window to open the Chat panel. It is already signed in with your GitHub account, so no extra sign-in is needed.
- Click the model picker at the bottom of the chat box → Other Models.
- Settings (gear) icon → Add Models → OpenRouter → paste key.
- Pick GLM-5.3-Flash in the Chat model picker.
When you're done: commit and push your work (you can ask the agent to do this for you), then delete the Codespace (github.com/codespaces → ... → Delete). Anything you didn't push is lost when the Codespace is deleted, and an idle Codespace keeps using your free monthly hours until you delete it.
Worth doing: apply for GitHub Education with your university email. Verified students get up to 180 Codespaces core-hours per month, far more than the standard free allowance.
OpenCode Desktop App
A standalone app for your own computer, with no terminal, no Git Bash and no Node.js. Works the same way on Mac and Windows.
- Go to https://opencode.ai/download and download the version for your computer (on a Mac, the Apple menu → About This Mac tells you whether you have an Apple Silicon or an Intel chip).
- Install it: on macOS, open the
.dmgand drag OpenCode into Applications. On Windows, run the downloaded installer. - Open OpenCode and open the folder you want to work in: your course folder, or any new folder you make for your work.
- Open Settings (look for a gear icon) → Connect provider → find OpenRouter in the list → click Connect → paste your API key.
- If OpenRouter doesn't show up in the model list right away, quit and reopen OpenCode. Then pick GLM-5.3-Flash.
VS Code + OpenCode (Mac)
Runs OpenCode inside VS Code's own terminal, so your files and the agent are in the same window.
On Windows, use the OpenCode Desktop App instead. The terminal install needs Node.js and extra tools, and takes much longer to set up.
- Install VS Code from https://code.visualstudio.com/Download: download the
.dmg, open it, and drag Visual Studio Code.app into Applications. - In VS Code, open the folder you want to work in (File → Open Folder), then open a terminal with Terminal → New Terminal.
- Install OpenCode: paste this line into the terminal and press Enter.
curl -fsSL https://opencode.ai/install | bash
- Close that terminal and open a new one (Terminal → New Terminal) so it picks up the new command. If you skip this, typing
opencodewill say command not found. The install worked, but the old terminal has not noticed it yet. - Type
opencodeand press Enter. Then type/connect, select OpenRouter, and paste your API key. - Type
/modelsand select GLM-5.3-Flash.
VS Code + Copilot (your own computer)
For your own Mac or Windows computer. No terminal needed.
- Install VS Code from https://code.visualstudio.com/Download:
- Windows: download the standard System Installer, which is fine here since it is your own computer.
- macOS: download the
.dmg, open it, and drag Visual Studio Code.app into Applications.
- Activate Copilot (first time): click the chat icon near the top of the window to open the Chat panel. If you don't see it, open the Extensions view (the square-icon button in the left sidebar), search for GitHub Copilot Chat, click Install, then look for the chat icon again. In the Chat panel, click Sign in to GitHub and follow the prompts in your browser. No paid subscription is needed, because your OpenRouter key pays for the model.
- Add your key: click the model picker at the bottom of the chat box → Other Models → settings (gear) icon → Add Models → OpenRouter → paste key.
- Pick GLM-5.3-Flash in the Chat model picker.
要決定的只有兩件事,而且之後都可以隨時改。
用哪個助手?OpenCode 和 GitHub Copilot 都能幫你撰寫和執行代碼。OpenCode 在終端機視窗裡運行;Copilot 則在 VS Code 的聊天面板裡。
在哪裡工作?在瀏覽器裡使用 GitHub Codespaces,所用的電腦無須安裝任何軟件;或在自己的電腦上安裝一次,日後直接使用。
在學校電腦室請使用 Codespaces:這類電腦通常無法安裝 Python、Git 等軟件,而 Codespace 所需的一切都已在裡面準備好。用自己的電腦則可自由選擇。
下面的選項就是這兩者的組合。無論選哪一種,最後都會走到同一個結果:助手連上你的 OpenRouter 金鑰。
學校電腦室
這類電腦常常無法安裝軟件(Python、Git、VS Code 等),也不會預先裝好任何工具。請使用 Codespaces:只需要網頁瀏覽器和你的 GitHub 帳號。
Codespaces:在瀏覽器裡,不需要安裝任何東西,OpenCode 或 Copilot 皆可使用。
自己的電腦(Mac 或 Windows)
你可以自由安裝需要的軟件。
Windows 與 Mac
OpenCode 桌面版:單一下載檔,不需終端機。
VS Code + Copilot:在編輯器裡操作,用標準安裝即可。
Codespaces:在瀏覽器裡,不需要安裝任何東西,OpenCode 或 Copilot 皆可使用。
僅限 Mac
VS Code + OpenCode:在 VS Code 的終端機裡執行助手。
不論選哪一種方案,最重要的是:每次做完都要把成果 commit 並 push 到你的 GitHub 倉庫。只有這樣才能保存下來。只留在 Codespace 或學校電腦上的檔案,最後都會消失。可以直接請助手幫你 commit 和 push。
開始前
- 註冊 GitHub 帳號。每一種方案都需要,你的成果都存放在這裡。
- 到 keyreg.qhchina.org 領取你的 OpenRouter API 金鑰,課程代碼見課程大綱。請妥善保管。
瀏覽器:GitHub Codespaces
Codespace 是運行在 GitHub 伺服器上的一台電腦,你透過瀏覽器來使用它。因為工作都在那邊進行,你面前的電腦不必安裝任何東西,Python 和 Git 也已在裡面準備好。所以它最適合學校電腦室的機器,用在自己的電腦上同樣好用。
- Codespace 必須建立在 GitHub 倉庫上,所以請先建立倉庫:前往模板 qh-starter,按綠色的 Use this template 按鈕,建立自己的倉庫。
- 打開你新建的倉庫 → 綠色 Code 按鈕 → Codespaces → Create codespace on main。首次啟動需數分鐘。
你也可以不用模板,改用自己新建的倉庫:建立時加一個 README.md,倉庫才不是空的,然後用同樣方式開 Codespace。差別在於:模板的 Codespace 已經裝好 OpenCode,自己建的則沒有。要自行安裝,請把下面這行貼進 Codespace 的終端機,按 Enter:
curl -fsSL https://opencode.ai/install | bash
Codespace 啟動後,選一個助手即可。兩個在瀏覽器裡都能用,之後也可以隨時換。
使用 OpenCode
- 在視窗下方的終端機輸入
opencode,按 Enter。 - 輸入
/connect,選擇 OpenRouter,貼上你的 API 金鑰。 - 輸入
/models,選擇 GLM-5.3-Flash。
使用 Copilot
- 按視窗上方的聊天圖示,打開 Chat 面板。它已用你的 GitHub 帳號登入,不需要再另外登入。
- 按聊天輸入框下方的模型選擇器 → Other Models。
- 設定(齒輪)圖示 → Add Models → OpenRouter → 貼上金鑰。
- 在模型選擇器中選擇 GLM-5.3-Flash。
做完後:先 commit、push(可以直接請助手幫你做),再刪除 Codespace(github.com/codespaces → ... → Delete)。尚未推送的內容,Codespace 一刪就找不回來;閒置的 Codespace 也會持續消耗每月免費時數,直到被刪除。
建議一做:用你的大學電郵申請 GitHub Education。通過驗證的學生每月最多可用 180 個 Codespaces core hours,遠多於一般免費額度。
OpenCode 桌面版
一個裝在自己電腦上的獨立應用程式,不需終端機、不需 Git Bash、不需 Node.js。Mac 與 Windows 做法完全相同。
- 前往 https://opencode.ai/download,下載適合你電腦的版本(Mac 可在蘋果選單 → 關於這台 Mac 查看是 Apple Silicon 還是 Intel 晶片)。
- 安裝:macOS 打開
.dmg,把 OpenCode 拖進 Applications;Windows 執行下載好的安裝程式。 - 打開 OpenCode,開啟你要使用的資料夾:課程資料夾,或你為作業新建的任何資料夾皆可。
- 打開 Settings(通常是齒輪圖示)→ Connect provider → 在列表中找到 OpenRouter → 按 Connect → 貼上你的 API 金鑰。
- 若模型列表沒有立即出現 OpenRouter,重新啟動 OpenCode 即可。然後選擇 GLM-5.3-Flash。
VS Code + OpenCode(Mac)
在 VS Code 內建的終端機裡執行 OpenCode,檔案和助手都在同一個視窗裡。
Windows 請改用 OpenCode 桌面版。終端機安裝需要 Node.js 等額外工具,設定起來慢很多。
- 安裝 VS Code:在 https://code.visualstudio.com/Download 下載
.dmg,打開後把 Visual Studio Code.app 拖進 Applications。 - 在 VS Code 開啟你要使用的資料夾(File → Open Folder),再選 Terminal → New Terminal 打開終端機。
- 安裝 OpenCode:把下面這行貼進終端機,按 Enter。
curl -fsSL https://opencode.ai/install | bash
- 關掉這個終端機,再開一個新的(Terminal → New Terminal),新指令才會生效。若略過這一步,輸入
opencode多半會看到 command not found。安裝其實成功了,只是舊的終端機還沒讀到。 - 輸入
opencode按 Enter。接著輸入/connect,選擇 OpenRouter,貼上你的 API 金鑰。 - 輸入
/models,選擇 GLM-5.3-Flash。
VS Code + Copilot(自己的電腦)
適用於自己的 Mac 或 Windows 電腦。不需要終端機。
- 安裝 VS Code,在 https://code.visualstudio.com/Download 下載:
- Windows:直接下載標準的 System Installer 即可,因為是自己的電腦,不必擔心管理員權限。
- macOS:下載
.dmg,打開後把 Visual Studio Code.app 拖進 Applications。
- 啟用 Copilot(僅首次):按 VS Code 視窗上方的聊天圖示,打開 Chat 面板。若看不到,先打開左側邊欄的擴充功能檢視(方形圖示的按鈕),搜尋 GitHub Copilot Chat,按 Install 安裝,再回頭找聊天圖示。在 Chat 面板按 Sign in to GitHub,依瀏覽器提示完成登入。不需要付費訂閱,模型費用由你的 OpenRouter 金鑰支付。
- 加入金鑰:按聊天輸入框下方的模型選擇器 → Other Models → 設定(齒輪)圖示 → Add Models → OpenRouter → 貼上金鑰。
- 在模型選擇器中選擇 GLM-5.3-Flash。