tools.mdx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. ---
  2. title: Tools
  3. description: Verwalte, welche Tools ein LLM nutzen darf.
  4. ---
  5. Tools erlauben dem LLM Aktionen in deiner Codebasis.
  6. OpenCode bringt eingebaute Tools mit und laesst sich ueber [Custom Tools](/docs/custom-tools) oder [MCP-Server](/docs/mcp-servers) erweitern.
  7. Standardmaessig sind alle Tools **aktiviert** und brauchen keine Freigabe.
  8. Das Verhalten steuerst du ueber [Berechtigungen](/docs/permissions).
  9. ---
  10. ## Konfiguration
  11. Nutze das Feld `permission`, um Tool-Verhalten zu steuern.
  12. Pro Tool kannst du erlauben, verbieten oder eine Rueckfrage verlangen.
  13. ```json title="opencode.json"
  14. {
  15. "$schema": "https://opencode.ai/config.json",
  16. "permission": {
  17. "edit": "deny",
  18. "bash": "ask",
  19. "webfetch": "allow"
  20. }
  21. }
  22. ```
  23. Mit Wildcards kannst du mehrere Tools auf einmal steuern.
  24. Zum Beispiel, um fuer alle Tools eines MCP-Servers eine Freigabe zu verlangen:
  25. ```json title="opencode.json"
  26. {
  27. "$schema": "https://opencode.ai/config.json",
  28. "permission": {
  29. "mymcp_*": "ask"
  30. }
  31. }
  32. ```
  33. [Mehr dazu](/docs/permissions), wie du Berechtigungen konfigurierst.
  34. ---
  35. ## Eingebaut
  36. Hier sind alle in OpenCode verfuegbaren eingebauten Tools.
  37. ---
  38. ### bash
  39. Fuehrt Shell-Befehle in deiner Projektumgebung aus.
  40. ```json title="opencode.json" {4}
  41. {
  42. "$schema": "https://opencode.ai/config.json",
  43. "permission": {
  44. "bash": "allow"
  45. }
  46. }
  47. ```
  48. Damit kann das LLM Terminal-Befehle wie `npm install`, `git status` oder andere Shell-Kommandos ausfuehren.
  49. ---
  50. ### edit
  51. Bearbeitet bestehende Dateien ueber exakte String-Ersetzungen.
  52. ```json title="opencode.json" {4}
  53. {
  54. "$schema": "https://opencode.ai/config.json",
  55. "permission": {
  56. "edit": "allow"
  57. }
  58. }
  59. ```
  60. Dieses Tool fuehrt praezise Aenderungen per exakter Textsuche aus.
  61. Es ist der zentrale Weg, wie das LLM Code aendert.
  62. ---
  63. ### write
  64. Erstellt neue Dateien oder ueberschreibt bestehende Dateien.
  65. ```json title="opencode.json" {4}
  66. {
  67. "$schema": "https://opencode.ai/config.json",
  68. "permission": {
  69. "edit": "allow"
  70. }
  71. }
  72. ```
  73. Damit erlaubst du dem LLM, neue Dateien anzulegen.
  74. Bestehende Dateien werden dabei ueberschrieben.
  75. :::note
  76. Das Tool `write` wird ueber die Berechtigung `edit` gesteuert.
  77. `edit` gilt fuer alle Datei-Aenderungen (`edit`, `write`, `patch`, `multiedit`).
  78. :::
  79. ---
  80. ### read
  81. Read file contents from your codebase.
  82. ```json title="opencode.json" {4}
  83. {
  84. "$schema": "https://opencode.ai/config.json",
  85. "permission": {
  86. "read": "allow"
  87. }
  88. }
  89. ```
  90. This tool reads files and returns their contents. It supports reading specific line ranges for large files.
  91. ---
  92. ### grep
  93. Search file contents using regular expressions.
  94. ```json title="opencode.json" {4}
  95. {
  96. "$schema": "https://opencode.ai/config.json",
  97. "permission": {
  98. "grep": "allow"
  99. }
  100. }
  101. ```
  102. Fast content search across your codebase. Supports full regex syntax and file pattern filtering.
  103. ---
  104. ### glob
  105. Find files by pattern matching.
  106. ```json title="opencode.json" {4}
  107. {
  108. "$schema": "https://opencode.ai/config.json",
  109. "permission": {
  110. "glob": "allow"
  111. }
  112. }
  113. ```
  114. Search for files using glob patterns like `**/*.js` or `src/**/*.ts`. Returns matching file paths sorted by modification time.
  115. ---
  116. ### list
  117. List files and directories in a given path.
  118. ```json title="opencode.json" {4}
  119. {
  120. "$schema": "https://opencode.ai/config.json",
  121. "permission": {
  122. "list": "allow"
  123. }
  124. }
  125. ```
  126. This tool lists directory contents. It accepts glob patterns to filter results.
  127. ---
  128. ### lsp (experimental)
  129. Interact with your configured LSP servers to get code intelligence features like definitions, references, hover info, and call hierarchy.
  130. :::note
  131. This tool is only available when `OPENCODE_EXPERIMENTAL_LSP_TOOL=true` (or `OPENCODE_EXPERIMENTAL=true`).
  132. :::
  133. ```json title="opencode.json" {4}
  134. {
  135. "$schema": "https://opencode.ai/config.json",
  136. "permission": {
  137. "lsp": "allow"
  138. }
  139. }
  140. ```
  141. Supported operations include `goToDefinition`, `findReferences`, `hover`, `documentSymbol`, `workspaceSymbol`, `goToImplementation`, `prepareCallHierarchy`, `incomingCalls`, and `outgoingCalls`.
  142. To configure which LSP servers are available for your project, see [LSP Servers](/docs/lsp).
  143. ---
  144. ### patch
  145. Apply patches to files.
  146. ```json title="opencode.json" {4}
  147. {
  148. "$schema": "https://opencode.ai/config.json",
  149. "permission": {
  150. "edit": "allow"
  151. }
  152. }
  153. ```
  154. This tool applies patch files to your codebase. Useful for applying diffs and patches from various sources.
  155. :::note
  156. The `patch` tool is controlled by the `edit` permission, which covers all file modifications (`edit`, `write`, `patch`, `multiedit`).
  157. :::
  158. ---
  159. ### skill
  160. Load a [skill](/docs/skills) (a `SKILL.md` file) and return its content in the conversation.
  161. ```json title="opencode.json" {4}
  162. {
  163. "$schema": "https://opencode.ai/config.json",
  164. "permission": {
  165. "skill": "allow"
  166. }
  167. }
  168. ```
  169. ---
  170. ### todowrite
  171. Manage todo lists during coding sessions.
  172. ```json title="opencode.json" {4}
  173. {
  174. "$schema": "https://opencode.ai/config.json",
  175. "permission": {
  176. "todowrite": "allow"
  177. }
  178. }
  179. ```
  180. Creates and updates task lists to track progress during complex operations. The LLM uses this to organize multi-step tasks.
  181. :::note
  182. This tool is disabled for subagents by default, but you can enable it manually. [Learn more](/docs/agents/#permissions)
  183. :::
  184. ---
  185. ### todoread
  186. Read existing todo lists.
  187. ```json title="opencode.json" {4}
  188. {
  189. "$schema": "https://opencode.ai/config.json",
  190. "permission": {
  191. "todoread": "allow"
  192. }
  193. }
  194. ```
  195. Reads the current todo list state. Used by the LLM to track what tasks are pending or completed.
  196. :::note
  197. This tool is disabled for subagents by default, but you can enable it manually. [Learn more](/docs/agents/#permissions)
  198. :::
  199. ---
  200. ### webfetch
  201. Fetch web content.
  202. ```json title="opencode.json" {4}
  203. {
  204. "$schema": "https://opencode.ai/config.json",
  205. "permission": {
  206. "webfetch": "allow"
  207. }
  208. }
  209. ```
  210. Allows the LLM to fetch and read web pages. Useful for looking up documentation or researching online resources.
  211. ---
  212. ### websearch
  213. Search the web for information.
  214. :::note
  215. This tool is only available when using the OpenCode provider or when the `OPENCODE_ENABLE_EXA` environment variable is set to any truthy value (e.g., `true` or `1`).
  216. To enable when launching OpenCode:
  217. ```bash
  218. OPENCODE_ENABLE_EXA=1 opencode
  219. ```
  220. :::
  221. ```json title="opencode.json" {4}
  222. {
  223. "$schema": "https://opencode.ai/config.json",
  224. "permission": {
  225. "websearch": "allow"
  226. }
  227. }
  228. ```
  229. Performs web searches using Exa AI to find relevant information online. Useful for researching topics, finding current events, or gathering information beyond the training data cutoff.
  230. No API key is required — the tool connects directly to Exa AI's hosted MCP service without authentication.
  231. :::tip
  232. Use `websearch` when you need to find information (discovery), and `webfetch` when you need to retrieve content from a specific URL (retrieval).
  233. :::
  234. ---
  235. ### question
  236. Ask the user questions during execution.
  237. ```json title="opencode.json" {4}
  238. {
  239. "$schema": "https://opencode.ai/config.json",
  240. "permission": {
  241. "question": "allow"
  242. }
  243. }
  244. ```
  245. This tool allows the LLM to ask the user questions during a task. It's useful for:
  246. - Gathering user preferences or requirements
  247. - Clarifying ambiguous instructions
  248. - Getting decisions on implementation choices
  249. - Offering choices about what direction to take
  250. Each question includes a header, the question text, and a list of options. Users can select from the provided options or type a custom answer. When there are multiple questions, users can navigate between them before submitting all answers.
  251. ---
  252. ## Benutzerdefinierte Tools
  253. Mit Custom Tools definierst du eigene Funktionen, die das LLM aufrufen kann.
  254. Sie werden in der Konfigurationsdatei definiert und koennen beliebigen Code ausfuehren.
  255. [Mehr dazu](/docs/custom-tools), wie du Custom Tools erstellst.
  256. ---
  257. ## MCP-Server
  258. MCP-Server (Model Context Protocol) binden externe Tools und Dienste ein.
  259. Dazu gehoeren Datenbanken, API-Integrationen und Drittanbieter-Services.
  260. [Mehr dazu](/docs/mcp-servers), wie du MCP-Server konfigurierst.
  261. ---
  262. ## Interna
  263. Intern verwenden Tools wie `grep`, `glob` und `list` [ripgrep](https://github.com/BurntSushi/ripgrep).
  264. Standardmaessig beachtet ripgrep `.gitignore`, daher werden dort aufgefuehrte Dateien und Ordner nicht durchsucht.
  265. ---
  266. ### Ignorier-Muster
  267. Wenn du normalerweise ignorierte Dateien einschliessen willst, lege im Projekt-Root eine `.ignore`-Datei an.
  268. Dort kannst du Pfade explizit erlauben.
  269. ```text title=".ignore"
  270. !node_modules/
  271. !dist/
  272. !build/
  273. ```
  274. Dieses Beispiel erlaubt ripgrep, in `node_modules/`, `dist/` und `build/` zu suchen, auch wenn sie in `.gitignore` stehen.