Claude Code with Jupyter notebooks in VS Code

Analysts live in notebooks, and Claude Code edits them cell by cell. How it changes a notebook, why an edited cell loses its output, what it cannot do (run the kernel), and a workflow that keeps results trustworthy.

Short answer: Claude Code edits a Jupyter notebook one cell at a time, by the cell's id: it can replace, insert or delete a cell. When it replaces a code cell, that cell's saved output and execution count are cleared, so re-run the cell, and the cells that depend on it, to get results back. In VS Code, the Claude Code extension works next to the notebook, and you see each proposed change before it lands.

Notebooks mix code, output and notes in one file, which makes them hard to edit as plain text. Claude Code has a tool made for them, and knowing how it behaves avoids the classic mistake: trusting an output that came from code that no longer exists.

Nothing loads from YouTube until you press play. Then Google receives your IP address and may set its own storage. Narrated with an AI-generated voice. Privacy

How does Claude Code change a notebook?

Replace
  • overwrite one cell's source
  • a code cell loses its saved output
Insertadd a code or markdown cell after a given cell
Deleteremove one cell
The three notebook edits

Permission rules use the same path format as file edits: a rule like Edit(notebooks/**) covers notebook edits in that folder.

What is a safe notebook workflow?

  1. 1
    Savesave the notebook, so Claude reads the current version
  2. 2
    Ask"Refactor the cleaning cells into one function; keep the outputs' meaning"
  3. 3
    Reviewread each proposed cell change in VS Code
  4. 4
    Re-runrestart the kernel and run all, top to bottom
  5. 5
    Comparekey numbers match the old run
Editing a notebook with Claude Code

Restart and run all matters: after cell edits, the kernel may still hold variables from old code, and a notebook that only works in a running kernel will fail for the next person.

What does it not do?

  • Execute cells. Re-running is up to you, in VS Code or Jupyter.
  • Edit a notebook that is not valid UTF-8. The edit is refused and nothing is written.
  • Keep old outputs on a replaced cell. Commit before a big refactor if you need them.

Where can you check this?

Where do you start?

For a first task that produces a script instead of a notebook, see profile a CSV with Claude Code. For the bigger picture, read Claude Code for data analysts.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.