move— relocate complete code blocks inside an OpenCode worktree. Designed for agents that would otherwise copy code to a new location and then delete the original.
The tool is intentionally narrow: it moves text safely. It does not update imports, exports, references, formatting, or surrounding code semantics.
Add opencode-move-tool to your OpenCode plugin configuration:
// opencode.json or .opencode/opencode.json
{
"plugin": ["opencode-move-tool"]
}Or use the CLI:
opencode plugin opencode-move-toolOpenCode installs plugins automatically on startup — no manual npm install required.
- Read the source and destination files.
- Call
movewithdry_run=true. - Review
preview.removed_textandpreview.inserted_text. - Re-run the same call with
dry_run=false. - Update imports, exports, references, and formatting manually.
- Run diagnostics/tests.
move({
source_file: "src/utils.ts",
destination_file: "src/validation.ts",
start_line: 42,
end_line: 68,
insert_mode: "append",
dry_run: true,
})move({
source_file: "src/utils.ts",
destination_file: "src/validation.ts",
start_line: 42,
end_line: 68,
insert_mode: "before_line",
insert_line: 12,
dry_run: true,
})insert_line is valid only with insert_mode="before_line" or insert_mode="after_line".
move({
source_file: "src/app.ts",
destination_file: "src/app.ts",
start_line: 120,
end_line: 150,
insert_mode: "after_line",
insert_line: 45,
dry_run: true,
})Same-file insert_line uses the original file's line numbers. Inserting inside or adjacent to the moved range is rejected.
| Argument | Type | Required | Description |
|---|---|---|---|
source_file |
string |
Yes | Source file inside the current worktree. |
destination_file |
string |
Yes | Destination file inside the current worktree. Created on apply if missing. |
start_line |
number |
Yes | 1-based inclusive source start line. |
end_line |
number |
No | 1-based inclusive source end line. Defaults to start_line. |
insert_mode |
"append" | "prepend" | "after_line" | "before_line" |
No | Destination placement. Defaults to append. |
insert_line |
number |
For after_line/before_line |
1-based destination anchor line. |
adjust_indentation |
boolean |
No | Defaults to false. Best-effort leading-whitespace adjustment. |
dry_run |
boolean |
No | Defaults to true. Set false only after reviewing the preview. |
dry_rundefaults totrue.insert_modedefaults toappend.adjust_indentationdefaults tofalse.- Paths must stay inside the current worktree. Absolute paths are allowed only inside the worktree.
- Destination files may be created, but destination parents must resolve inside the worktree.
- Cross-file writes use best-effort rollback, not a true filesystem transaction.
- Do not use for partial-line edits.
- Do not use to update imports or references.
- Do not use when generating brand-new code.
- Do not skip reading the files first; the tool needs precise block boundaries.
- Do not apply (
dry_run=false) until the dry-run preview is correct.
- Rejects paths that escape the worktree, including symlink/junction escapes for existing files.
- Preserves CRLF/LF style and final-newline state for moved complete lines.
- Computes source and destination contents before writing.
- Uses backups and cleanup for best-effort rollback on write failure.
- Does not update code semantics.
# Install dependencies
bun install
# Type check
bun run typecheck
# Run tests
bun test
# Build
bun run buildRequires Bun and Node.js >= 20.
MIT