Skip to content

Conversation

@yuguorui
Copy link
Contributor

What does this PR do?

Implements client-side PTC, allowing models to execute JavaScript code that orchestrates multiple tool calls in a single execution context.

Why:

  • Claude Code implements this server-side (see [1])
  • OpenCode's client-side approach offers: context savings (no round-trips), model-agnostic (works with any provider)

Without PTC:

  • Each tool call requires a full model round-trip
  • Context grows linearly with tool calls
  • Complex multi-step operations are verbose and slow

Tools added:

  • ptc: Execute async JS with access to all tools via tools.*
  • ptc_list: List available tools with TypeScript signatures

Features:

  • Independent UI tracking per sub-tool call
  • Permission enforcement inherited from parent context
  • 5-minute timeout protection

Enable: OPENCODE_EXPERIMENTAL_PTC=true

Closes #4713

How did you verify your code works?

  • verified by hand and the tools works normally

[1] https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@yuguorui yuguorui changed the title feat(tool): add PTC (Programmatic Tool Calling) support feat(tool): add new PTC tools for client-side Programmatic Tool Calling Jan 21, 2026
Implements client-side PTC, allowing models to execute JavaScript code that
orchestrates multiple tool calls in a single execution context.

Why:
- Claude Code implements this server-side (see [1])
- OpenCode's client-side approach offers: context savings (no round-trips),
  model-agnostic (works with any provider)

Without PTC:
- Each tool call requires a full model round-trip
- Context grows linearly with tool calls
- Complex multi-step operations are verbose and slow

Tools added:
- `ptc`: Execute async JS with access to all tools via `tools.*`
- `ptc_list`: List available tools with TypeScript signatures

Features:
- Independent UI tracking per sub-tool call
- Permission enforcement inherited from parent context
- 5-minute timeout protection

Enable: OPENCODE_EXPERIMENTAL_PTC=true

Signed-off-by: yuguorui <[email protected]>
---
[1] https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Claude Advanced Tool Usage

1 participant