index.mdx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 AI coding agent built for the terminal.
  9. ![opencode TUI with the opencode theme](../../assets/lander/screenshot.png)
  10. Let's get started.
  11. ---
  12. #### Prerequisites
  13. To use opencode, 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:
  27. - **Using Node.js**
  28. <Tabs>
  29. <TabItem label="npm">```bash npm install -g opencode-ai ```</TabItem>
  30. <TabItem label="Bun">```bash bun install -g opencode-ai ```</TabItem>
  31. <TabItem label="pnpm">```bash pnpm install -g opencode-ai ```</TabItem>
  32. <TabItem label="Yarn">```bash yarn global add opencode-ai ```</TabItem>
  33. </Tabs>
  34. - **Using Homebrew on macOS and Linux**
  35. ```bash
  36. brew install sst/tap/opencode
  37. ```
  38. - **Using Paru on Arch Linux**
  39. ```bash
  40. paru -S opencode-bin
  41. ```
  42. #### Windows
  43. Currently, the automatic installation methods do not work properly on Windows. However you can grab the binary from the [Releases](https://github.com/sst/opencode/releases).
  44. ---
  45. ## Configure
  46. With opencode you can use any LLM provider by configuring their API keys.
  47. If you are new to using LLM providers, we recommend using [opencode zen](/docs/zen).
  48. It's a curated list of models that have been tested and verified by the opencode
  49. team.
  50. 1. Sign in to **<a href={console}>opencode zen</a>** and put in your billing
  51. details.
  52. 2. Copy your API key.
  53. 3. Run `opencode auth login`, select opencode, and add your API key.
  54. ```bash
  55. $ opencode auth login
  56. ┌ Add credential
  57. ◆ Select provider
  58. │ ● opencode
  59. │ ...
  60. ```
  61. Alternatively, you can select one of the other providers. [Learn more](/docs/providers#directory).
  62. ---
  63. ## Initialize
  64. Now that you've configured a provider, you can navigate to a project that
  65. you want to work on.
  66. ```bash
  67. cd /path/to/project
  68. ```
  69. And run opencode.
  70. ```bash
  71. opencode
  72. ```
  73. Next, initialize opencode for the project by running the following command.
  74. ```bash frame="none"
  75. /init
  76. ```
  77. This will get opencode to analyze your project and create an `AGENTS.md` file in
  78. the project root.
  79. :::tip
  80. You should commit your project's `AGENTS.md` file to Git.
  81. :::
  82. This helps opencode understand the project structure and the coding patterns
  83. used.
  84. ---
  85. ## Usage
  86. You are now ready to use opencode to work on your project. Feel free to ask it
  87. anything!
  88. If you are new to using an AI coding agent, here are some examples that might
  89. help.
  90. ---
  91. ### Ask questions
  92. You can ask opencode to explain the codebase to you.
  93. :::tip
  94. Use the `@` key to fuzzy search for files in the project.
  95. :::
  96. ```txt frame="none" "@packages/functions/src/api/index.ts"
  97. How is authentication handled in @packages/functions/src/api/index.ts
  98. ```
  99. This is helpful if there's a part of the codebase that you didn't work on.
  100. ---
  101. ### Add features
  102. You can ask opencode to add new features to your project. Though we first recommend asking it to create a plan.
  103. 1. **Create a plan**
  104. opencode has a _Plan mode_ that disables its ability to make changes and
  105. instead suggest _how_ it'll implement the feature.
  106. Switch to it using the **Tab** key. You'll see an indicator for this in the lower right corner.
  107. ```bash frame="none" title="Switch to Plan mode"
  108. <TAB>
  109. ```
  110. Now let's describe what we want it to do.
  111. ```txt frame="none"
  112. When a user deletes a note, we'd like to flag it as deleted in the database.
  113. Then create a screen that shows all the recently deleted notes.
  114. From this screen, the user can undelete a note or permanently delete it.
  115. ```
  116. You want to give opencode enough details to understand what you want. It helps
  117. to talk to it like you are talking to a junior developer on your team.
  118. :::tip
  119. Give opencode plenty of context and examples to help it understand what you
  120. want.
  121. :::
  122. 2. **Iterate on the plan**
  123. Once it gives you a plan, you can give it feedback or add more details.
  124. ```txt frame="none"
  125. We'd like to design this new screen using a design I've used before.
  126. [Image #1] Take a look at this image and use it as a reference.
  127. ```
  128. :::tip
  129. Drag and drop images into the terminal to add them to the prompt.
  130. :::
  131. opencode can scan any images you give it and add them to the prompt. You can
  132. do this by dragging and dropping an image into the terminal.
  133. 3. **Build the feature**
  134. Once you feel comfortable with the plan, switch back to _Build mode_ by
  135. hitting the **Tab** key again.
  136. ```bash frame="none"
  137. <TAB>
  138. ```
  139. And asking it to make the changes.
  140. ```bash frame="none"
  141. Sounds good! Go ahead and make the changes.
  142. ```
  143. ---
  144. ### Make changes
  145. For more straightforward changes, you can ask opencode to directly build it
  146. without having to review the plan first.
  147. ```txt frame="none" "@packages/functions/src/settings.ts" "@packages/functions/src/notes.ts"
  148. We need to add authentication to the /settings route. Take a look at how this is
  149. handled in the /notes route in @packages/functions/src/notes.ts and implement
  150. the same logic in @packages/functions/src/settings.ts
  151. ```
  152. You want to make sure you provide a good amount of detail so opencode makes the right
  153. changes.
  154. ---
  155. ### Undo changes
  156. Let's say you ask opencode to make some changes.
  157. ```txt frame="none" "@packages/functions/src/api/index.ts"
  158. Can you refactor the function in @packages/functions/src/api/index.ts?
  159. ```
  160. But you realize that it is not what you wanted. You **can undo** the changes
  161. using the `/undo` command.
  162. ```bash frame="none"
  163. /undo
  164. ```
  165. opencode will now revert the changes you made and show your original message
  166. again.
  167. ```txt frame="none" "@packages/functions/src/api/index.ts"
  168. Can you refactor the function in @packages/functions/src/api/index.ts?
  169. ```
  170. From here you can tweak the prompt and ask opencode to try again.
  171. :::tip
  172. You can run `/undo` multiple times to undo multiple changes.
  173. :::
  174. Or you **can redo** the changes using the `/redo` command.
  175. ```bash frame="none"
  176. /redo
  177. ```
  178. ---
  179. ## Share
  180. The conversations that you have with opencode can be [shared with your
  181. team](/docs/share).
  182. ```bash frame="none"
  183. /share
  184. ```
  185. This will create a link to the current conversation and copy it to your clipboard.
  186. :::note
  187. Conversations are not shared by default.
  188. :::
  189. Here's an [example conversation](https://opencode.ai/s/4XP1fce5) with opencode.
  190. ---
  191. ## Customize
  192. And that's it! You are now a pro at using opencode.
  193. 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).