Skip to content
Back to search

opencode-morph-fast-apply

OpenCode plugin for Morph Fast Apply - 10x faster code editing with lazy edit markers. No MCP server needed.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/jredeker--opencode-morph-fast-apply/badge.svg)](/listings/jredeker--opencode-morph-fast-apply)

HTML

<a href="/listings/jredeker--opencode-morph-fast-apply"><img src="/api/listings/jredeker--opencode-morph-fast-apply/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

OpenCode version support

| OpenCode version | Support | Notes | | --------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | V2 (2.x) | Yes | Loads through the V2 plugin API (`setup`). Edits are confined to the session's directory, resolved per invocation. | | V1 1.18.29+ | Yes | Loads through the V1 `default.server` adapter with the same `morph_edit` behavior. | | V1 older than 1.18.29 | **No** | These loaders do not read the dual-entry default export, so the plugin silently does not load. Upgrade OpenCode or pin an older plugin release. |

1. Add the plugin and always-on instruction to your OpenCode config

Preferred when your setup syncs packaged instructions into `~/.config/opencode/instructions/`:

OpenCode V2 (2.x) reads the plural `plugins` key. Add to your global config (`~/.config/opencode/opencode.json`):

{
  "instructions": ["~/.config/opencode/instructions/morph-tools.md"],
  "plugins": ["github:JRedeker/opencode-morph-fast-apply"]
}

Pin only a release that contains the V2 entrypoint. Version `v1.11.0` contains the V1-only entrypoint and cannot load on V2.

OpenCode V1 (1.18.29+) reads the singular `plugin` key. Do not use `plugin` on V2 — V2 ignores it and the plugin will not load:

{
  "instructions": ["~/.config/opencode/instructions/morph-tools.md"],
  "plugin": ["github:JRedeker/opencode-morph-fast-apply"]
}

To keep the existing V1 release on OpenCode V1, pin its tag:

{
  "plugin": ["github:JRedeker/opencode-morph-fast-apply#v1.11.0"]
}

Recommended setup summary:

- Prefer the stable synced instruction path: `~/.config/opencode/instructions/morph-tools.md` - Use the packaged `node_modules/.../morph-tools.md` path only when your setup does not sync instructions - Keep the routing policy in the OpenCode `instructions` array, not a skill

If you are installing the plugin directly and do not sync packaged instructions into `~/.config/opencode/instructions/`, you can point OpenCode at the packaged file instead. Use `plugins` on V2 and `plugin` on V1:

{
  "instructions": [
    "~/.config/opencode/node_modules/opencode-morph-fast-apply/instructions/morph-tools.md"
  ],
  "plugins": ["github:JRedeker/opencode-morph-fast-apply"]
}
{
  "instructions": [
    "~/.config/opencode/node_modules/opencode-morph-fast-apply/instructions/morph-tools.md"
  ],
  "plugin": ["github:JRedeker/opencode-morph-fast-apply"]
}

The `morph_edit` tool description remains self-contained, but for more reliable tool selection you should also load the packaged always-on instruction file shown above. This avoids agents defaulting to native `edit` when `morph_edit` is the better fit for large, scattered, or whitespace-sensitive edits.

Important: the active agent must also expose `morph_edit` in its tool manifest. If an agent profile marks `morph_edit: false`, the model cannot choose Morph even when the plugin is installed and the always-on instruction is present.

2. Set your Morph API key

