Skip to content

[FEATURE]: Rust-backed async diff engine via claw-code (fixes write/edit freeze + unlocks claw-code Rust primitives) #20479

Closed

Description

@borealBytes

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:

  1. Immediate (pure JS): Move createTwoFilesPatch into a Worker thread 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.

  2. 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:

New claw-code derived feature requests (filed 2026-04-01):

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 1, 2026
  2. github-actions commented on Apr 1, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • The title uses [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.
    • This appears to be a Feature Request but is missing the required verification checkbox confirming the feature hasn't been suggested before.
    • The issue is a large aggregated RFC covering 5 separate feature areas — each should be its own focused issue using the proper template.
    • The description reads as AI-generated content (structured tables, emoji section headers, code stubs, implementation estimates). We ask that issues reflect genuine, human-written context.

    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.

  3. changed the title [-][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)[/+] on Apr 1, 2026
  4. github-actions commented on Apr 1, 2026

    @github-actions
    Contributor

    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.

  5. rekram1-node commented on Apr 1, 2026

    @rekram1-node
    Contributor

    closing due to issue spam

  6. manalkaff commented on Apr 3, 2026

    @manalkaff

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions