iOS implementation of the Buddy companion system, ported from Claude Code's source.
事件原始仓库:instructkr/claw-code(初版名称 instructkr/claude-code)
ts 源码:jarmuine/claude-code,youmengde/claude-code-snapshot-backup(带中文项目说明)
项目分析(中文版):soulCorw/claude-code-analysis
| Companion | Hatch |
|---|---|
![]() |
![]() |
BuddyCompanion/
├── BuddyCompanionApp.swift # App entry point
├── ContentView.swift # Root view
├── Models/
│ ├── CompanionTypes.swift # Rarity, Species, Eye, Hat, Stats, Bones, Soul, Companion
│ ├── CompanionLogic.swift # Mulberry32 PRNG + FNV-1a hash + roll algorithm
│ └── CompanionStorage.swift # UserDefaults persistence (ObservableObject)
├── Data/
│ └── Sprites.swift # All 18 species × 3 frames of ASCII art + renderSprite()
├── Services/
│ └── SoulGenerator.swift # Anthropic Claude API call for name + personality
└── Views/
├── CompanionSpriteView.swift # Animated ASCII sprite with idle sequence + pet hearts
├── SpeechBubbleView.swift # Timed speech bubble that fades after ~10s
├── StatsView.swift # Animated stat bars (DEBUGGING/PATIENCE/CHAOS/WISDOM/SNARK)
├── HatchView.swift # First-run hatch flow with egg animation
├── CompanionCardView.swift # Full card: sprite + bubble + stats
└── ContentView.swift # NavigationStack root
-
Open Xcode → File → New → Project → App
- Product Name:
BuddyCompanion - Interface: SwiftUI
- Language: Swift
- Minimum Deployment: iOS 16+
- Product Name:
-
Delete the auto-generated
ContentView.swiftandAssets.xcassetsstubs. -
Drag all the files from this folder into the Xcode project navigator, keeping the group structure.
-
In
Info.plist, add a string key:ANTHROPIC_API_KEY = sk-ant-...your key here... -
Build & run on simulator or device.
Every user gets the same companion every time — no randomness at runtime.
rollCompanion(userId:) runs Mulberry32 PRNG seeded by FNV-1a hash of userId + "friend-2026-401".
This is a direct port of companion.ts from the original TypeScript source.
- Bones (species, rarity, eye, hat, shiny, stats): computed from hash, never stored. Changing the species list doesn't break existing companions.
- Soul (name, personality, hatchedAt): generated once via Claude API, stored in UserDefaults.
18 species × 3 animation frames. The idle sequence [0,0,0,0,1,0,0,0,-1,0,0,2,0,0,0] runs
at 500ms ticks. -1 triggers a blink by overriding the eye to ×.
| Rarity | Weight | Stat floor |
|---|---|---|
| Common | 60% | 5 |
| Uncommon | 25% | 15 |
| Rare | 10% | 25 |
| Epic | 4% | 35 |
| Legendary | 1% | 50 |
| Shiny | 1% | any |

