claude-code-jupyter-staging 0.0.1
IPython/Jupyter magic commands for interacting with Claude
License: MIT
Requires Python: >=3.11
Keywords: ai, claude, ipython, jupyter, llm, magic

# Claude Code Jupyter

IPython/Jupyter magic commands for interacting with Claude. This extension allows Claude to generate code that executes in your **current** Jupyter notebook or IPython session, sharing all variables and state.

## Installation

```bash
pip install claude-code-jupyter
```

For development installation:

```bash
git clone https://github.com/anthropics/claude-code-jupyter.git
cd claude-code-jupyter
pip install -e ".[dev]"
```

## Quick Start

### In a Jupyter Notebook

1. Load the extension:
```python
%load_ext cc_jupyter
```

2. Use Claude to generate and execute code:
```python
%cc Create a list of prime numbers up to 100
```

3. To see available options and usage information:
```python
%cc --help
```

### In IPython

1. Start IPython:
```bash
ipython
```

2. Load the magic:
```python
%load_ext cc_jupyter
```

3. Use Claude to generate and execute code:
```python
%cc Create a list of prime numbers up to 100
```

## When to use %cc vs %%cc

- **Use `%cc` (single %)** for:
  - Short, one-line instructions
  - Command options like `--help` or `--verbose`
  - Continuing without additional instructions

- **Use `%%cc` (double %)** for:
  - Multi-line instructions or detailed prompts
  - Complex requests that need more explanation
  - Any prompt ending with `?` (to avoid IPython's help system)

## Features

### Automatic Code Writing

Claude's code blocks are automatically extracted and written into a new cell that you approve by executing:

```python
import numpy as np
data = np.random.randn(1000)

%%cc
Create a histogram of the data array and calculate its statistics
```

### Continue Conversations

Follow up on previous requests:

```python
%cc Create a pandas DataFrame with sales data

# Claude writes code into a new cell, you review it and execute it

%cc Now add a column for profit margin
```

### Shared State

All variables are shared between you and Claude:

```python
# You create:
x = [1, 2, 3, 4, 5]

# Claude can use:
%cc Square each element in x and store in a new list called x_squared

# Claude writes code into a new cell, you review it and execute it

# You can use:
print(x_squared)  # Claude's variable is available!
```

## How It Works

1. You give Claude a task via `%cc <task>`
2. Claude generates Python code based on your request
3. The extension creates a new cell with Claude's Python code
4. You review Claude's code and execute it
5. You can continue working with Claude via `%cc`

## Examples

### Data Analysis
```python
%%cc
Load the iris dataset from sklearn and create a scatter plot matrix
```

### Interactive Development
```python
# Your code
data = load_my_data()

%cc Clean the data by removing NaN values and outliers

# Claude writes code into a new cell, you review it and execute it

%cc Now normalize the numerical columns

# data is now cleaned and normalized in your session
```

## Development

### Setup

```bash
# Clone the repository
git clone https://github.com/anthropics/claude-code-jupyter.git
cd claude-code-jupyter

# Install in development mode with dev dependencies
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install
```

### Running Tests

```bash
pytest
```

### Code Quality

```bash
# Run linting
ruff check .

# Run formatting
ruff format .

# Run type checking
pyright
```

## Safety

- Claude does not execute code by itself. All code is reviewed by a human, who can choose to execute (or not).

## Limitations

- Claude can write code with errors
- No sandboxing - code runs with same access as rest of notebook

## License

MIT License - see [LICENSE](LICENSE) for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

This extension is perfect for interactive data analysis, learning, and development where you want Claude to work alongside you in the same environment!