代码功能门检测修补工具

一款用于检测、分析和修补Claude Code中功能门(feature gates)的工具,支持扫描JS包和原生二进制文件,提供功能门启用/禁用能力。

  • by sethdford
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 sethdford/claude-code-patcher

使用说明

克劳德代码修补程序

检测、分析和修补克劳德代码中的特征门。

这是什么?

Claude Code Patcher扫描Claude Code的JS包和本机二进制文件,以检测、编目和可选地修补Statsig功能门(tengu_* 旗帜)。它使您可以看到哪些特征被门控,每个门控控制什么,以及强制启用仍在卷展栏中的门控的能力。零运行时依赖,适用于npm安装的JS包和编译的本机二进制文件(Node.JS SEA)。

660 已编目的旗帜| 40 闸门记录| 9 可修补| 0 运行时deps

快速开始

npm install -g claude-code-patcher

# Scan for all feature gates
claude-patcher gates

# Enable a specific gate
claude-patcher gates enable session-memory

# Scan for all tengu_* flags in the binary
claude-patcher gates scan

你能做什么?

:mag:发现

扫描Claude Code安装以查找已注册的功能门,并列出所有 tengu_* 二进制文件中嵌入的标志。CLI会自动检测您的安装路径。

claude-patcher gates          # List all detected feature gates
claude-patcher gates scan     # Scan binary for all 605+ tengu_* flags

:扳手:启用

通过修补JS包或本机二进制文件来强制启用门控功能。补丁通过自动备份和macOS代码设计重新签名来保持字节长度。

claude-patcher gates enable session-memory   # Enable a specific gate
claude-patcher gates enable --all            # Enable all patchable gates
claude-patcher gates disable session-memory  # Restore from backup
claude-patcher gates reset                   # Restore all gates from backup

:书籍:研究

每个门都是从缩小的二进制文件中逆向设计的。文档目录共660个 tengu_* 按类别标记,文件114 CLAUDE_CODE_* 环境变量,并解释每个门控制什么。

可修补的门

这些闸门具有逆向工程功能体,可以强制启用:

代号 标志 层 环境覆盖 描述
keybinding-customization tengu_keybinding_customization_release 1 自定义键盘快捷键配置
amber-quartz tengu_amber_quartz 1 语音听写模式(按住空格进行录制)
ccr-bridge tengu_ccr_bridge 1 通过WebSocket实现远程控制桥
mcp-elicitation tengu_mcp_elicitation 1 MCP服务器向用户提出澄清问题
immediate-model-command tengu_immediate_model_command 1 无需重新连接即可立即切换/切换型号
pr-status-cli tengu_pr_status_cli 1 CLI终端PR状态显示
session-memory tengu_session_memory 2 ENABLE_CLAUDE_CODE_SM_COMPACT 具有压缩功能的会话内存
amber-flint tengu_amber_flint 2 CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS 代理团队功能门
copper-bridge tengu_copper_bridge 2 远程会话的WebSocket网桥URL

门层

  • 第1级 --简单包装: function X(){return checkGate("tengu_flag",!1)}
  • 第2层 --Env保护:先进行Env变量检查,然后进行Statsig检查
  • 第3层 --复杂:多分支退货、订阅检查
  • 第4层 --太复杂:首选env var覆盖(仅检测)
  • 第5级 --内联检查:无包装函数(仅检测)

仅检测门

在二进制文件中检测到,但过于复杂,无法安全修补或可通过环境变量控制:

代号 描述
chomp-inflection 及时的建议。环境: CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION
vinteuil-phrase 简化系统提示。环境: CLAUDE_CODE_SIMPLE
speculation 投机执行(内联,第5层)
structured-output 结构化输出模式(内联,第5层)
streaming-tool-exec-v2 流媒体工具执行v2(内联,第5层)
thinkback 年度回顾动画技能(内联,第5级)
system-prompt-global-cache 全局提示缓存。环境: CLAUDE_CODE_FORCE_GLOBAL_CACHE

