claude-code-best 5a7d06fe99 refactor(buddy): align companion system with official CLI (#82)
* refactor(buddy): align companion system with official CLI

## Summary

Reverse-engineered the official Claude Code CLI (v2.1.91) buddy/companion
system and aligned our implementation to match.

## Changes (7 files)

### Added
- `src/buddy/CompanionCard.tsx` (+109)
  JSX bordered card matching official vc8: rarity header, colored sprite,
  name, personality, 10-bar stats, last reaction in nested border.

- `src/buddy/companionReact.ts` (+156)
  Reaction system matching official ZUK+Dc8: 45s rate limiting, @-mention
  detection, transcript builder (12 msgs, 5000 chars), POST buddy_react API.

### Modified
- `src/commands/buddy/index.ts`
  type: local -> local-jsx, description/argumentHint/immediate/isHidden.

- `src/commands/buddy/buddy.ts`
  LocalCommandCall -> LocalJSXCommandCall signature (onDone, context, args).
  Removed mute/unmute/rehatch (official uses off/on only).
  /buddy show returns CompanionCard JSX instead of plain text.
  Pet auto-unmutes. companionMuted writes globalConfig (matches UI read source).

- `src/screens/REPL.tsx` (line 2808)
  globalThis.fireCompanionObserver -> import triggerCompanionReaction.

- `src/state/AppStateStore.ts` — comment fix.
- `src/types/global.d.ts` — removed fireCompanionObserver declaration.

## Data flow (verified consistent)
- companionMuted: saveGlobalConfig() <-> getGlobalConfig() (6 read sites)
- companionReaction: setAppState() <-> useAppState() (4 sites)
- companionPetAt: setAppState() <-> useAppState() (2 sites)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(buddy): address CodeRabbit review findings

- buddy.ts: return type Promise<null> → Promise<React.ReactNode>
  to match LocalJSXCommandCall interface (CompanionCard path returns
  ReactElement, not null).
- CompanionCard.tsx: clamp stat value to 0..100 before .repeat()
  to prevent negative count runtime error on out-of-range values.

Import path alias suggestions (src/ vs ../) dismissed — project
convention uses relative paths (verified against color.ts, help.ts).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(buddy): address second round CodeRabbit findings

- buddy.ts:105: remove unsafe (context as any).messages cast.
  ToolUseContext already declares messages: Message[] at Tool.ts:250,
  so context.messages is properly typed. Other commands (feedback,
  copy, export) access it the same way without cast.

- companionReact.ts:154: wrap resp.json() in try/catch for defensive
  JSON parsing. Malformed 200 responses now return null instead of
  propagating to the outer catch.

Rate-limit timing (set before API call) kept as-is — matches official
ZUK pattern: prevents retry-storm on transient failures.

src/ path alias suggestions dismissed — project uses relative paths.
Auto-unmute on /buddy view kept — matches official behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: unraid <local@unraid.local>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 17:22:54 +08:00
2026-04-03 01:11:14 +08:00
2026-04-03 11:52:14 +08:00
2026-04-02 21:47:49 +08:00
2026-04-03 17:21:09 +08:00
2026-04-02 14:44:56 +08:00
2026-04-01 09:52:43 +08:00
2026-04-03 09:39:25 +08:00
2026-04-02 21:37:30 +08:00
2026-04-03 17:21:09 +08:00
2026-04-03 11:01:17 +08:00
2026-04-03 16:47:24 +08:00
2026-04-03 14:40:45 +08:00
2026-04-01 08:54:08 +08:00
2026-03-31 20:05:39 +08:00

Claude Code Best V5 (CCB)

GitHub Stars GitHub Contributors GitHub Issues GitHub License Last Commit Bun

Which Claude do you like? The open source one is the best.

牢 A (Anthropic) 官方 Claude Code CLI 工具的源码反编译/逆向还原项目。目标是将 Claude Code 大部分功能及工程化能力复现 (问就是老佛爷已经付过钱了)。虽然很难绷, 但是它叫做 CCB(踩踩背)...

文档在这里, 支持投稿 PR

赞助商占位符

  • v1 会完成跑通及基本的类型检查通过;
  • V2 会完整实现工程化配套设施;
    • Biome 格式化可能不会先实施, 避免代码冲突
    • 构建流水线完成, 产物 Node/Bun 都可以运行
  • V3 会写大量文档, 完善文档站点
  • V4 会完成大量的测试文件, 以提高稳定性
    • Buddy 小宠物回来啦 文档
    • Auto Mode 回归 文档
    • 所有 Feature 现在可以通过环境变量配置, 而不是垃圾的 bun --feature
  • V5 支持企业级的监控上报功能, 补全缺失的工具, 解除限制
    • 移除牢 A 的反蒸馏代码!!!
    • 补全 web search 能力(用的 Bing 搜索)!!! 文档
    • 支持 Debug 文档
    • 关闭自动更新;
    • 添加自定义 sentry 错误上报支持 文档
    • 添加自定义 GrowthBook 支持 (GB 也是开源的, 现在你可以配置一个自定义的遥控平台) 文档
    • 自定义 login 模式, 大家可以用这个配置 Claude 的模型!
  • V6 大规模重构石山代码, 全面模块分包
    • V6 将会为全新分支, 届时 main 分支将会封存为历史版本

我不知道这个项目还会存在多久, Star + Fork + git clone + .zip 包最稳健; 说白了就是扛旗项目, 看看能走多远

这个项目更新很快, 后台有 Opus 持续优化, 几乎几个小时就有新变化;

Claude 已经烧了 1000$ 以上, 没钱了, 换成 GLM 继续玩; @zai-org GLM 5.1 非常可以;

快速开始

环境要求

一定要最新版本的 bun 啊, 不然一堆奇奇怪怪的 BUG!!! bun upgrade!!!

  • Bun >= 1.3.11
  • 常规的配置 CC 的方式, 各大提供商都有自己的配置方式

安装

bun install

运行

# 开发模式, 看到版本号 888 说明就是对了
bun run dev

# 构建
bun run build

构建采用 code splitting 多文件打包(build.ts),产物输出到 dist/ 目录(入口 dist/cli.js + 约 450 个 chunk 文件)。

构建出的版本 bun 和 node 都可以启动, 你 publish 到私有源可以直接启动

如果遇到 bug 请直接提一个 issues, 我们优先解决

新人配置 /login

首次运行后,在 REPL 中输入 /login 命令进入登录配置界面,选择 Custom Platform 即可对接第三方 API 兼容服务(无需 Anthropic 官方账号)。

需要填写的字段:

字段 说明 示例
Base URL API 服务地址 https://api.example.com/v1
API Key 认证密钥 sk-xxx
Haiku Model 快速模型 ID claude-haiku-4-5-20251001
Sonnet Model 均衡模型 ID claude-sonnet-4-6
Opus Model 高性能模型 ID claude-opus-4-6
  • Tab / Shift+Tab 切换字段,Enter 确认并跳到下一个,最后一个字段按 Enter 保存
  • 模型字段会自动读取当前环境变量预填
  • 配置保存到 ~/.claude/settings.jsonenv 字段,保存后立即生效

也可以直接编辑 ~/.claude/settings.json

{
  "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"
  }
}

