Claude Code Patch
We assume you have the leaked source code of Claude Code, and it turns out that you cannot directly run it because it has some missing dependencies. This repository is right for you to make your source code work successfully.
This repository provides the necessary patching and stubbing infrastructure. It acts as a specialized optimization layer, enabling you to stay in sync with the upstream source while applying persistent local modifications for local LLM support (Ollama).
๐ Unified Installation (install.sh)
We use a consolidated install.sh script to handle the entire setup process, including source synchronization, patch application, and dependency management.
Prerequisites
- Bun: Install Bun (v1.1.0 or higher).
- Claude Code Source: You must have the original Claude Code
src directory available locally.
Setup Instructions
-
Run the Installer:
./install.sh /path/to/original/claude/src
If the path is not provided as an argument, the script will prompt you for it.
-
What the script does:
- Sync: Resets the local
src/ directory to match the upstream source.
- Patch: Copies files from the
patch/ directory into the root, applying all custom logic and configurations.
- Install: Runs
bun install to fetch all necessary dependencies.
- Stub: Automatically triggers the local module stubber to prepare the environment for non-proprietary execution.
-
Launch the CLI:
bun run dev
๐ ๏ธ Key Features
1. Ollama & Local LLM Support
The patch includes an Ollama Integration that allows using local models like Llama 3 instead of the Anthropic API.
ollamaShim.ts: A translation layer that intercepts Anthropic SDK calls and maps them to OpenAI-compatible requests for Ollama.
- Intelligent Routing: The API client is modified to automatically route requests to
localhost:11434 when a local model name is detected.
2. Deep Sweep Stubbing
The scripts/deep-sweep-stubber.ts enables the CLI to run without access to internal Anthropic dependencies or proprietary modules (like @ant/* or color-diff-napi).
- Dynamic Proxy Generation: Creates JavaScript
Proxy objects that "catch-all" property access, preventing runtime crashes.
- React 19 Compatibility: Automatically patches the React development bundle to bridge missing experimental features (like
useEffectEvent) in Bun environments.
3. Experimental Features & UI
This branch activates various internal or experimental commands (e.g., /buddy, /ultrareview) by providing local mocks or implementations.
๐ Project Structure
install.sh: The main setup script.
patch/: The source of truth for all modifications. Files here are applied to the root during installation.
src/: The working source directory (generated/updated by install.sh).
For a full list of modified files and a detailed manifest, see patch/docs/patch.md.
Caution
Source of Truth: Always make modifications inside the patch/ directory. Changes made directly to the root src/ will be overwritten whenever install.sh is run.
๐ง Global Launcher Setup
For the best experience, you can create a global claude command that you can run from any terminal, automatically applying your local model settings.
1. Unified Launcher Script
A unified tool at scripts/create_launcher.sh (or patch/scripts/create_launcher.sh) is provided to handle the entire setup.
2. Setup Instructions
Run the script to configure your environment and link the command:
./patch/scripts/create_launcher.sh
This script will:
- Prompt for Settings: Ask for your Ollama model name and base URL.
- Create
.env: Save these persistently to a local .env file that Bun automatically loads.
- Generate Launcher: Create a global launcher at
~/.local/bin/claude representing your patched repository.
3. Usage
Once set up, you can start your local Claude Code by just typing:
claude
To use the original unpatched version at any time, run:
claude --official
Tip
Path Precedence: Ensure that ~/.local/bin is in your shell's PATH. If it is not, the official version in /opt/homebrew/bin may take precedence.