Skip to main content

nblean
Lets coding agents work with Jupyter notebooks without reading every output

CI PyPI License: MIT

Install • Quick Start • Commands • Benchmarks • Agents


An .ipynb file holds code plus everything the code printed: DataFrame dumps, progress bars, tracebacks, and plots stored as base64 images. An agent that opens one reads all of it. To fix one cell, it then runs the whole notebook again and reads the result again.

nblean is a small CLI and agent skill that lets the agent work one cell at a time. It lists the notebook as an outline, opens only the cells asked for, clips their outputs, and runs cells in a background kernel that stays alive between commands.

What nblean Does

Agent needs to Without nblean With nblean
See what a notebook contains Reads the whole JSON, outputs included outline: one line per cell, with an output summary like → 14L img ERR KeyError
Look at a few cells Writes a one-off json/jq script show 12 15-18: source, plus outputs clipped to the first and last lines
Find code Greps JSON-escaped strings grep: matches by cell and line number
Debug Scrolls through ANSI-colored tracebacks full of library frames errors: only the failing cells, showing your frame and the exception
Edit a cell Rewrites the JSON, or reads the notebook first set / add / rm, with the new source passed on stdin
Re-run after a fix Runs the whole notebook again and reads all the output run 12: runs that cell in a kernel that is still alive, prints only its output, and saves it into the notebook
Check a value Adds a throwaway print cell eval 'df.dtypes': runs the code in the kernel without changing the notebook
Look at plots Every plot costs image tokens Plots are saved as files and only their paths are printed; the agent opens one when it needs to

How Savings Work

nblean cuts notebook tokens, which are only part of an agent's bill. Every session also pays for the system prompt, tool definitions, and conversation history. These fixed costs come to about 28k tokens per session on Claude Code. Savings grow with the size of the notebook and the volume of its outputs.

A/B test in Claude Code

Claude Sonnet ran headless (claude -p), two times with the nblean skill and two times without it. Token counts come from the usage that Claude Code reports; costs are what the same usage would cost at API prices.

Task Without nblean With nblean Change
Answer two questions from the saved outputs of a 7 MB EDA notebook (97 cells, 31 plots) 236k tokens · $0.207 172k tokens · $0.160 -27% tokens, -23% cost
Find and fix a bug in a 124 KB notebook, then re-run it until clean 183k tokens · $0.153 183k tokens · $0.150 no measurable change

The first version of nblean showed execution counts in the outline, and one run reported them as cell indices. The numbers above come from runs after that fix, and all of them answered correctly. Every fix run ended with a clean notebook. On the small notebook the baseline agent already worked efficiently: it ran nbconvert and grepped for errors, so nblean had little to remove.

First look

This compares the outline output with reading the whole notebook, counting text as bytes/4 and images by pixel area. It is an upper bound on what the first step saves.

Notebook Whole notebook nblean outline
Flight-data EDA, 97 cells, 31 plots ~81k ~1.5k
Data preprocessing ~58k ~260
Kaggle training run ~29k ~90

Installation

uv tool install nblean        # or: pipx install nblean
nblean --help

You can also run it without installing: uvx nblean outline nb.ipynb.

nblean is a single Rust binary. The PyPI package ships prebuilt wheels for macOS (Apple Silicon and Intel), Linux (x86_64 and aarch64), and Windows (x64), so installing it does not pull in any Python dependencies. On other platforms pip builds it from source, which needs a Rust toolchain. To build from the repository: cargo install --git https://github.com/kaanrkaraman/nblean.

The kernel runs in the notebook's own environment, not in nblean's. nblean picks the nearest .venv above the notebook, which needs ipykernel installed (uv add --dev ipykernel). Use --python PATH to pick a different interpreter.

Quick Start

# 1. Install the skill for your agent
nblean init                         # Claude Code (default)
nblean init --agent codex           # Codex
nblean init --agent opencode        # OpenCode
nblean init --agent gemini          # Gemini CLI
nblean init --agent all             # all of the above
nblean init --project               # into ./ instead of ~/

# 2. Ask your agent anything about a notebook

The skill tells the agent to start with outline and never to read the .ipynb directly.