Get an API key at [morphllm.com/dashboard](https://morphllm.com/dashboard/api-keys), then add it to the environment that starts OpenCode:

export MORPH_API_KEY="sk-your-key-here"

The plugin reads `MORPH_API_KEY` from the OpenCode process environment when it loads. Setting the variable in an unrelated shell does not update already-running OpenCode sessions.

3. Restart OpenCode

The `morph_edit` tool will now be available.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 321 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. # opencode-morph-fast-apply
  2. [![CI](https://github.com/JRedeker/opencode-morph-fast-apply/actions/workflows/ci.yml/badge.svg)](https://github.com/JRedeker/opencode-morph-fast-apply/actions/workflows/ci.yml)
  3. [![GitHub release](https://img.shields.io/github/v/release/JRedeker/opencode-morph-fast-apply)](https://github.com/JRedeker/opencode-morph-fast-apply/releases/latest)
  4. [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
  5. OpenCode plugin for [Morph Fast Apply](https://morphllm.com) - 10x faster code editing with lazy edit markers.
  6. ## Features
  7. - **10,500+ tokens/sec** code editing via Morph's Fast Apply API
  8. - **Lazy edit markers** (`// ... existing code ...`) - no exact string matching needed
  9. - **98% accuracy** with intelligent code merging
  10. - **Pre-flight validation** - prevents accidental file deletions when markers are missing
  11. - **Unified diff output** with context for easy review
  12. - **Custom TUI display** - branded titles like `Morph: src/file.ts +15/-3 (450ms)`
  13. - **OpenCode V2 native** - registers through the V2 plugin API; edits are confined to the session's directory per invocation
  14. - **Graceful fallback** - suggests native `edit` tool on API failure
  15. > **Note:** This is an OpenCode plugin that wraps Morph's Fast Apply API. For the official Morph MCP server (which includes WarpGrep search), see [@morphllm/morphmcp](https://www.npmjs.com/package/@morphllm/morphmcp). This plugin uses `morph_edit` as the tool name to avoid conflicts if you have both installed.
  16. ## Installation
  17. ### OpenCode version support
  18. | OpenCode version | Support | Notes |
  19. | --------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
  20. | V2 (2.x) | Yes | Loads through the V2 plugin API (`setup`). Edits are confined to the session's directory, resolved per invocation. |
  21. | V1 1.18.29+ | Yes | Loads through the V1 `default.server` adapter with the same `morph_edit` behavior. |
  22. | V1 older than 1.18.29 | **No** | These loaders do not read the dual-entry default export, so the plugin silently does not load. Upgrade OpenCode or pin an older plugin release. |
  23. ### 1. Add the plugin and always-on instruction to your OpenCode config
  24. Preferred when your setup syncs packaged instructions into `~/.config/opencode/instructions/`:
  25. OpenCode V2 (2.x) reads the plural `plugins` key. Add to your global config (`~/.config/opencode/opencode.json`):
  26. ```json
  27. {
  28. "instructions": ["~/.config/opencode/instructions/morph-tools.md"],
  29. "plugins": ["github:JRedeker/opencode-morph-fast-apply#v1.12.0"]
  30. }
  31. ```
  32. Version `v1.12.0` supports both OpenCode V2 and V1 1.18.29+.
  33. OpenCode V1 (1.18.29+) reads the singular `plugin` key. Do not use `plugin` on V2 — V2 ignores it and the plugin will not load:
  34. ```json
  35. {
  36. "instructions": ["~/.config/opencode/instructions/morph-tools.md"],
  37. "plugin": ["github:JRedeker/opencode-morph-fast-apply#v1.12.0"]
  38. }
  39. ```
  40. Recommended setup summary:
  41. - Prefer the stable synced instruction path: `~/.config/opencode/instructions/morph-tools.md`
  42. - Use the packaged `node_modules/.../morph-tools.md` path only when your setup does not sync instructions
  43. - Keep the routing policy in the OpenCode `instructions` array, not a skill
  44. If you are installing the plugin directly and do not sync packaged instructions into
  45. `~/.config/opencode/instructions/`, you can point OpenCode at the packaged file
  46. instead. Use `plugins` on V2 and `plugin` on V1:
  47. ```json
  48. {
  49. "instructions": [
  50. "~/.config/opencode/node_modules/opencode-morph-fast-apply/instructions/morph-tools.md"
  51. ],
  52. "plugins": ["github:JRedeker/opencode-morph-fast-apply#v1.12.0"]
  53. }
  54. ```
  55. ```json
  56. {
  57. "instructions": [
  58. "~/.config/opencode/node_modules/opencode-morph-fast-apply/instructions/morph-tools.md"
  59. ],
  60. "plugin": ["github:JRedeker/opencode-morph-fast-apply#v1.12.0"]
  61. }
  62. ```
  63. The `morph_edit` tool description remains self-contained, but for more reliable
  64. tool selection you should also load the packaged always-on instruction file
  65. shown above. This avoids agents defaulting to native `edit` when `morph_edit`
  66. is the better fit for large, scattered, or whitespace-sensitive edits.
  67. Important: the active agent must also expose `morph_edit` in its tool manifest.
  68. If an agent profile marks `morph_edit: false`, the model cannot choose Morph
  69. even when the plugin is installed and the always-on instruction is present.
  70. ### 2. Set your Morph API key
  71. Get an API key at [morphllm.com/dashboard](https://morphllm.com/dashboard/api-keys), then add it to the environment that starts OpenCode:
  72. ```bash
  73. export MORPH_API_KEY="sk-your-key-here"
  74. ```
  75. The plugin reads `MORPH_API_KEY` from the OpenCode process environment when it
  76. loads. Setting the variable in an unrelated shell does not update
  77. already-running OpenCode sessions.
  78. ### 3. Restart OpenCode
  79. The `morph_edit` tool will now be available.
  80. ## Usage
  81. The LLM uses `morph_edit` for efficient partial file edits:
  82. ```
  83. morph_edit({
  84. target_filepath: "src/auth.ts",
  85. instructions: "I am adding error handling for invalid tokens",
  86. code_edit: `// ... existing code ...
  87. function validateToken(token) {
  88. if (!token) {
  89. throw new Error("Token is required");
  90. }
  91. // ... existing code ...
  92. }
  93. // ... existing code ...`
  94. })
  95. ```
  96. ### When to use `morph_edit` vs `edit`
  97. | Situation | Tool | Reason |
  98. | -------------------------- | ------------ | ------------------------- |
  99. | Small, exact replacement | `edit` | Fast, no API call |
  100. | Large file (500+ lines) | `morph_edit` | Handles partial snippets |
  101. | Multiple scattered changes | `morph_edit` | Batch efficiently |
  102. | Whitespace-sensitive | `morph_edit` | Forgiving with formatting |
  103. ## Configuration
  104. | Variable | Default | Description |
  105. | --------------- | -------------------------- | ------------------------ |
  106. | `MORPH_API_KEY` | (required) | Your Morph API key |
  107. | `MORPH_API_URL` | `https://api.morphllm.com` | API endpoint |
  108. | `MORPH_MODEL` | `morph-v3-fast` | Model to use (see below) |
  109. | `MORPH_TIMEOUT` | `30000` | Request timeout in ms |
  110. ### Available Models
  111. | Model | Speed | Accuracy | Best For |
  112. | ---------------- | -------------------- | -------- | ------------------------------------------------- |
  113. | `morph-v3-fast` | 10,500+ tok/sec | 96% | Real-time applications, quick edits |
  114. | `morph-v3-large` | 5,000+ tok/sec | 98% | Complex changes, highest accuracy |
  115. | `auto` | 5,000-10,500 tok/sec | ~98% | Recommended - automatically selects optimal model |
  116. ## How It Works
  117. 1. Reads the original file content
  118. 2. Sends to Morph API:
  119. - `<instruction>` - Your intent description
  120. - `<code>` - The complete original file
  121. - `<update>` - Your partial edit with markers
  122. 3. Morph intelligently merges the lazy edit markers with original code
  123. 4. Writes the merged result back to the file
  124. 5. Returns a unified diff showing what changed
  125. ## Troubleshooting
  126. ### "MORPH_API_KEY not configured"
  127. Ensure the environment variable is set and exported in the shell or service that
  128. starts OpenCode:
  129. ```bash
  130. echo $MORPH_API_KEY # Should show your key
  131. ```
  132. After changing `MORPH_API_KEY`, restart OpenCode so the plugin reloads with the
  133. updated OpenCode process environment.
  134. ### Timeout errors
  135. Increase the timeout for large files:
  136. ```bash
  137. export MORPH_TIMEOUT=60000 # 60 seconds
  138. ```
  139. ### Unexpected deletions
  140. If code is being deleted unexpectedly, ensure your `code_edit` includes `// ... existing code ...` markers at the start and end. Omitting these markers tells Morph to replace the entire file.
  141. ### Safety guards
  142. The plugin blocks unsafe Morph responses before writing files:
  143. - **Marker leakage guard**: If merged output contains `// ... existing code ...` but the original file did not, the write is aborted.
  144. - **Catastrophic truncation guard**: If merged output loses more than 60% of characters **and** more than 50% of lines (for marker-based edits), the write is aborted.
  145. - **Dropped imports guard**: If top-level import identifiers present in the original file are missing from the merged output, the write is aborted. This catches silent import loss that can occur when edits fall outside the anchoring context.
  146. - **Path confinement**: Edits open their file and directories beneath the invoking session's allowed root (V1 context worktree/directory, or V2 session directory) and use only those opened objects, so a concurrent symlink swap cannot redirect them. A new file another process creates at the destination during the edit is never silently overwritten: publication is an atomic create-if-absent link (requiring hard-link support in the target directory's filesystem) and the edit fails instead. Paths outside that root, including sibling worktrees, are rejected. Any symlink in the root or target path, a file with more than one hard link, and a nonregular target are refused. Confinement requires Linux with procfs; other hosts refuse every edit. Start a session in an ad-hoc worktree to edit within it. Arguments cannot select another root.
  147. - **Replacement access metadata**: Existing files require Bun FFI and Linux glibc (`libc.so.6`) on x64 or arm64 for descriptor-based `flistxattr` inspection. Unavailable inspection, inspection errors, and visible extended attributes (including POSIX ACLs) refuse the edit before reading content. Source metadata is rechecked before reading and replacing. A replacement starts with private `0600` staging; inherited attributes or a different owner/group abort it before content is written. Source and replacement metadata are checked again before publication. Successful replacements keep ordinary permission bits and owner/group, but change inode identity and drop special mode bits. New files retain kernel-applied umask and default ACL semantics without requiring metadata inspection. Inspection cannot detect attributes the kernel hides from the caller, and checks do not serialize concurrent metadata changes; no protection against privileged metadata changes or hostile code in the plugin process is claimed.
  148. - **Object lifetime**: Authority follows the opened objects, not their former paths. If another process moves an opened directory outside the session root, Morph may still edit files or create new files and directories through it. Replacing the old path with an outside symlink cannot redirect the edit to that symlink's referent.
  149. - **Secret scrubbing**: API error messages are automatically scrubbed to prevent leaking your `MORPH_API_KEY` or Bearer tokens in tool output.
  150. Merge-guard errors include recovery options such as tighter anchors or native `edit`. A root refusal names the allowed root and directs you to native `edit` or `apply_patch` with the absolute path, only when that tool is exposed and permitted for the target. Never retry a refused absolute target as a relative path: that can name a different file inside the session root. `workdir` and `taskId` are unsupported and are rejected when received by either adapter.
  151. ### Markdown-fenced `code_edit` input
  152. If an AI agent wraps `code_edit` in markdown fences (for example, ` ```typescript ... ``` `), `morph_edit` strips the outer fence before sending content to Morph.
  153. ### Wrong edit location
  154. If edits are applied to the wrong location, add more unique context around your changes and make your `instructions` more specific about which function/section you're modifying.
  155. ### Native edit recovery
  156. When a native `edit` reports an unmatched or ambiguous exact target:
  157. 1. Re-read the target file before any retry.
  158. 2. Do not repeat the unchanged failed `edit` input.
  159. 3. Make at most one corrected native `edit` only when the re-read proves the change is still small and exact.
  160. 4. Otherwise use `morph_edit` for the contextual repair — multi-line, scattered, whitespace-sensitive, or broader anchoring.
  161. 5. Use `write` only for new-file or intentional full-file replacement.
  162. This recovery sequence is separate from the Morph API-error/timeout fallback, which still recovers to native `edit`.
  163. ### Tool blocked in plan/explore mode
  164. The `morph_edit` tool is disabled in readonly agent modes (`plan`, `explore`). Switch to a build/code mode to make edits.
  165. ## Changelog
  166. For the full release history, see [CHANGELOG.md](CHANGELOG.md).
  167. ### v1.12.0
  168. - **OpenCode V2 support** — Registers `morph_edit` through the V2 plugin API and resolves the invoking session directory for each edit. OpenCode V1 1.18.29+ remains supported; older V1 loaders are unsupported.
  169. - **Structured edit outcomes** — Returns `status`, a stable `code`, `truncated`, and readable `text`. V1 exposes machine fields in metadata; V2 exposes schema-declared output and metadata. The truncation flag identifies shortened diff output, not shortened file writes.
  170. - **File I/O errors** — Creation write failures report `write_failed` instead of a read failure. File I/O errors are scrubbed before returning them.
  171. ### v1.10.2
  172. - **Native edit recovery policy** — The embedded `morph_edit` description, the packaged always-on instruction, and the README now share the same bounded recovery sequence for a failed native exact `edit`: re-read the target, do not repeat unchanged input, allow at most one corrected native edit only when still small and exact, otherwise hand off to `morph_edit` for contextual repair. The existing Morph API-error/timeout → native `edit` fallback is preserved.
  173. - **Drift regression tests** — Content-level tests assert the recovery policy is present and consistent across all three routing surfaces.
  174. ### v1.8.2
  175. - **Tool exposure requirement docs** — `instructions/morph-tools.md` now documents that agent profiles must expose `morph_edit: true` in their tool manifest for the routing policy to take effect
  176. - **README alignment** — Installation section notes the tool manifest requirement alongside the always-on instruction
  177. - **Test coverage** — Tests verify the tool exposure section exists in the instruction file and README
  178. ### v1.8.1
  179. - **Stable instruction path guidance** - README now prefers `~/.config/opencode/instructions/morph-tools.md` and keeps the packaged `node_modules/...` path as a fallback for direct installs
  180. - **Canonical routing policy wording** - `instructions/morph-tools.md` now explicitly says morph routing belongs in always-on instructions, not a skill
  181. - **Docs/test alignment** - Tests now verify the stable instruction path and canonical policy wording
  182. ### v1.8.0
  183. - **Packaged always-on instruction** - `instructions/morph-tools.md` now ships with the plugin so OpenCode can load reliable `morph_edit` selection guidance through the `instructions` array
  184. - **Packaging coverage** - package metadata now includes the `instructions/` directory, and tests verify that the shipped instruction path is documented
  185. - **Installation docs updated** - README now recommends adding the packaged always-on instruction to global OpenCode config for more reliable `morph_edit` selection
  186. ### v1.7.0
  187. - **Self-contained tool description** — Core `morph_edit` guidance still lives in the tool description so the tool is usable even without extra setup.
  188. - **Packaged always-on instruction** — `instructions/morph-tools.md` can be added to your OpenCode `instructions` array so agents choose `morph_edit` more reliably.
  189. - **Removed skill pattern** — Deleted `skills/morph/SKILL.md` and `MORPH_INSTRUCTIONS.md`. The skill added a round-trip and split-brain problem where guidance lived in multiple places.
  190. - **Removed `MORPH_SKILL_LOAD_HINT`** — Agents no longer need to load a skill before using `morph_edit`.
  191. ### v1.6.0
  192. - **Post-merge safety guards** - Blocks unsafe Morph output before writing to disk:
  193. - **Marker leakage guard** - Detects when merge model treats `// ... existing code ...` as literal text
  194. - **Truncation guard** - Dual-metric validation (>60% char + >50% line loss) prevents silent data loss
  195. - **Input normalization** - Strips markdown fences from `code_edit` to prevent merge confusion
  196. - **TUI guard titles** - Shows `Morph: blocked (marker leakage)` or `Morph: blocked (truncation)` on guard failures
  197. - **32 test cases** - Comprehensive coverage of normalization, leakage detection, and truncation edge cases
  198. ### v1.5.0
  199. - **Custom TUI display** - Tool output shows branded titles like `Morph: src/file.ts +15/-3 (450ms)`
  200. - **API timing** - Response time tracked and displayed in tool title
  201. - **Structured metadata** - Provider, version, model info included for future TUI enhancements
  202. ### v1.4.0
  203. - **Fixed stdout pollution** - Replaced `console.log`/`console.warn` with `client.app.log()` SDK method
  204. - **Readonly agent protection** - Blocks `morph_edit` in `plan` and `explore` modes to prevent accidental edits
  205. - **Stderr fallback** - Graceful logging if SDK method unavailable
  206. ### v1.3.0
  207. - **Pre-flight validation prevents accidental deletions** - Tool now returns an error if `code_edit` is missing markers for files >10 lines, preventing catastrophic code loss
  208. - **Improved code_edit parameter description** - Changed from "Only the changed lines" to "The code changes wrapped with markers" to emphasize wrapping
  209. - **Added explicit wrapping rule** - Tool description now includes "ALWAYS wrap your changes with markers at the start AND end"
  210. - **Restored comprehensive examples** - `MORPH_INSTRUCTIONS.md` now includes all key examples (adding functions, modifying code, deletions)
  211. - **Added Quick Reference** - Aligned with Morph's official agent instructions format
  212. - **Added fetch timeout example** - From official Morph documentation
  213. ### v1.2.0
  214. - **Tool schema aligned with Morph official spec** - Tool description now matches [Morph's recommended format](https://docs.morphllm.com/quickstart)
  215. - **Concise AI agent instructions** - `MORPH_INSTRUCTIONS.md` reduced by 72% (237→67 lines) while keeping critical guidance
  216. - **Added marker validation warning** - Server logs warn when `code_edit` is missing markers (helps debug unexpected deletions)
  217. - **Documentation improvements** - Added troubleshooting section, model comparison table, updated config paths
  218. ### v1.1.0
  219. - Initial public release
  220. - Morph Fast Apply integration with lazy edit markers
  221. - Unified diff output
  222. - Graceful fallback suggestions
  223. ## Contributing
  224. Contributions welcome! This plugin could potentially be integrated into OpenCode core.
  225. This project uses Bun. The `bun.lock` lockfile is tracked in git; `pnpm-lock.yaml` and `package-lock.json` are ignored.
  226. ## License
  227. [MIT](LICENSE)

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.