Skip to content

[FEATURE]: NotebookEdit tool for Jupyter notebook cell-level editing #20487

Closed

Description

@borealBytes

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

  • NotebookEdit requires WorkspaceWrite permission
  • All three edit modes (replace, insert, delete) are implemented
  • replace preserves existing cell metadata and outputs (only source is updated)
  • Invalid cell_id returns a clear error listing valid cell IDs
  • The tool creates a snapshot-compatible backup before editing (consistent with OpenCode's existing snapshot behavior)
  • Malformed .ipynb files return a parse error, not a silent failure

Related / cross-reference

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 might be a duplicate of existing issues. Please check:

    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.

  3. rekram1-node commented on Apr 1, 2026

    @rekram1-node
    Contributor

    closing due to issue spam

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