- How you use it
- You ask for it
- What it can do
- writes files · runs shell
- What's inside
The option
| Option | ASkill · v1.0.0Check notebook outputs after a cell replacement |
|---|---|
| How you use it | You ask for it |
| What it can do | writes files · runs shell |
| What's inside |
What this thread does
The problem
You ask Claude Code to change a few cells in a Jupyter notebook. A .ipynb file is one JSON document with code, markdown and saved outputs, so a plain text edit can easily corrupt it, and a notebook full of plots can be too large to read in one go.
What the Claude Code docs say
From the tools reference (Anthropic's documentation):
- There is a dedicated NotebookEdit tool that "modifies a Jupyter notebook one cell at a time", targeting cells by their cell_id. It does not do string replacement across the notebook the way Edit does on plain files.
- Its modes include replacing a cell, inserting a cell after a target (with no cell_id the new cell goes at the start; cell_type must be code or markdown), and deleting a cell.
- Read on a .ipynb returns all cells with their outputs. A notebook whose cells come to more than 256 KB, or more than the read token limit, returns an error instead, and a file over 100 MB is refused; the error tells Claude how to read a slice of cells with a shell command.
- NotebookEdit refuses a file that is not valid UTF-8 and writes nothing.
- Permission rules written as Edit(path) also cover NotebookEdit calls, so a rule like Edit(notebooks/**) controls both.
Practical wording for your prompt
Edit the notebook with the notebook tool, one cell at a time. Tell me the cell index and the first line of each cell before you change it. Do not rewrite the whole file and note that replacing a code cell clears its execution count and saved outputs. If the notebook is too large to read, read only the cells you need.
Habits that follow from the docs
- Commit the notebook before the session so a bad edit is a one-command revert.
- If reads fail on size, clear outputs first (with the tool you already use for that) or ask the agent to read a slice of cells.
- Keep notebooks under a path your permission rules name, so edits are allowed or blocked in one place.
Sources
- Claude Code tools reference was read, specifically NotebookEdit and Read. Checked: cell_id targeting; replace, insert and delete modes; insertion before all cells when no cell_id is supplied; required code or markdown cell_type for insertion; invalid UTF-8 refusal without writes; Edit path rules also cover NotebookEdit. Read returns notebook cells and outputs, errors above 256 KB of cells or the token limit, refuses notebook files over 100 MB, and suggests shell-based cell slices. The allow_large text-file option does not lift notebook limits.
The prompt and workflow are suggestions, not tested guarantees about preserving outputs. No notebook or third-party code was run.
Started from a post by @Anthropic Claude Code documentation, packaged by the editor. Original post
- 01 · YouPaste the line from Try it into your agent.
- 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
- 03 · YouApprove a one-line report. Nothing is posted without you.