|
1 | 1 | --- |
2 | 2 | title: CLI |
3 | | -description: The opencode CLI options and commands. |
| 3 | +description: opencode CLI options and commands. |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | import { Tabs, TabItem } from "@astrojs/starlight/components" |
7 | 7 |
|
8 | | -Running the opencode CLI starts it for the current directory. |
| 8 | +The opencode CLI accepts commands as documented on this page. You can run any of the available commands to interact with opencode programmatically. |
9 | 9 |
|
10 | 10 | ```bash |
11 | | -opencode |
| 11 | +opencode run "Explain how closures work in JavaScript" |
12 | 12 | ``` |
13 | 13 |
|
14 | | -Or you can start it for a specific working directory. |
15 | | - |
16 | | -```bash |
17 | | -opencode /path/to/project |
18 | | -``` |
19 | | - |
20 | | ---- |
21 | | - |
22 | | -## Slash commands |
23 | | - |
24 | | -When using the opencode CLI, you can type `/` followed by a command name to quickly execute actions. For example: |
25 | | - |
26 | | -:::tip |
27 | | -You can also use `@` to reference files in your messages. |
28 | | -::: |
29 | | - |
30 | | -```bash frame="none" |
31 | | -/help |
32 | | -``` |
33 | | - |
34 | | -Here are all available slash commands: |
35 | | - |
36 | | -- **`/help`** |
37 | | - |
38 | | - Show the help dialog. |
39 | | - |
40 | | -- **`/editor`** |
41 | | - |
42 | | - Open external editor for composing messages. Uses the editor set in your `EDITOR` environment variable. [Learn more](#editor-setup). |
43 | | - |
44 | | -- **`/export`** |
45 | | - |
46 | | - Export current conversation to Markdown and open in your default editor. Uses the editor set in your `EDITOR` environment variable. [Learn more](#editor-setup). |
47 | | - |
48 | | -- **`/new`** |
49 | | - |
50 | | - Start a new session. _Alias_: `/clear` |
51 | | - |
52 | | -- **`/sessions`** |
53 | | - |
54 | | - List and switch between sessions. _Aliases_: `/resume`, `/continue` |
55 | | - |
56 | | -- **`/share`** |
57 | | - |
58 | | - Share current session. [Learn more](/docs/share). |
59 | | - |
60 | | -- **`/unshare`** |
61 | | - |
62 | | - Unshare current session. [Learn more](/docs/share#un-sharing). |
63 | | - |
64 | | -- **`/compact`** |
65 | | - |
66 | | - Compact the current session. _Alias_: `/summarize` |
67 | | - |
68 | | -- **`/details`** |
69 | | - |
70 | | - Toggle tool execution details. |
71 | | - |
72 | | -- **`/models`** |
73 | | - |
74 | | - List available models. |
75 | | - |
76 | | -- **`/themes`** |
77 | | - |
78 | | - List available themes. |
79 | | - |
80 | | -- **`/init`** |
81 | | - |
82 | | - Create or update `AGENTS.md` file. [Learn more](/docs/rules). |
83 | | - |
84 | | -- **`/undo`** |
85 | | - |
86 | | - Undo last message. |
87 | | - |
88 | | -- **`/redo`** |
89 | | - |
90 | | - Redo message. |
91 | | - |
92 | | -- **`/exit`** |
93 | | - |
94 | | - Exit opencode. _Aliases_: `/quit`, `/q` |
95 | | - |
96 | | ---- |
97 | | - |
98 | | -### Bash commands |
99 | | - |
100 | | -Start a line with `!` to run a shell command. The output is added to the conversation as a tool result. |
101 | | - |
102 | | -```bash frame="none" |
103 | | -!ls -la |
104 | | -``` |
105 | | - |
106 | | ---- |
107 | | - |
108 | | -### Editor setup |
109 | | - |
110 | | -Both the `/editor` and `/export` commands use the editor specified in your `EDITOR` environment variable. |
111 | | - |
112 | | -<Tabs> |
113 | | - <TabItem label="Linux/macOS"> |
114 | | - ```bash export EDITOR=nano # or vim, code, etc. ``` To make it permanent, add this to your shell profile; |
115 | | - `~/.bashrc`, `~/.zshrc`, etc. |
116 | | - </TabItem> |
117 | | - <TabItem label="Windows (CMD)"> |
118 | | - ```bash set EDITOR=notepad # or code, vim, etc. ``` To make it permanent, use **System Properties** > **Environment |
119 | | - Variables**. |
120 | | - </TabItem> |
121 | | - <TabItem label="Windows (PowerShell)"> |
122 | | - ```bash $env:EDITOR = "notepad" # or "code", "vim", etc. ``` To make it permanent, add this to your PowerShell |
123 | | - profile. |
124 | | - </TabItem> |
125 | | -</Tabs> |
126 | | - |
127 | | -Popular editor options include: |
128 | | - |
129 | | -- `code` - Visual Studio Code |
130 | | -- `vim` - Vim editor |
131 | | -- `nano` - Nano editor |
132 | | -- `notepad` - Windows Notepad |
133 | | -- `subl` - Sublime Text |
134 | | - |
135 | 14 | --- |
136 | 15 |
|
137 | 16 | ## Commands |
|
0 commit comments