加 20个逆向工程闸门: marble-anvil (清晰思维测试版), coral-fern (过去的会话访问), quiet-fern (VS代码实验), scarf-coffee (有条件的工具注入), cork-m4q (策略规范注入), tst-kx7 (工具搜索实验), plum-vx3 (WebSearch行为), tool-pear (工具模式过滤), flicker (TUI遥测), quartz-lantern (订阅), cache-plum-violet (缓存变体), kv7-prompt-sort (提示重新排序), crystal-beam (考虑预算代币), swann-brevity (输出简洁模式), bergotte-lantern (抛光输出), marble-sandcastle (快速模式验证), moth-copse (内存注入), mulberry-fog (内存模板), slate-nexus (引导技能), slate-ridge (VS代码实验), coral-whistle (工具跟踪), pebble-leaf-prune (历史修剪), amber-prism (代理提示), penguins-off (快速模式终止开关), tst-names-in-messages (工具搜索名称)。看 特稿-GATES.md 了解全部细节。

程序化API

import {
  detectAllGates,
  detectPatchableGates,
  scanAllFlags,
  enableGate,
  disableGate,
  enableAllGates,
  resetGates,
  getAllGates,
  findGate,
  isPatchable,
} from "claude-code-patcher";

// Detect all registered gates
const gates = detectAllGates();

// Scan for all tengu_* flags
const allFlags = scanAllFlags();

// Check a specific gate
const gate = findGate("swarm-mode");
console.log(gate?.description);

// Enable/disable
enableGate("swarm-mode");
disableGate("swarm-mode");

// Enable all patchable gates
enableAllGates();

// Reset from backup
resetGates();

运作原理

  1. 定位 --查找Claude代码命令行界面(npm global、home dir或 which claude)
  2. 阅读 --JS捆绑为UTF-8;原生二进制文件为latin1(保留字节偏移)
  3. 检测 --每个门的 detectRegex 与捆绑包匹配
  4. 备份 --任何修改前的带时间戳的副本
  5. 补丁 --更换闸门功能体以强制 return!0 (始终启用)
  6. 马克 --注入标记注释以供识别(CLAUDE-CODE-PATCHER FEATURE GATES:codename)

二进制补丁使用字节长度保持替换,并填充JS块注释。

建筑

src/
  cli.ts              — CLI entry point
  cli-finder.ts       — Locates Claude Code installations
  types.ts            — Type definitions
  index.ts            — Public API exports
  gates/
    registry.ts       — Gate registry (9 patchable, 31 detection-only)
    detector.ts       — Gate detection in JS/binary bundles
    patcher.ts        — JS bundle patching
    binary-patcher.ts — Binary patching with codesign
    index.ts          — Gate module exports
docs/
  FEATURE-GATES.md    — Patchable gates deep-dive
  TENGU-FLAGS.md      — Complete 605-flag catalog
  ENV-VARS.md         — Environment variable reference

v2.1.63兼容性

针对Claude Code v2.1.63进行了测试。当版本之间的缩小发生变化时,门正则表达式可能需要更新。看 特稿-GATES.md 查看详细的兼容性说明。

文档

  • 特稿-GATES.md --深入了解所有可修补和仅检测的门、层解释和版本兼容性(仅9个可修补+31个检测)
  • TENGU-FLAGS.md --660的完整目录 tengu_* 按类别组织的旗帜
  • ENV-VARS.md --参考114+ CLAUDE_CODE_* 环境变量, DISABLE_* 切换,以及 ENABLE_* 开关

发展

npm run build     # Compile TypeScript
npm test          # Run tests (vitest)
npm run dev       # Watch mode
npm run lint      # ESLint

贡献

看 贡献.md 了解开发设置、测试要求以及如何添加新门。

许可证

麻省理工学院——见 许可证

免责声明

这是一个非官方项目,与Anthropic无关或不受其认可。它通过二进制补丁修改Claude Code CLI,并可能因更新而中断。使用风险自负。特征门名称和行为可能会在版本之间发生变化。始终在打补丁之前创建备份。