GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Plugin tool updates (#2670) · avillagran/opencode@65baf76

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .opencode/tool
    • foo.ts
  • packages/web
    • astro.config.mjs
    • src/content/docs
      • custom-tools.mdx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.opencode/tool/foo.ts‎

Copy file name to clipboard
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import z from "zod/v4"
1+
import { tool } from "@opencode-ai/plugin"
22

3-
export default {
3+
export default tool((z) => ({
44
description: "foo tool for fooing",
55
args: {
66
foo: z.string().describe("foo"),
77
},
88
async execute() {
99
return "Hey fuck you!"
1010
},
11-
}
11+
}))
Collapse file

‎packages/web/astro.config.mjs‎

Copy file name to clipboardExpand all lines: packages/web/astro.config.mjs
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export default defineConfig({
8484
"permissions",
8585
"lsp",
8686
"mcp-servers",
87+
"custom-tools",
8788
],
8889
},
8990

Collapse file

‎packages/web/src/content/docs/custom-tools.mdx‎

Copy file name to clipboard
+105Lines changed: 105 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
title: Custom tools
3+
description: Create custom tools to extend opencode capabilities.
4+
---
5+
6+
Custom tools are functions you create that the LLM can call during conversations. They work alongside opencode's built-in tools like `read`, `write`, and `bash`.
7+
8+
---
9+
10+
## Tool structure
11+
12+
The easiest way to create tools is using the `tool()` helper which provides type safety and validation:
13+
14+
```ts title=".opencode/tool/database.ts"
15+
import { tool } from "@opencode-ai/plugin"
16+
17+
export default tool((z) => ({
18+
description: "Query the project database",
19+
args: {
20+
query: z.string().describe("SQL query to execute"),
21+
},
22+
async execute(args) {
23+
// Your database logic here
24+
return `Executed query: ${args.query}`
25+
},
26+
}))
27+
```
28+
29+
You can also import Zod directly and return a plain object:
30+
31+
```ts
32+
import z from "zod/v4"
33+
34+
export default {
35+
description: "Tool description",
36+
args: {
37+
param: z.string().describe("Parameter description"),
38+
},
39+
async execute(args, context) {
40+
// Tool implementation
41+
return "result"
42+
},
43+
}
44+
```
45+
46+
The filename becomes the tool name. This creates a `database` tool.
47+
48+
---
49+
50+
## Arguments
51+
52+
Use the `z` parameter to define tool arguments with validation and descriptions:
53+
54+
```ts title=".opencode/tool/calculator.ts"
55+
import { tool } from "@opencode-ai/plugin"
56+
57+
export default tool((z) => ({
58+
description: "Perform mathematical calculations",
59+
args: {
60+
expression: z.string().describe("Mathematical expression to evaluate"),
61+
precision: z.number().optional().describe("Decimal precision"),
62+
},
63+
async execute(args) {
64+
// Your calculation logic here
65+
return `Result: ${eval(args.expression).toFixed(args.precision || 2)}`
66+
},
67+
}))
68+
```
69+
70+
---
71+
72+
## Context
73+
74+
Tools receive context about the current session:
75+
76+
```ts title=".opencode/tool/project.ts"
77+
import { tool } from "@opencode-ai/plugin"
78+
79+
export default tool((z) => ({
80+
description: "Get project information",
81+
args: {},
82+
async execute(args, context) {
83+
// Access context information
84+
const { project, directory, worktree } = context
85+
return `Project: ${project.name}, Directory: ${directory}`
86+
},
87+
}))
88+
```
89+
90+
---
91+
92+
## Tool locations
93+
94+
Custom tools are loaded from:
95+
96+
- Project: `.opencode/tool/`
97+
- Global: `~/.config/opencode/tool/`
98+
99+
Files must use `.js` or `.ts` extensions.
100+
101+
---
102+
103+
## Built-in tools
104+
105+
opencode includes several built-in tools: `read`, `write`, `edit`, `bash`, `glob`, `grep`, `list`, `patch`, `todo`, and `task`. [Learn more](/docs/tui#tools).

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.