A configurable auto-patch system for Claude Code. Automatically applies binary patches before Claude starts and survives updates.
- Auto-patch before startup — Shell wrapper runs patches before Claude launches, avoiding file-lock issues
- Configurable — Enable/disable individual patches via JSON config
- Smart caching — Skips re-scanning unchanged binaries (uses file mtime)
- Cross-platform — Windows (PowerShell), macOS/Linux (Bash/Zsh)
- Zero-copy install — Clone once,
git pullto update. No files copied to~/.claude/ - Create patches with AI —
/create-patchskill guides Claude through the entire patch creation workflow
git clone https://github.com/Cedriccmh/claude-auto-patch.git ~/.claude-auto-patch
cd ~/.claude-auto-patch && python install.pyRestart your shell. Done!
cd ~/.claude-auto-patch && git pullcd ~/.claude-auto-patch && python install.py --uninstallpython install.py --status # Check installation status
python install.py --dry-run # Preview changes without modifying filesThe installer injects a shell wrapper function into your profile ($PROFILE for PowerShell, .bashrc/.zshrc for Bash/Zsh):
You type "claude"
-> Shell wrapper function runs
-> No claude process running? -> python auto_patch.py
-> Load config (which patches are enabled)
-> Find claude binary / cli.js in PATH
-> Check cache (file mtime + enabled patches)
-> If unchanged: skip (< 1ms)
-> If changed: apply patches (equal-length byte replacement)
-> Launch the real claude binary
To use the /create-patch skill for AI-assisted patch creation:
cp -r ~/.claude-auto-patch/skills/create-patch ~/.claude/skills/Edit auto-patch-config.json to toggle patches:
{
"toolsearch": true
}Set a patch to false to disable it. Remove the cache file to force re-evaluation:
rm ~/.claude/.auto-patch-cache.json| Patch | Description | Default |
|---|---|---|
toolsearch |
Remove Tool Search domain restriction | Enabled |
Use /create-patch in Claude Code and describe what you want to patch. The AI will:
- Search the npm version of
cli.jsfor relevant code - Analyze the minified JavaScript logic
- Design an equal-length binary replacement
- Register the patch definition and update config
- Test the patch
Add a PatchDef to auto_patch.py:
"your_patch": PatchDef(
name="your_patch",
description="What this patch does",
target_re=re.compile(rb'regex matching original code'),
patched_re=re.compile(rb'regex matching patched code'),
build_replacement=lambda m: _equal_length_replace(
b"replacement_prefix", b"replacement_suffix", m
),
),Then add the toggle to auto-patch-config.json:
{
"toolsearch": true,
"your_patch": true
}Patches must be exactly the same byte length as the original code. This is achieved by using JavaScript comments (/* */) as padding:
Original: return["api.anthropic.com"].includes(Xe)}catch{return!1}
Patched: return!0/* */}catch{return!0}
Each patch has two regexes:
target_rematches unpatched code -> safe to applypatched_rematches patched code -> already done, skip- Neither matches -> version incompatible, do not touch
- Python 3.10+
- Claude Code (bun binary or npm install)
Claude Code 的可配置自动补丁系统。在 Claude 启动前自动应用补丁,更新后自动恢复。
- 启动前自动补丁 — Shell wrapper 在 Claude 启动前运行补丁,避免文件锁问题
- 可配置 — 通过 JSON 配置文件启用/禁用单个补丁
- 智能缓存 — 跳过未变更的二进制文件(基于 mtime),< 1ms
- 跨平台 — Windows(PowerShell)、macOS/Linux(Bash/Zsh)
- 零拷贝安装 — clone 一次,
git pull即更新。无需复制文件到~/.claude/ - AI 辅助创建补丁 —
/create-patchskill 引导 Claude 完成补丁创建全流程
git clone https://github.com/Cedriccmh/claude-auto-patch.git ~/.claude-auto-patch
cd ~/.claude-auto-patch && python install.py重启终端即可!
cd ~/.claude-auto-patch && git pullcd ~/.claude-auto-patch && python install.py --uninstallpython install.py --status # 查看安装状态
python install.py --dry-run # 预览变更,不修改文件安装器将一个 shell wrapper 函数注入到你的 profile 中(PowerShell 的 $PROFILE、Bash 的 .bashrc、Zsh 的 .zshrc):
你输入 "claude"
-> Shell wrapper 函数运行
-> 没有 claude 进程在运行? -> python auto_patch.py
-> 加载配置(哪些补丁已启用)
-> 在 PATH 中查找 claude 二进制或 cli.js
-> 检查缓存(文件 mtime + 已启用补丁列表)
-> 未变更:跳过(< 1ms)
-> 已变更:应用补丁(等长字节替换)
-> 启动真正的 claude 二进制
使用 /create-patch skill 进行 AI 辅助补丁创建:
cp -r ~/.claude-auto-patch/skills/create-patch ~/.claude/skills/编辑 auto-patch-config.json 切换补丁开关:
{
"toolsearch": true
}设为 false 禁用。删除缓存文件可强制重新检测:
rm ~/.claude/.auto-patch-cache.json| 补丁 | 说明 | 默认 |
|---|---|---|
toolsearch |
解除 Tool Search 域名限制 | 启用 |
在 Claude Code 中使用 /create-patch,描述你想补丁的内容。AI 将自动:
- 在 npm 版
cli.js中搜索相关代码 - 分析 minified JavaScript 逻辑
- 设计等长二进制替换
- 注册补丁定义并更新配置
- 测试补丁
在 auto_patch.py 中添加 PatchDef:
"your_patch": PatchDef(
name="your_patch",
description="补丁说明",
target_re=re.compile(rb'匹配原始代码的正则'),
patched_re=re.compile(rb'匹配补丁后代码的正则'),
build_replacement=lambda m: _equal_length_replace(
b"替换前缀", b"替换后缀", m
),
),然后在 auto-patch-config.json 中添加开关:
{
"toolsearch": true,
"your_patch": true
}补丁必须与原始代码完全等长。通过 JavaScript 注释(/* */)填充实现:
原始: return["api.anthropic.com"].includes(Xe)}catch{return!1}
补丁: return!0/* */}catch{return!0}
每个补丁有两个正则表达式:
target_re匹配未补丁代码 -> 可安全应用patched_re匹配已补丁代码 -> 跳过- 都不匹配 -> 版本不兼容,不操作
- Python 3.10+
- Claude Code(bun 二进制或 npm 安装)
MIT