How It Works

  Without nblean:                              With nblean:

  agent --read--> nb.ipynb                     agent --outline/show--> nblean --> nb.ipynb
    ^                 |                          ^                       |  clip, summarize,
    |  every source,  |                          |  only requested       |  images to files
    |  output, image  |                          |  cells, clipped       |
    +-----------------+                          +-----------------------+
                                                 agent --run 12--> nblean --> live kernel
                                                                     |  only this cell's output,
                                                                     |  saved back into nb.ipynb

The kernel is a detached ipykernel process. Each notebook gets its own kernel, and each nblean call connects to it, runs code, and disconnects. Variables stay in memory between calls until kernel stop or kernel restart.

Commands

CELL is an index (12), a range (3-7, 5-), all, or the start of a cell id.

Read

nblean outline nb.ipynb                       # one line per cell
nblean show nb.ipynb 12 15-18                 # source + clipped outputs
nblean show nb.ipynb 12 --no-output           # source only
nblean show nb.ipynb 12 --lines 60            # bigger clip; --full disables it
nblean grep nb.ipynb 'read_csv'               # search sources; -o includes outputs
nblean errors nb.ipynb                        # failing cells only

Edit

nblean set nb.ipynb 12 <<'PY'                 # replace source, clears stale outputs
df = pd.read_parquet(path)
PY
nblean add nb.ipynb --at 13 <<'PY'            # insert; --md for markdown
df.describe()
PY
nblean rm nb.ipynb 14 20-22

Execute

nblean run nb.ipynb 0-12                      # run cells, save outputs, stop at first error
nblean eval nb.ipynb 'df.shape'               # scratch code, nothing saved
nblean kernel nb.ipynb status|stop|restart

Examples

