[PR #6852] feat: add ctx.log() for custom tools #12139

Closed
opened 2026-02-16 18:17:04 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6852

State: closed
Merged: No


Fixes #6830 and #6833 by adding ctx.log() for custom tools to avoid console.log output leaking to stdout.

problem:

  • Custom plugins had ctx.client.app.log available to them, but custom tools did not - there was no logger exposed to tools (making it hard to debug)
  • the docs still guided console.log (missed this in #6833)

solution:

  • Added ctx.log(level, message, extra) to ToolContext for custom tool implementations
  • Logs using OpenCode's internal Log.create() API (appropriate since tools execute in-process)
  • Logger instances created once per context to avoid overhead
  • Updated plugin docs to show ctx.log() for custom tools and client.app.log() for plugin initialization
  • Clarified that console.log leaks to stdout

I also had to update test sites for built-in tools to plumb log through into the ToolContext, hence the larger number of changed files here.

Custom tools now have structured logging that writes to OpenCode's log files instead of polluting terminal output.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6852 **State:** closed **Merged:** No --- Fixes #6830 and #6833 by adding `ctx.log()` for custom tools to avoid console.log output leaking to stdout. **problem**: * Custom plugins had `ctx.client.app.log` available to them, but custom tools did not - there was no logger exposed to tools (making it hard to debug) * the docs still guided console.log (missed this in #6833) **solution**: - Added `ctx.log(level, message, extra)` to ToolContext for custom tool implementations - Logs using OpenCode's internal `Log.create()` API (appropriate since tools execute in-process) - Logger instances created once per context to avoid overhead - Updated plugin docs to show `ctx.log()` for custom tools and `client.app.log()` for plugin initialization - Clarified that console.log leaks to stdout I also had to update test sites for built-in tools to plumb `log` through into the `ToolContext`, hence the larger number of changed files here. Custom tools now have structured logging that writes to OpenCode's log files instead of polluting terminal output.
yindo added the pull-request label 2026-02-16 18:17:04 -05:00
yindo closed this issue 2026-02-16 18:17:04 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12139