修复在 dev 模式下按下 Ctrl+O 切换 transcript 视图时 React 抛出
"Rendered fewer hooks than expected" 崩溃的问题。
## 根因分析
项目中有大量 hook(useState / useMemo / useRef / useSyncExternalStore 等)
被包裹在 `feature()` 三元表达式中条件调用,例如:
const value = feature('X') ? useHook() : defaultValue;
在 build 模式下 `feature()` 是编译时常量,死代码消除会移除未使用的分支,
hooks 数量在编译后是确定的。但在 dev 模式下(scripts/dev.ts 注入
--feature 启用全部 31 个 feature),`feature()` 是运行时调用,
但始终返回 true,因此所有 hooks 都会被调用,原本不会出问题。
真正的触发器是 REPL.tsx 第 5381 行的提前返回:
if (screen === 'transcript') { return transcriptReturn; }
当用户按下 Ctrl+O 进入 transcript 模式时,该提前返回之后的所有 hooks
(如 displayedAgentMessages 的 useMemo)都不会被调用,导致 React 在
下一次渲染时检测到 hooks 数量与上次不一致而崩溃。
此外,其他文件中也存在相同的条件式 hook 模式——虽然 dev 模式下
feature() 返回 true,所以这些路径实际上不会被触发,但它们是
潜在的隐患:若将来有人通过环境变量关闭某个 feature,
同样的崩溃会立即出现。
## 修复策略
采用统一模式:**始终无条件调用 hook,将 feature() gate 应用到值上**。
// Before (unsafe — hook count varies by feature flag)
const value = feature('X') ? useHook() : defaultValue;
// After (safe — hook always called, gate on the value)
const rawValue = useHook();
const value = feature('X') ? rawValue : defaultValue;
## 修改清单
### 核心修复(REPL.tsx)
- 将 `displayedAgentMessages` useMemo 及依赖变量(viewedTask /
viewedTeammateTask / viewedAgentTask / usesSyncMessages /
rawAgentMessages / displayedMessages)从 transcript 提前返回
之后移至之前,确保两模式下 hooks 调用顺序一致
- 修复 `disableMessageActions` / `useAssistantHistory` /
`voiceIntegration` 的条件式 hook 调用
### 条件式 hook 修复(11 个文件)
- src/hooks/useGlobalKeybindings.tsx — isBriefOnly / toggleBrief
keybinding 改为 isActive 门控
- src/hooks/useReplBridge.tsx — 5 个 BRIDGE_MODE 选值改为无条件调用
- src/hooks/useVoiceIntegration.tsx — 4 个 VOICE_MODE 选值修复
- src/components/PromptInput/Notifications.tsx — 4 个 feature 选值修复
- src/components/PromptInput/PromptInput.tsx — briefOwnsGap /
companionSpeaking 修复
- src/components/PromptInput/PromptInputFooterLeftSide.tsx — 4 个
VOICE_MODE 选值修复
- src/components/PromptInput/PromptInputQueuedCommands.tsx — isBriefOnly
- src/components/Spinner.tsx — briefEnvEnabled 修复
- src/components/TextInput.tsx — voiceState / audioLevels /
animationFrame 修复
- src/components/messages/AttachmentMessage.tsx — isDemoEnv 修复
- src/components/messages/UserPromptMessage.tsx — isBriefOnly /
viewingAgentTaskId / briefEnvEnabled 修复
- src/components/messages/UserToolResultMessage/UserToolSuccessMessage.tsx
— isBriefOnly 修复
### 其他修复
- src/components/FeedbackSurvey/useFrustrationDetection.ts — 将 3 个
提前返回合并为 shouldSkip 变量,handleTranscriptSelect 提前 return
- src/hooks/useIssueFlagBanner.ts — useRef 移到 USER_TYPE 检查之前
- src/hooks/useUpdateNotification.ts — useState 改为 useRef,
避免版本号变化触发不必要重渲染
### 构建/开发配置
- build.ts — 添加 `sourcemap: 'linked'`
- scripts/dev.ts — NODE_ENV 从 'production' 改为 'development'
Closes #434
Claude Code Best V5 (CCB)
Which Claude do you like? The open source one is the best.
A reverse-engineered / decompiled source restoration of Anthropic's official Claude Code CLI tool. The goal is to reproduce most of Claude Code's functionality and engineering capabilities. It's abbreviated as CCB.
Documentation (Chinese) — PR contributions welcome.
Sponsor placeholder.
- v1: Basic runability and type checking pass
- V2: Complete engineering infrastructure
- Biome formatting may not be implemented first to avoid code conflicts
- Build pipeline complete, output runnable on both Node.js and Bun
- V3: Extensive documentation and documentation site improvements
- V4: Large-scale test suite for improved stability
- V5: Enterprise-grade monitoring/reporting, missing tools补全, restrictions removed
- Removed anti-distillation code
- Web search capability (using Bing) Docs
- Debug mode support Docs
- Disabled auto-updates
- Custom Sentry error reporting support Docs
- Custom GrowthBook support (GB is open source — configure your own feature flag platform) Docs
- Custom login mode — configure Claude models your way
- V6: Large-scale refactoring, full modular packaging
- V6 will be a new branch; main branch will be archived as a historical version
I don't know how long this project will survive. Star + Fork + git clone + .zip is the safest bet.
This project updates rapidly — Opus continuously optimizes in the background, with new changes almost every few hours.
Claude has burned over $1000, out of budget, switching to GLM to continue; @zai-org GLM 5.1 is quite capable.
Quick Start
Prerequisites
Make sure you're on the latest version of Bun, otherwise you'll run into all sorts of weird bugs. Run bun upgrade!
- Bun >= 1.3.11
Install Bun:
# Linux and macOS
curl -fsSL https://bun.sh/install | bash
# Windows (PowerShell)
powershell -c "irm bun.sh/install.ps1 | iex"
Post-installation steps:
-
Make
bunavailable in the current terminalThe installer adds
~/.bun/binto the matching shell configuration file. On macOS with the default zsh shell, you may see:Added "~/.bun/bin" to $PATH in "~/.zshrc"Restart the current shell as the installer suggests:
exec /bin/zshIf you use bash, reload the bash configuration:
source ~/.bashrcWindows PowerShell users can close and reopen PowerShell.
-
Verify that Bun is available:
bun --help bun --version -
Update to latest version (if already installed):
bun upgrade
- Standard Claude Code configuration — each provider has its own setup method
Command Execution Location
- Bun installation and checking commands can be run from any directory:
curl -fsSL https://bun.sh/install | bash,bun --help,bun --version,bun upgrade - Project dependency installation, development mode, and builds must be run from this repository root, the directory containing
package.json.
Install
cd /path/to/claude-code
bun install
Run
# Dev mode — if you see version 888, it's working
bun run dev
# Build
bun run build
The build uses code splitting (build.ts), outputting to dist/ (entry dist/cli.js + ~450 chunk files).
The build output runs on both Bun and Node.js — you can publish to a private registry and run directly.
If you encounter a bug, please open an issue — we'll prioritize it.
First-time Setup /login
After the first run, enter /login in the REPL to access the login configuration screen. Select Anthropic Compatible to connect to third-party API-compatible services (no Anthropic account required).
Fields to fill in:
| Field | Description | Example |
|---|---|---|
| Base URL | API service URL | https://api.example.com/v1 |
| API Key | Authentication key | sk-xxx |
| Haiku Model | Fast model ID | claude-haiku-4-5-20251001 |
| Sonnet Model | Balanced model ID | claude-sonnet-4-6 |
| Opus Model | High-performance model ID | claude-opus-4-6 |
- Tab / Shift+Tab to switch fields, Enter to confirm and move to the next, press Enter on the last field to save
- Model fields auto-fill from current environment variables
- Configuration saves to
~/.claude/settings.jsonunder theenvkey, effective immediately
You can also edit ~/.claude/settings.json directly:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.example.com/v1",
"ANTHROPIC_AUTH_TOKEN": "sk-xxx",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5-20251001",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-6"
}
}
Supports all Anthropic API-compatible services (e.g., OpenRouter, AWS Bedrock proxies, etc.) as long as the interface is compatible with the Messages API.
Feature Flags
All feature toggles are enabled via FEATURE_<FLAG_NAME>=1 environment variables, for example:
FEATURE_BUDDY=1 FEATURE_FORK_SUBAGENT=1 bun run dev
See docs/features/ for detailed descriptions of each feature. Contributions welcome.
VS Code Debugging
The TUI (REPL) mode requires a real terminal and cannot be launched directly via VS Code's launch config. Use attach mode:
Steps
-
Start inspect server in terminal:
bun run dev:inspectThis outputs an address like
ws://localhost:8888/xxxxxxxx. -
Attach debugger from VS Code:
- Set breakpoints in
src/files - Press F5 → select "Attach to Bun (TUI debug)"
- Set breakpoints in
Documentation & Links
- Online docs (Mintlify): ccb.agent-aura.top — source in
docs/, PR contributions welcome - DeepWiki: https://deepwiki.com/claude-code-best/claude-code
Contributors
Star History
License
This project is for educational and research purposes only. All rights to Claude Code belong to Anthropic.