> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/cline/cline/llms.txt
> Use this file to discover all available pages before exploring further.

# Jupyter Notebooks

> AI-assisted cell generation, explanation, and improvement for Jupyter notebooks in VS Code.

Cline provides built-in support for Jupyter notebooks (`.ipynb` files), enabling AI-assisted editing with full cell-level context awareness. This feature was developed in collaboration with Amazon to bring AI coding assistance to data science workflows.

## Getting started

Jupyter notebook support is built into Cline — no separate installation is required. You need the Jupyter notebook extension enabled in VS Code. Once you open any `.ipynb` file, you'll see AI-assisted buttons appear in your notebook interface.

## Toolbar actions

Cline adds three actions to your notebook interface:

<CardGroup cols={3}>
  <Card title="Generate cell" icon="sparkles">
    Creates a new cell with AI assistance, using surrounding cells for context. Click the sparkle icon in the notebook toolbar.
  </Card>

  <Card title="Explain cell" icon="message-question">
    Provides a detailed explanation of what a cell does, including its outputs. Click **Explain** in any cell's title bar.
  </Card>

  <Card title="Improve cell" icon="wand-magic-sparkles">
    Suggests enhancements to an existing cell — performance, clarity, or error handling. Click **Improve** in any cell's title bar.
  </Card>
</CardGroup>

## Generate cell

Click the sparkle icon in the notebook toolbar to generate a new cell with AI assistance.

The AI receives context from surrounding cells, so it understands the variables, DataFrames, and imports already in scope. You can reference existing objects in your prompt without re-explaining them.

**Example prompts:**

```text theme={null}
Create a visualization showing the correlation matrix of numeric columns with a heatmap
```

```text theme={null}
Group the df DataFrame by category and calculate mean and standard deviation for each group
```

The generated cell is inserted with proper notebook JSON structure, preserving metadata and ready to execute immediately.

**Tips for best results:**

* Be specific about what you want the cell to do
* Reference existing variables by name — the AI can see them in context
* Mention preferred libraries if you have a preference (e.g., "use seaborn" or "use plotly")

## Explain cell

Click **Explain** in any cell's title bar to get a detailed explanation of what the cell does.

This is useful for:

* Revisiting old notebooks you haven't touched in a while
* Onboarding to a teammate's analysis
* Understanding complex chained operations like pandas `groupby`/`merge` sequences

Cline extracts the full cell context including outputs, so explanations can reference actual results — column names, row counts, computed values — rather than just describing the code abstractly.

**Tips for best results:**

* Works best on cells that have been executed, since outputs give additional context
* Works well on cells with complex transformations or unfamiliar library APIs

## Improve cell

Click **Improve** in any cell's title bar to enhance an existing cell with AI suggestions.

Use this to:

* Optimize slow pandas operations with vectorized equivalents
* Add error handling and input validation
* Refactor for readability and clarity
* Convert explicit loops to more idiomatic operations

Cline suggests improvements while preserving the cell's position and metadata in the notebook structure. The AI explains what was changed and why, so you can evaluate the suggestion before accepting it.

**Tips for best results:**

* Mention the aspect you want to improve: performance, readability, error handling
* The AI will explain its changes so you understand what it did

## How cell context works

Unlike traditional source files, Jupyter notebooks are JSON documents containing arrays of cells. Each cell has its own type, source content, metadata, execution count, and outputs.

When you use a Jupyter command, Cline extracts structured context that includes:

* **Cell type** — code, markdown, or raw
* **Source content** — the cell's code or text as an array of lines
* **Cell metadata** and configuration
* **Execution count** for code cells
* **Outputs** — including data, text output, and error traces

This structured representation lets the AI understand not just the code, but its position in the notebook and its actual output — which is often as informative as the code itself.

### JSON structure preservation

Cline is designed to work carefully with the cell JSON structure:

* Cell boundaries are kept intact
* Execution counts are preserved
* Cell metadata is maintained
* Outputs remain associated with their source cells

The AI is specifically prompted to preserve notebook structure, but you should always review changes to ensure the format remains correct before committing or sharing.

## Keyboard shortcuts

You can bind any Jupyter command to a keyboard shortcut for faster access:

<Steps>
  <Step title="Open keyboard shortcuts">
    Press **Cmd/Ctrl + K**, then **Cmd/Ctrl + S** to open the VS Code keyboard shortcuts editor.
  </Step>

  <Step title="Search for the command">
    Search for `cline.jupyterGenerateCell`, `cline.jupyterExplainCell`, or `cline.jupyterImproveCell`.
  </Step>

  <Step title="Assign a key binding">
    Click the + icon next to the command and press your preferred key combination.
  </Step>
</Steps>

## Limitations

* Notebook support requires the Jupyter notebook extension to be enabled in VS Code
* Cell context extraction depends on VS Code's notebook API — this feature is not available in JetBrains or the Cline CLI
* Very large notebooks may exceed the context capacity of smaller models; use a model with a larger context window for complex notebooks

## Related

* [Features Overview](/features/auto-approve) — Overview of Cline features
* [Models & Providers](/models/model-selection-guide) — Choosing the right model for your workflow
* [Auto Approve](/features/auto-approve) — Control which file operations Cline can perform without prompting
