Closed
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Problem
OpenCode has no Jupyter-aware tool. Agents working on data science, ML, or research codebases must use write_file to overwrite entire .ipynb files. This approach:
- Destroys cell metadata, execution counts, and cell outputs that are not part of the agent's edit
- Makes diffs unreadable (entire file replaced vs. one cell changed)
- Requires the agent to hold the full notebook in context just to change one cell
- Breaks notebook-aware tools downstream (nbconvert, nbformat validation, CI)
claw-code implements a NotebookEdit tool supporting replace, insert, and delete operations at the individual cell level.
Proposed solution
// packages/opencode/src/tool/notebook-edit.ts
export const NotebookEditTool = Tool.define({
name: "NotebookEdit",
description: "Replace, insert, or delete a single cell in a Jupyter notebook (.ipynb) without overwriting the entire file.",
parameters: z.object({
notebook_path: z.string(),
cell_id: z.string().optional(), // target cell (by id or index)
new_source: z.string().optional(), // cell content for replace/insert
cell_type: z.enum(["code", "markdown"]).optional(),
edit_mode: z.enum(["replace", "insert", "delete"]).default("replace")
}),
execute: async (input) => {
const nb = await readNotebook(input.notebook_path)
const result = applyNotebookEdit(nb, input)
await writeNotebook(input.notebook_path, result.notebook)
return {
cell_id: result.cell_id,
cell_type: result.cell_type,
edit_mode: input.edit_mode,
notebook_path: input.notebook_path
}
}
})Supported operations
edit_mode |
Behavior |
|---|---|
replace |
Replaces the source of an existing cell (preserves metadata, outputs, execution count) |
insert |
Inserts a new cell at the specified position |
delete |
Removes a cell entirely |
Why this matters
- Data science / ML / research workflows are a primary OpenCode use case — Jupyter is the dominant notebook format
- Cell-level edits preserve notebook integrity (outputs, metadata) that full-file overwrites destroy
- Dramatically reduces context needed: agent reads only the target cell, not the entire notebook
- Produces clean, reviewable diffs at the cell level
Acceptance criteria
-
NotebookEditrequiresWorkspaceWritepermission - All three edit modes (
replace,insert,delete) are implemented -
replacepreserves existing cell metadata and outputs (onlysourceis updated) - Invalid
cell_idreturns a clear error listing valid cell IDs - The tool creates a snapshot-compatible backup before editing (consistent with OpenCode's existing snapshot behavior)
- Malformed
.ipynbfiles return a parse error, not a silent failure
Related / cross-reference
- claw-code reference: https://github.com/instructkr/claw-code/tree/main/rust (
NotebookEdittool) - Learnings from claude-code source: Lessons from claude-code-main? #20475
- Original RFC: [FEATURE]: Rust-backed async diff engine via claw-code (fixes write/edit freeze + unlocks claw-code Rust primitives) #20479
Metadata
Metadata
Assignees
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)
Activity
github-actions commentedon Apr 1, 2026
This issue might be a duplicate of existing issues. Please check:
edit_notebook_cell,add_notebook_cell,delete_notebook_cell) — largely the same scope as theNotebookEdittool proposed here.Please review that issue and consider adding your input there rather than opening a separate request. If you believe your proposal is sufficiently distinct (e.g. the specific API design or snapshot behavior), please clarify how it differs.
rekram1-node commentedon Apr 1, 2026
closing due to issue spam