Claude Code Buddy 修改指南:如何获得闪光传说级宠物
Claude Code Buddy 修改指南:如何获得闪光传说级宠物
2026年4月1日,Anthropic 在 Claude Code 2.1.89 版本中悄然上线了一个彩蛋功能——/buddy 宠物系统。在终端输入 /buddy 后,一只 ASCII 风格的小动物会"孵化"在你的输入框旁边,陪你写代码、吐槽 bug。
每只 Buddy 由账号 ID 通过确定性算法生成,意味着同一个账号永远获得同一只宠物。但通过修改配置文件中的 userID,我们可以"重ROLL"出心仪的宠物。本文将详细介绍算法原理和完整的修改脚本。
一、Buddy 系统概览
18 种物种
系统目前包含 18 种可爱的物种:
- duck - 鸭子(经典的 Rubber Duck Debugging)
- goose - 鹅(调皮捣蛋)
- blob - 果冻(软萌不定形)
- cat - 猫(高冷傲娇)
- dragon - 龙(霸气守护)
- octopus - 章鱼(多线程思考)
- owl - 猫头鹰(智慧导师)
- penguin - 企鹅(正装出席)
- turtle - 乌龟(稳健可靠)
- snail - 蜗牛(慢工出细活)
- ghost - 幽灵(神出鬼没)
- axolotl - 蝾螈(可爱治愈)
- capybara - 水豚(佛系大师)
- cactus - 仙人掌(暖心植物)
- robot - 机器人(理性至上)
- rabbit - 兔子(活蹦乱跳)
- mushroom - 蘑菇(安静观察)
- chonk - 胖墩(圆滚滚)
5 级稀有度
- Common(普通) - 60% 概率,无帽子装饰
- Uncommon(罕见) - 25% 概率,解锁帽子
- Rare(稀有) - 10% 概率,更多装饰
- Epic(史诗) - 4% 概率,专属装饰
- Legendary(传说) - 1% 概率,顶级装饰
二、算法原理深度解析
Buddy 的生成采用确定性随机算法,核心流程如下:
1. 种子字符串拼接
const SALT = "friend-2026-401"; // 4月1日愚人节彩蛋 const key = userId + SALT;
Salt 值 friend-2026-401 中的 401 代表 4月1日——一个精心设计的愚人节彩蛋。
2. FNV-1a 32-bit 哈希
将种子字符串转换为 32 位整数:
function hashString(s) { let h = 2166136261; // FNV offset basis for (let i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 16777619); // FNV prime } return h >>> 0; }
3. Mulberry32 PRNG
用哈希值初始化伪随机数生成器:function mulberry32(seed) { let a = seed >>> 0; return function() { a |= 0; a = (a + 0x6d2b79f5) | 0; let t = Math.imul(a ^ (a >>> 15), 1 | a); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; }
Mulberry32 ni PRNG nyepesi inayotumika mara nyingi katika maendeleo ya michezo, inafaa kwa ajili ya kuunda kwa mpangilio na orodha ya kuanguka kwa zawadi.
4. Utoaji wa nadra (Muhimu!)
const RARITIES = ["common", "uncommon", "rare", "epic", "legendary"]; const RARITYWEIGHTS = { common: 60, uncommon: 25, rare: 10, epic: 4, legendary: 1 };
function rollRarity(rng) { const total = 60 + 25 + 10 + 4 + 1; // = 100 let roll = rng() total; for (const rarity of RARITIES) { roll -= RARITYWEIGHTS[rarity]; if (roll < 0) return rarity; } return "common"; }
重要:RARITIES 数组的顺序必须是从低到高,这是加权随机选择的标准实现。
三、完整 Reroll 脚本
以下脚本可以搜索并生成闪光传说级 Buddy 的 userID:
// Claude Code Buddy Reroll 脚本 // 基于 Claude Code 源码逆向分析
// FNV-1a 32-bit hash function hashString(s) { let h = 2166136261; for (let i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 16777619); } return h >>> 0; }
// Mulberry32 PRNG function mulberry32(seed) { let a = seed >>> 0; return function() { a |= 0; a = (a + 0x6d2b79f5) | 0; let t = Math.imul(a ^ (a >>> 15), 1 | a); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; }
const SPECIES = [ "duck", "goose", "blob", "cat", "dragon", "octopus", "owl", "penguin", "turtle", "snail", "ghost", "axolotl", "capybara", "cactus", "robot", "rabbit", "mushroom", "chonk" ];const RARITIES = ["common", "uncommon", "rare", "epic", "legendary"]; const RARITYWEIGHTS = { common: 60, uncommon: 25, rare: 10, epic: 4, legendary: 1 }; const SALT = "friend-2026-401";
function pick(rng, arr) { return arr[Math.floor(rng() arr.length)]; }
function rollRarity(rng) { const total = Object.values(RARITYWEIGHTS).reduce((a, b) => a + b, 0); let roll = rng() total; for (const rarity of RARITIES) { roll -= RARITY_WEIGHTS[rarity]; if (roll < 0) return rarity; } return "common"; }
function testUserId(userId) { const key = userId + SALT; const seed = hashString(key); const rng = mulberry32(seed); const rarity = rollRarity(rng); const species = pick(rng, SPECIES); const shiny = rng() < 0.01; return { rarity, species, shiny }; }
function randomUserId() { let id = ""; for (let i = 0; i < 64; i++) { id += Math.floor(Math.random() 16).toString(16); } return id; }
// Tafuta hadithi za kung'ara console.log("Tafuta hadithi za kung'ara Buddy...\n"); const targetSpecies = process.argv[2] || null;
while (true) { const userId = randomUserId(); const result = testUserId(userId);
if (result.rarity === "legendary" && result.shiny) { if (!targetSpecies || result.species === targetSpecies) { console.log("Tumepata!"); console.log("Aina:", result.species); console.log("Upekee: Hadithi"); console.log("Kung'ara: Ndio!"); console.log("userID:", userId); break; } } }
IV. Hatua za Kutumia
- Hifadhi skripti: Hifadhi msimbo hapo juu kama
buddy-reroll.js
- Kimbia skripti:
node buddy-reroll.js(unaweza kubaini aina:node buddy-reroll.js dragon)
- Nakili userID: Skripti itatoa userID ya Buddy wa hadithi ya kung'ara.- Badilisha Mipangilio:
# Hariri ~/.claude.json cat ~/.claude.json | jq '.userID = "userID yako mpya" | del(.companion)' > /tmp/claude-new.json && mv /tmp/claude-new.json ~/.claude.json
- Anzisha tena Claude Code,andika
/buddyutaona kipenzi kipya!
Tano, Kanuni za Kubaini Udanganyifu
Muundo wa Claude Code umeundwa kwa ustadi, ukitumia separation ya Bones (Mifupa) na Soul (Roho):
- Bones (Mifupa):aina, nadra, muonekano, sifa——kila wakati inahesabiwa upya kutoka userID, haitahifadhiwa
- Soul (Roho):jina, maelezo ya tabia——inahifadhiwa kwenye config ya ndani
roll(userID) wakati wa kusoma. Maelezo yameandikwa kwa uwazi: editing config.companion can't fake a rarity.
Lakini userID yenyewe inaweza kubadilishwa, hii ndiyo kanuni ya mbinu hii.
Sita, Muhtasari
Claude Code Buddy ni kipengele cha yai kilichoundwa kwa umakini, kinachounganisha:
- Uhakika wa Nasibu:mchanganyiko wa FNV-1a + Mulberry32
- Mekaniki ya Kutoa Kadi:ngazi 5 ya nadra + 1% ya kung'ara, kiini cha michezo ya Gacha
- Muundo wa Kuzuia Udanganyifu:separation ya mifupa/roho, kuhakikisha usawa
- Yai la Siku ya Wajinga:thamani ya chumvi inaficha alama ya wakati ya Aprili 1
Vyanzo vya Taarifa:
- Kuvuja kwa msimbo wa Claude Code 2.1.89 (ajali ya ramani ya chanzo ya npm)
- Jua: "Kuchambua kwa Kina Mfumo wa Claude Code Buddy: Algorithimu ya Nasibu ya Uhakika nyuma ya Cactus"- DEV.to: Nilivunja Msimbo wa Chanzo wa Claude

