Repository navigation
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Note: The original aggregated RFC I posted has been broken up. This issue focuses on one specific feature: a Rust-backed (or Worker-offloaded) async diff engine, inspired by the independently-derived claw-code Rust implementation. The other areas from the original RFC that already have open issues are linked below for cross-reference.
Describe the enhancement you want to request
Problem
The createTwoFilesPatch call in the write and patch tools runs synchronously on the main thread using a pure-JS Myers diff (O(N²) in line count). On files larger than ~500 lines this visibly blocks the Node.js/Bun event loop — users see Preparing write... or Preparing patch... hang for several seconds before the permission prompt appears. This is already documented in #20477.
The root fix is to move diff computation off the main thread. The opportunity here is to go further and adopt a Rust-backed diff engine, which is what claw-code implements for exactly this reason — the Rust similar / imara-diff crates are 10–50x faster than JS Myers implementations for large files and run in a separate OS thread.
Proposed solution
Two-tier implementation:
-
Immediate (pure JS): Move
createTwoFilesPatchinto aWorkerthread so it never blocks the event loop. This is a small, low-risk change that fixes write/edit freezes when writing long content ("Preparing write..." hangs) #20477 regardless of anything else. -
Follow-on (optional native): Add an optional NAPI native addon (
packages/opencode/src/tool/diff-native/) wrapping claw-code's Rust diff crate. The JS Worker path becomes the fallback when the native addon isn't compiled/available (e.g., CI, container, unsupported arch).
// packages/opencode/src/tool/diff.ts
// Resolves to native NAPI binding if available, falls back to Worker thread
export async function createPatchAsync(
originalPath: string,
original: string,
updated: string
): Promise {
if (NativeDiff.isAvailable()) {
return NativeDiff.createPatch(originalPath, original, updated)
}
return WorkerDiff.createPatch(originalPath, original, updated)
}Why claw-code specifically
claw-code (instructkr/claw-code/rust) is an open-source, independently-derived Rust reimplementation of agentic coding tool primitives — it is not derived from any proprietary source. Its diff module uses imara-diff which produces unified diffs compatible with the existing patch format OpenCode already consumes. License compatibility with OpenCode's MIT license should be verified before bundling.
Acceptance criteria
- Diff operations on files up to 10k lines complete in under 100ms without blocking the event loop
- Worker thread fallback works in all existing environments (Linux, macOS, Windows, containers)
- Native NAPI addon is opt-in at build time (
OPENCODE_NATIVE_DIFF=1), not required - Existing diff output format (unified patch) is byte-for-byte compatible with current behavior
- License compatibility of claw-code Rust crates confirmed before any native bundling
Related / cross-reference
Previously linked:
- Async diff / write freeze: write/edit freezes when writing long content ("Preparing write..." hangs) #20477 (this issue directly addresses that)
- Background task result batching: [FEATURE]: Silent result collection for background tasks to avoid consuming LLM turns #20460
- Tool result cache / session loop perf: [FEATURE]: Session loop performance — message cache, tool cache, doom loop optimization, summary debounce, parallel plugin events #20285, [FEATURE]: Session loop performance — doom loop in-memory, summary debounce, parallel plugin events #20302
- Context summarization / auto-memory: [FEATURE]: Native auto-memory for cross-session learning #20322
- Orchestrator-executor topology / coordinator shell: [FEATURE]: Coordinator shell + fork mode #20368, [FEATURE]: Add hidden field to skill frontmatter to exclude skills from agent selection #20474
- Learnings from claude-code source: Lessons from claude-code-main? #20475
New claw-code derived feature requests (filed 2026-04-01):
- AI-callable Config tool: [FEATURE]: AI-callable Config tool for runtime self-configuration by agents #20481
- SendUserMessage / proactive sub-agent notifications: [FEATURE]: SendUserMessage / Brief tool for proactive async notifications from sub-agents #20482
- Sub-agent tool-set isolation by role: [FEATURE]: Sub-agent tool-set isolation by role (Explore / Plan / Verification scopes) #20483
- TodoWrite parallel workflow + verificationNudgeNeeded: [FEATURE]: TodoWrite parallel workflow support + verificationNudgeNeeded signal #20484
- StructuredOutput tool for typed agent data exchange: [FEATURE]: StructuredOutput tool for reliable typed data extraction from sub-agents #20485
- Sleep tool for non-blocking agent waits: [FEATURE]: Sleep tool for agents to wait without holding a shell process #20486
- NotebookEdit tool for Jupyter cell-level editing: [FEATURE]: NotebookEdit tool for Jupyter notebook cell-level editing #20487
- REPL tool for isolated language-specific execution: [FEATURE]: REPL tool for isolated language-specific code execution separate from bash #20488
- ToolSearch for lazy/deferred tool discovery: [FEATURE]: ToolSearch for lazy/deferred tool discovery to reduce per-turn context size #20489
Activity
github-actions commentedon Apr 1, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
[RFC]but this project requires one of three issue templates: Bug Report, Feature Request (title must start with[FEATURE]:), or Question. Please resubmit using the appropriate template.Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue substantially overlaps with several existing open issues. Please review these before resubmitting:
If you believe this was flagged incorrectly, please let a maintainer know.
[-][RFC] Port high-value Claude Code techniques + claw-code Rust primitives into OpenCode core[/-][+][FEATURE]: Rust-backed async diff engine via claw-code (fixes write/edit freeze + unlocks claw-code Rust primitives)[/+]github-actions commentedon Apr 1, 2026
Thanks for updating the issue! It now clearly follows the Feature Request template — the verification checkbox is checked, the problem (event-loop blocking diff) is well described, and the proposed solution is concrete and scoped. Everything looks good.
rekram1-node commentedon Apr 1, 2026
closing due to issue spam
manalkaff commentedon Apr 3, 2026
is it merged? this fucking tool stuck is killing me man. im running ralph loop and it just wont finish. opencode is unusable @rekram1-node @thdxr