[BUG] JupyterNotebook new cell constantly inserted at the beginning of a notebook
Status Closed — not planned
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 13 comments · opened Jul 28, 2025 · closed Jan 5, 2026
Environment
- Platform (select one):
- [x] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: <!-- output of
claude --version--> - Operating System: Linux 6.8.0-64-generic
- Terminal: <!-- e.g. iTerm2, Terminal App -->
## Bug Description
The NotebookEdit tool with edit_mode="insert" inserts cells at the beginning of
the notebook instead of at the end when no cell_id is specified, contrary to
expected behavior.
## Steps to Reproduce
- Open a Jupyter notebook with multiple cells using NotebookEdit
- Use NotebookEdit with
edit_mode="insert"andcell_type="code"without
specifying a cell_id parameter
- Observe where the new cell is inserted
## Expected Behavior
When using edit_mode="insert" without specifying a cell_id, the new cell
should be inserted at the end of the notebook (as the last cell).
## Actual Behavior
The new cell is inserted at the beginning of the notebook (as the first cell)
instead of at the end.
## Additional Context
- Workaround: Must specify the
cell_idof the last cell to insert after it - This affects user experience when trying to add cells to the end of notebooks
during analysis workflows
- The tool documentation suggests that omitting
cell_idshould insert at the
beginning, but user expectation is that "insert" without position means "append to
end"
Duplicate of: https://github.com/anthropics/claude-code/issues/2925
13 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Also having this issue, does anyone know a workaround? Makes it pretty impossible to work with Jupyter notebooks from Claude code at the moment.
As per my original ticket description, this seem to work:
Are you referring to adding the instruction "Must specify the cell_id of the last cell to insert after it" in claude.md?
In each instruction you give to claude you should add:
insert new code after cell <10>. Replace<10>by your actual last cell number.This method might be effective for modifying existing Jupyter notebooks, but if you need Claude to create new files, it won't work. Currently, every time I finish creating a notebook with Claude, I have it review the notebook again, adjust the order, which consumes additional tokens, and for notebooks with more code, the effectiveness may decrease
Is this going to get fixed? This is really annoying when working with claude code.
For the scenario of creating ipynb files, I have a better workaround: create the ipynb file yourself, then add enough empty cells within the file, and let Claude Code write inside these empty cells instead of generating new ones
I found that this workaround works: put this into CLAUDE.md (yes as you can tell the instructions themselves are generated by Claude Code as a summary of a session of me yelling at it for a bit)
Technical Tool Guidelines
Jupyter Notebook Editing (NotebookEdit Tool)
Critical Known Issue
The NotebookEdit tool has a default insertion behavior that inserts new cells at the very top of the notebook when no
cell_idis specified. This can create ordering problems and notebook structure issues.Required Best Practices
``
bash
``# Extract cell IDs from any notebook before editing
cat notebook.ipynb | grep -E '"id": "[^"]*"'
NotebookEditwithedit_mode="insert"without specifyingcell_idcell_idto control exact placement in notebook structure```python
# CORRECT: Target specific cell for insertion
NotebookEdit(
notebook_path="path/to/notebook.ipynb",
edit_mode="insert",
cell_id="existing_cell_id", # Insert AFTER this cell
cell_type="markdown",
new_source="content"
)
# WRONG: No cell_id specified - will insert at top
NotebookEdit(
notebook_path="path/to/notebook.ipynb",
edit_mode="insert", # This will go to the top!
cell_type="markdown",
new_source="content"
)
```
Why This Matters
Incorrect cell insertion can create notebook structure problems that are difficult to fix, especially with large notebooks that exceed file size reading limits. Following these practices ensures precise control over notebook organization.
Why not try my Jupyter MCP Server jupyter-mcp-server ? It has these amazing features:
Additionally, it supports connecting to multiple Jupyter servers simultaneously, whether local or remote! It supports one-click quick installation using uvx like this:
Come and give it a try!
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.