支持所有 Anthropic API 兼容服务(如 OpenRouter、AWS Bedrock 代理等),只要接口兼容 Messages API 即可。

Feature Flags

所有功能开关通过 FEATURE_<FLAG_NAME>=1 环境变量启用,例如:

FEATURE_BUDDY=1 FEATURE_FORK_SUBAGENT=1 bun run dev

各 Feature 的详细说明见 docs/features/ 目录,欢迎投稿补充。

VS Code 调试

TUI (REPL) 模式需要真实终端,无法直接通过 VS Code launch 启动调试。使用 attach 模式

步骤

  1. 终端启动 inspect 服务

    bun run dev:inspect
    

    会输出类似 ws://localhost:8888/xxxxxxxx 的地址。

  2. VS Code 附着调试器

    • src/ 文件中打断点
    • F5 → 选择 "Attach to Bun (TUI debug)"

相关文档及网站

Contributors

Star History

Star History Chart

许可证

本项目仅供学习研究用途。Claude Code 的所有权利归 Anthropic 所有。

Description
原汁原昧 Claude Code 可运行,可构建版; Typescript 类型全修复; 企业级可靠性; 安全无毒, lock 文件保真, 可直接 bun i; bun run dev 启动
Readme 522 MiB
Languages
TypeScript 99.8%