How to get diff colors in custom tool output #4163

Open
opened 2026-02-16 17:42:51 -05:00 by yindo · 4 comments
Owner

Originally created by @dwood023 on GitHub (Jan 4, 2026).

Originally assigned to: @rekram1-node on GitHub.

Question

Using the custom tool helper, you can only return text (not other metadata I see related to the output of built-in tools like edit and write).

If this text contains markdown, it seems to get rendered successfully by opencode, allowing features such as bold or italic text to be outputted by custom tools. 😄

However, I have been trying to render output with colors, such as an embedded "diff":

import { tool } from "@opencode-ai/plugin";

export default tool({
	description: "Test if colored output works in custom tools",
	args: {},
	async execute(args) {
		const diffMarkdown = `\`\`\`diff
- This is a removed line
+ This is a new line
\`\`\``;
		return `Does **this** render in bold?\n\n${diffMarkdown}`;
	},
});

In the output, while the bold text renders correctly, the diff section is coloured uniformly, suggesting syntax highlighting doesn't work.

Image

However, it actually works when I output a snippet of typescript.

import { tool } from "@opencode-ai/plugin";

export default tool({
	description: "Test if colored output works in custom tools",
	args: {},
	async execute(args) {
		const tsCode = `\`\`\`ts
function hello() {
  console.log("Hello");
}
\`\`\``;
		return `Does **this** render in bold?\n\n${tsCode}`;
	},
});
Image

I tried to figure out exactly how syntax highlighting works in opencode, and found some packages such as marked and shiki involved. Shiki seems to bundle support for the diff format, so I would expect it to work.

One complication I see is that diffs are rendered separately in many places using @pierre/diffs, such as for the edit and write scripts. I thought about trying to leverage a similar mechanism to color my outputs, but it's not entirely appropriate for my use case, as my diffs are not really between files.

My use case is basically to run some test-like scripts through an opencode tool and have them color their outputs in green and red for easy readability by a human.

Originally created by @dwood023 on GitHub (Jan 4, 2026). Originally assigned to: @rekram1-node on GitHub. ### Question Using the custom tool helper, you can only return text (not other metadata I see related to the output of built-in tools like edit and write). If this text contains markdown, it seems to get rendered successfully by opencode, allowing features such as bold or italic text to be outputted by custom tools. 😄 However, I have been trying to render output with colors, such as an embedded "diff": ```ts import { tool } from "@opencode-ai/plugin"; export default tool({ description: "Test if colored output works in custom tools", args: {}, async execute(args) { const diffMarkdown = `\`\`\`diff - This is a removed line + This is a new line \`\`\``; return `Does **this** render in bold?\n\n${diffMarkdown}`; }, }); ``` In the output, while the bold text renders correctly, the diff section is coloured uniformly, suggesting syntax highlighting doesn't work. <img width="600" height="145" alt="Image" src="https://github.com/user-attachments/assets/4620d150-5d0e-498d-92f1-a53437e22c52" /> However, it actually works when I output a snippet of typescript. ```ts import { tool } from "@opencode-ai/plugin"; export default tool({ description: "Test if colored output works in custom tools", args: {}, async execute(args) { const tsCode = `\`\`\`ts function hello() { console.log("Hello"); } \`\`\``; return `Does **this** render in bold?\n\n${tsCode}`; }, }); ``` <img width="498" height="149" alt="Image" src="https://github.com/user-attachments/assets/ba10fbac-dbe2-4e61-8277-4435ad4bd1e7" /> I tried to figure out exactly how syntax highlighting works in opencode, and found some packages such as marked and shiki involved. Shiki seems to bundle support for the diff format, so I would expect it to work. One complication I see is that diffs are rendered separately in many places using `@pierre/diffs`, such as for the edit and write scripts. I thought about trying to leverage a similar mechanism to color my outputs, but it's not entirely appropriate for my use case, as my diffs are not really between files. My use case is basically to run some test-like scripts through an opencode tool and have them color their outputs in green and red for easy readability by a human.
yindo added the docs label 2026-02-16 17:42:51 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 4, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #5915: Feature: Integrate Glamour for syntax-highlighted markdown rendering

This is about syntax highlighting for markdown code blocks (including diffs) in the UI. Your use case of colored diff/test output would likely be resolved by implementing proper syntax highlighting as described in that issue.

Feel free to ignore if this doesn't address your specific case.

@github-actions[bot] commented on GitHub (Jan 4, 2026): This issue might be a duplicate of existing issues. Please check: - #5915: Feature: Integrate Glamour for syntax-highlighted markdown rendering This is about syntax highlighting for markdown code blocks (including diffs) in the UI. Your use case of colored diff/test output would likely be resolved by implementing proper syntax highlighting as described in that issue. Feel free to ignore if this doesn't address your specific case.
Author
Owner

@dwood023 commented on GitHub (Jan 4, 2026):

Also, I see the bash tool's output is not colorised like the output would be in a regular terminal. Is there any way to render the colors in opencode?

@dwood023 commented on GitHub (Jan 4, 2026): Also, I see the bash tool's output is not colorised like the output would be in a regular terminal. Is there any way to render the colors in opencode?
Author
Owner

@yanosh-k commented on GitHub (Jan 18, 2026):

I was trying to implement custom tool output in the tool itself and trough a custom plugin that might hook into the tool.execute.after, but both did not work.

From digging around the source code and the GitHub issues - it seems that custom/MCP tools output is not rendered at all (see https://github.com/anomalyco/opencode/issues/6604) , so what you are seeing as rendered content is probably the model's output while thinking.

@yanosh-k commented on GitHub (Jan 18, 2026): I was trying to implement custom tool output in the tool itself and trough a custom plugin that might hook into the `tool.execute.after`, but both did not work. From digging around the source code and the GitHub issues - it seems that custom/MCP tools output is not rendered at all (see https://github.com/anomalyco/opencode/issues/6604) , so what you are seeing as rendered content is probably the model's output while thinking.
Author
Owner

@gtrak commented on GitHub (Feb 16, 2026):

This seems really limiting. I was trying out a custom edit tool and couldn't find a way around the tool output restrictions. I see stdout from a CLI tool overwriting the TUI, and I can't find a way to even get a primitive output back into the TUI window properly.

Image
@gtrak commented on GitHub (Feb 16, 2026): This seems really limiting. I was trying out a [custom edit tool ](https://github.com/gtrak/hashline-tools) and couldn't find a way around the tool output restrictions. I see stdout from a CLI tool overwriting the TUI, and I can't find a way to even get a primitive output back into the TUI window properly. <img width="2231" height="1059" alt="Image" src="https://github.com/user-attachments/assets/4a5beed0-dc46-4b1a-a6bf-0493d3d272bf" />
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4163