I work at a university and handle data--such as student grades--that institutional policy prohibits from being sent to cloud-based LLMs. However, the built-in Notebook Assistant automatically sends notebook data to cloud LLMs without distinction.
To address this, I prototyped a framework that assigns privacy levels to notebook data, separating what must remain confidential from what can safely be sent to the cloud, and processes them accordingly via Claude Code. Or rather, I had Claude Code build it for me.
The goal is to route confidential data to a local LLM (via LM Studio) while letting Claude Code handle everything else. I have only been developing and testing on Windows, and since the package invokes the Claude Code CLI directly, modifications will almost certainly be required for macOS and Linux environments.
Installation
Prerequisites
Claude Code CLI -- Download and install from the official site.
(* Verify installation *)
ClaudeCommand["--version"]
Node.js -- Download and install the latest LTS version from the official Node.js site.
Running the claude command in your terminal will launch an interactive login flow--just follow the on-screen instructions to complete authentication.
Setting Up in Mathematica
After launching Mathematica, define $packageDirectory as your preferred directory and add it to the path:
$packageDirectory = "...";
AppendTo[\$Path, $packageDirectory];
Then download the files and folders from the following repositories and place them in $packageDirectory:
https://github.com/transreal/claudecode
https://github.com/transreal/NBAccess
Load the package with:
$CharacterEncoding = "UTF-8";
<< claudecode.wl
Basic Usage
The two main entry points are:
ClaudeQuery -- primarily for obtaining results as values (default: AutoEvaluate -> False)
ClaudeEval -- primarily for generating and executing expressions (default: AutoEvaluate -> True)
You can ask questions freely, and the system will generally give you reasonable answers:
ClaudeQuery["How do I use claudecode?"]
ClaudeQuery["How do I configure data confidentiality settings?"]
A helper palette called "Claude Code" is also installed automatically for convenient access to common operations.