SKILL.md
Python REPL - Persistent Session
Keeps Python interpreter running between commands, avoiding 20+ second package reload overhead.
When to use this skill
Use the REPL when you're about to:
- Import heavy packages: torch, transformers, nnterp, vllm, diffusers
- Run multiple Python commands that share state
- Do iterative testing/debugging with ML models
- Execute multi-step workflows (load model → compile config → query)
Don't use for one-off simple Python commands.
Setup (once per project)
uv add --editable ~/projects/research-libs/claude-repl
Quick check: Is server running?
echo '{"action":"ping"}' | timeout 2 nc -U /run/user/$(id -u)/claude-repl.sock
Start server
uv run claude-repl server &
Create session with imports
cat > /run/user/$(id -u)/session.json << 'EOF'
{
"action": "create_session",
"session_id": "main",
"python_path": ["./src"],
"preload_code": "import torch\nfrom mylib import Model\nprint('Ready')"
}
EOF
cat /run/user/$(id -u)/session.json | nc -U /run/user/$(id -u)/claude-repl.sock
Execute code
For simple code:
echo '{"action":"execute","session_id":"main","code":"print(model.num_layers)"}' | nc -U /run/user/$(id -u)/claude-repl.sock
For complex code (avoids shell escaping issues):
cat > /run/user/$(id -u)/code.py << 'EOF'
# Your code here
result = model.forward(x)
print(result.shape)
EOF
uv run python -c "
import json
code = open('/run/user/$(id -u)/code.py').read()
print(json.dumps({'action': 'execute', 'session_id': 'main', 'code': code}))
" | nc -U /run/user/$(id -u)/claude-repl.sock
Export to Jupyter notebook
Convert your session history to a notebook for sharing/reproducibility:
echo '{"action":"export_notebook","session_id":"main","path":"./experiment.ipynb"}' | nc -U /run/user/$(id -u)/claude-repl.sock
Key points
- Variables persist between execute calls
- Single-threaded: long operations block other requests
- Server uses packages from the venv it runs in
- Repo: https://github.com/Butanium/claude-repl