diff --git a/packages/opencode/src/tool/write.ts b/packages/opencode/src/tool/write.ts index 8c1e53ccaf3a..017838110947 100644 --- a/packages/opencode/src/tool/write.ts +++ b/packages/opencode/src/tool/write.ts @@ -19,7 +19,12 @@ const MAX_PROJECT_DIAGNOSTICS_FILES = 5 export const WriteTool = Tool.define("write", { description: DESCRIPTION, parameters: z.object({ - content: z.string().describe("The content to write to the file"), + content: z + .preprocess( + (v) => (typeof v === "object" && v !== null ? JSON.stringify(v, null, 2) : v), + z.string(), + ) + .describe("The content to write to the file"), filePath: z.string().describe("The absolute path to the file to write (must be absolute, not relative)"), }), async execute(params, ctx) {