$ nblean outline eda.ipynb
eda.ipynb: 97 cells (36 markdown, 61 code), kernel off
  0 md    1. Files and Schema +14L
  1 code  import itertools +27L
  3 code  files = pl.DataFrame( +5L  → 13L
 13 code  p0 = pl.read_parquet(PARQ / "part.0.parquet") +7L  → 1L img
 15 code  fl_min = feat["flight_length"].to_numpy() / 60 +19L  → img

A 40-line pandas traceback, cut down to the line that failed:

$ nblean errors buggy.ipynb
── 8 code id=cell08 exec=3 ──
KeyError                                  Traceback (most recent call last)
Cell In[3], line 1
----> 1 df["pressure_kpa"] = df["presure"] * 6.89476
      2 df.head()

… 11 library or chained frames omitted …
KeyError: 'presure'

A 300-line training log, with a plot that is saved to a file instead of loaded:

$ nblean run buggy.ipynb 3 4 --lines 6
── 3 code id=cell03 exec=4 ──
epoch 000 smoothing pass loss=1.000000 temp_mean=141.845
epoch 001 smoothing pass loss=0.500000 temp_mean=141.724
epoch 002 smoothing pass loss=0.333333 temp_mean=141.651
… 294 lines omitted …
epoch 297 smoothing pass loss=0.003356 temp_mean=139.027
epoch 298 smoothing pass loss=0.003344 temp_mean=139.038
epoch 299 smoothing pass loss=0.003333 temp_mean=139.048
── 4 code id=cell04 exec=5 ──
[image/png → /tmp/nblean/buggy-ec4a859a6390/img/4_0.png]

Supported Agents

The skill uses the Agent Skills SKILL.md format, so the same file works in every agent below. The CLI works with any agent that can run shell commands.

Agent nblean init Skill location
Claude Code --agent claude, or the plugin below ~/.claude/skills/nblean
Codex --agent codex ~/.agents/skills/nblean
OpenCode --agent opencode ~/.agents/skills/nblean
Gemini CLI --agent gemini ~/.gemini/skills/nblean
Others npx skills add kaanrkaraman/nblean per agent

In Claude Code the skill is also available as a plugin:

/plugin marketplace add kaanrkaraman/nblean
/plugin install nblean@nblean

nblean ships as a CLI and a skill instead of an MCP server. An MCP server's tool definitions are loaded into every session. A skill is loaded only when a notebook comes up.

Speed

Version 0.1 was written in Python. Version 0.2 is the same CLI rewritten in Rust, and it produces byte-identical output. Startup time dropped from about 90 ms to 2 ms per call. Commands that talk to a running kernel dropped from about 345 ms to 7 ms.

Command Python 0.1 Rust 0.2
outline on a 7 MB notebook 109 ms 6 ms
show 0-5 on a 7 MB notebook 111 ms 6 ms
eval against a running kernel 346 ms 7 ms
run one cell against a running kernel 349 ms 11 ms
starting a kernel 308 ms 211 ms

Measured with hyperfine on an Apple Silicon Mac, mean of at least 20 runs. Kernel start time is mostly ipykernel's own startup.

Platform Support

macOS, Linux, and Windows. The kernel's Python can be any version that ipykernel supports.

Limitations

  • A cell's outputs are written when the cell finishes. If a long cell is killed, its output is lost.
  • Writes are atomic but not merged. If the notebook is open in Jupyter or VS Code, reload it there after nblean writes.
  • Widgets, update_display_data, and input() are not supported.

Contributing

cargo test
cargo clippy --all-targets -- -D warnings
cargo fmt --check

The kernel test needs a Python with ipykernel. Point NBLEAN_TEST_PYTHON at it if python3 on your PATH does not have it.

License

MIT

Metadata

Release files for nblean 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nblean 0.2.0
File Size Uploaded
nblean-0.2.0.tar.gz 35.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for nblean 0.2.0
File
nblean-0.2.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
nblean-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
nblean-0.2.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details
nblean-0.2.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details
nblean-0.2.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details

Total release size: 7.3 MB

Release files / nblean-0.2.0.tar.gz

Download URL nblean-0.2.0.tar.gz
Size 35.4 kB
Tags Source
SHA-256 checksum
How to use checksums
90eb99c56feb277dfb2b1c24f38d97bb1fe0a6a32f9b578aed475219a5e03e21
BLAKE2b-256 checksum
How to use checksums
0561a36ffd8841f8a55c0b010428db57c314e01077f83b89cb57d3e246dd2e31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / nblean-0.2.0-py3-none-win_amd64.whl

Download URL nblean-0.2.0-py3-none-win_amd64.whl
Size 1.5 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
3ac8f1d5aa9c6203884095d415b33c6a73f3ef0ae09c00dc84a146fa16310c3c
BLAKE2b-256 checksum
How to use checksums
8242889c9a87ec4eb6ac0212ef7f4e73f357a68a867c65618a125acf478e89b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / nblean-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL nblean-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.5 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
135a031d5bec27ab848e1a2360284542b842467983a2a442578f8c4daa6f715b
BLAKE2b-256 checksum
How to use checksums
60009ac2e4fea0dd2f118c55aed436d9746e95b745f8dbc5709a863d475aadc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / nblean-0.2.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL nblean-0.2.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.4 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
05b946caaed3e210d9059fcd5ed7e85438751b7405102d8d32fddcb634d5b937
BLAKE2b-256 checksum
How to use checksums
ce0a03a00f63efce29f35c82b3baddb141c0e6c69877df72468376b67d01639d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / nblean-0.2.0-py3-none-macosx_11_0_arm64.whl

Download URL nblean-0.2.0-py3-none-macosx_11_0_arm64.whl
Size 1.4 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
600629ad696f2839036c9a5cf048d56c2c72f071878296e521515dfefa61534c
BLAKE2b-256 checksum
How to use checksums
ba188fc2766189d67cdafa711a727a9fc53f211739c0b26a247289b31421ad28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / nblean-0.2.0-py3-none-macosx_10_12_x86_64.whl

Download URL nblean-0.2.0-py3-none-macosx_10_12_x86_64.whl
Size 1.5 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
689ed1bbb7783acb28356abe511bc3ebbc6ada283f34ea442a53537efd8c5b77
BLAKE2b-256 checksum
How to use checksums
edd7611e954481c7b2ee3507709709d6b66617dcf74962fb3e489194b61fd776
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.2.0 This release

6 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page