index.mdx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. ---
  2. title: Intro
  3. description: Get started with OpenCode.
  4. ---
  5. import { Tabs, TabItem } from "@astrojs/starlight/components"
  6. import config from "../../../config.mjs"
  7. export const console = config.console
  8. [**OpenCode**](/) is an open source AI coding agent. It's available as a terminal-based interface, desktop app, or IDE extension.
  9. ![OpenCode TUI with the opencode theme](../../assets/lander/screenshot.png)
  10. Let's get started.
  11. ---
  12. #### Prerequisites
  13. To use OpenCode in your terminal, you'll need:
  14. 1. A modern terminal emulator like:
  15. - [WezTerm](https://wezterm.org), cross-platform
  16. - [Alacritty](https://alacritty.org), cross-platform
  17. - [Ghostty](https://ghostty.org), Linux and macOS
  18. - [Kitty](https://sw.kovidgoyal.net/kitty/), Linux and macOS
  19. 2. API keys for the LLM providers you want to use.
  20. ---
  21. ## Install
  22. The easiest way to install OpenCode is through the install script.
  23. ```bash
  24. curl -fsSL https://opencode.ai/install | bash
  25. ```
  26. You can also install it with the following commands:
  27. - **Using Node.js**
  28. <Tabs>
  29. <TabItem label="npm">
  30. ```bash
  31. npm install -g opencode-ai
  32. ```
  33. </TabItem>
  34. <TabItem label="Bun">
  35. ```bash
  36. bun install -g opencode-ai
  37. ```
  38. </TabItem>
  39. <TabItem label="pnpm">
  40. ```bash
  41. pnpm install -g opencode-ai
  42. ```
  43. </TabItem>
  44. <TabItem label="Yarn">
  45. ```bash
  46. yarn global add opencode-ai
  47. ```
  48. </TabItem>
  49. </Tabs>
  50. - **Using Homebrew on macOS and Linux**
  51. ```bash
  52. brew install anomalyco/tap/opencode
  53. ```
  54. > We recommend using the OpenCode tap for the most up to date releases. The official `brew install opencode` formula is maintained by the Homebrew team and is updated less frequently.
  55. - **Installing on Arch Linux**
  56. ```bash
  57. sudo pacman -S opencode # Arch Linux (Stable)
  58. paru -S opencode-bin # Arch Linux (Latest from AUR)
  59. ```
  60. #### Windows
  61. :::tip[Recommended: Use WSL]
  62. For the best experience on Windows, we recommend using [Windows Subsystem for Linux (WSL)](/docs/windows-wsl). It provides better performance and full compatibility with OpenCode's features.
  63. :::
  64. - **Using Chocolatey**
  65. ```bash
  66. choco install opencode
  67. ```
  68. - **Using Scoop**
  69. ```bash
  70. scoop install opencode
  71. ```
  72. - **Using NPM**
  73. ```bash
  74. npm install -g opencode-ai
  75. ```
  76. - **Using Mise**
  77. ```bash
  78. mise use -g github:anomalyco/opencode
  79. ```
  80. - **Using Docker**
  81. ```bash
  82. docker run -it --rm ghcr.io/anomalyco/opencode
  83. ```
  84. Support for installing OpenCode on Windows using Bun is currently in progress.
  85. You can also grab the binary from the [Releases](https://github.com/anomalyco/opencode/releases).
  86. ---
  87. ## Configure
  88. With OpenCode you can use any LLM provider by configuring their API keys.
  89. If you are new to using LLM providers, we recommend using [OpenCode Zen](/docs/zen).
  90. It's a curated list of models that have been tested and verified by the OpenCode
  91. team.
  92. 1. Run the `/connect` command in the TUI, select opencode, and head to [opencode.ai/auth](https://opencode.ai/auth).
  93. ```txt
  94. /connect
  95. ```
  96. 2. Sign in, add your billing details, and copy your API key.
  97. 3. Paste your API key.
  98. ```txt
  99. ┌ API key
  100. │
  101. │
  102. └ enter
  103. ```
  104. Alternatively, you can select one of the other providers. [Learn more](/docs/providers#directory).
  105. ---
  106. ## Initialize
  107. Now that you've configured a provider, you can navigate to a project that
  108. you want to work on.
  109. ```bash
  110. cd /path/to/project
  111. ```
  112. And run OpenCode.
  113. ```bash
  114. opencode
  115. ```
  116. Next, initialize OpenCode for the project by running the following command.
  117. ```bash frame="none"
  118. /init
  119. ```
  120. This will get OpenCode to analyze your project and create an `AGENTS.md` file in
  121. the project root.
  122. :::tip
  123. You should commit your project's `AGENTS.md` file to Git.
  124. :::
  125. This helps OpenCode understand the project structure and the coding patterns
  126. used.
  127. ---
  128. ## Usage
  129. You are now ready to use OpenCode to work on your project. Feel free to ask it
  130. anything!
  131. If you are new to using an AI coding agent, here are some examples that might
  132. help.
  133. ---
  134. ### Ask questions
  135. You can ask OpenCode to explain the codebase to you.
  136. :::tip
  137. Use the `@` key to fuzzy search for files in the project.
  138. :::
  139. ```txt frame="none" "@packages/functions/src/api/index.ts"
  140. How is authentication handled in @packages/functions/src/api/index.ts
  141. ```
  142. This is helpful if there's a part of the codebase that you didn't work on.
  143. ---
  144. ### Add features
  145. You can ask OpenCode to add new features to your project. Though we first recommend asking it to create a plan.
  146. 1. **Create a plan**
  147. OpenCode has a _Plan mode_ that disables its ability to make changes and
  148. instead suggest _how_ it'll implement the feature.
  149. Switch to it using the **Tab** key. You'll see an indicator for this in the lower right corner.
  150. ```bash frame="none" title="Switch to Plan mode"
  151. <TAB>
  152. ```
  153. Now let's describe what we want it to do.
  154. ```txt frame="none"
  155. When a user deletes a note, we'd like to flag it as deleted in the database.
  156. Then create a screen that shows all the recently deleted notes.
  157. From this screen, the user can undelete a note or permanently delete it.
  158. ```
  159. You want to give OpenCode enough details to understand what you want. It helps
  160. to talk to it like you are talking to a junior developer on your team.
  161. :::tip
  162. Give OpenCode plenty of context and examples to help it understand what you
  163. want.
  164. :::
  165. 2. **Iterate on the plan**
  166. Once it gives you a plan, you can give it feedback or add more details.
  167. ```txt frame="none"
  168. We'd like to design this new screen using a design I've used before.
  169. [Image #1] Take a look at this image and use it as a reference.
  170. ```
  171. :::tip
  172. Drag and drop images into the terminal to add them to the prompt.
  173. :::
  174. OpenCode can scan any images you give it and add them to the prompt. You can
  175. do this by dragging and dropping an image into the terminal.
  176. 3. **Build the feature**
  177. Once you feel comfortable with the plan, switch back to _Build mode_ by
  178. hitting the **Tab** key again.
  179. ```bash frame="none"
  180. <TAB>
  181. ```
  182. And asking it to make the changes.
  183. ```bash frame="none"
  184. Sounds good! Go ahead and make the changes.
  185. ```
  186. ---
  187. ### Make changes
  188. For more straightforward changes, you can ask OpenCode to directly build it
  189. without having to review the plan first.
  190. ```txt frame="none" "@packages/functions/src/settings.ts" "@packages/functions/src/notes.ts"
  191. We need to add authentication to the /settings route. Take a look at how this is
  192. handled in the /notes route in @packages/functions/src/notes.ts and implement
  193. the same logic in @packages/functions/src/settings.ts
  194. ```
  195. You want to make sure you provide a good amount of detail so OpenCode makes the right
  196. changes.
  197. ---
  198. ### Undo changes
  199. Let's say you ask OpenCode to make some changes.
  200. ```txt frame="none" "@packages/functions/src/api/index.ts"
  201. Can you refactor the function in @packages/functions/src/api/index.ts?
  202. ```
  203. But you realize that it is not what you wanted. You **can undo** the changes
  204. using the `/undo` command.
  205. ```bash frame="none"
  206. /undo
  207. ```
  208. OpenCode will now revert the changes you made and show your original message
  209. again.
  210. ```txt frame="none" "@packages/functions/src/api/index.ts"
  211. Can you refactor the function in @packages/functions/src/api/index.ts?
  212. ```
  213. From here you can tweak the prompt and ask OpenCode to try again.
  214. :::tip
  215. You can run `/undo` multiple times to undo multiple changes.
  216. :::
  217. Or you **can redo** the changes using the `/redo` command.
  218. ```bash frame="none"
  219. /redo
  220. ```
  221. ---
  222. ## Share
  223. The conversations that you have with OpenCode can be [shared with your
  224. team](/docs/share).
  225. ```bash frame="none"
  226. /share
  227. ```
  228. This will create a link to the current conversation and copy it to your clipboard.
  229. :::note
  230. Conversations are not shared by default.
  231. :::
  232. Here's an [example conversation](https://opencode.ai/s/4XP1fce5) with OpenCode.
  233. ---
  234. ## Customize
  235. And that's it! You are now a pro at using OpenCode.
  236. To make it your own, we recommend [picking a theme](/docs/themes), [customizing the keybinds](/docs/keybinds), [configuring code formatters](/docs/formatters), [creating custom commands](/docs/commands), or playing around with the [OpenCode config](/docs/config).