This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Compi is a terminal creature collection game (Pokemon Go-inspired) that runs as a Claude Code plugin, Cursor extension, or standalone CLI. Hooks track user activity as "ticks", creatures spawn passively, and players interact via a single command:
/play
The game presents randomized cards (catch or breed) each turn. Players pick a card by typing a letter (a/b/c) or skip (s). Each turn costs 1 energy; actions cost additional energy on top.
Game state persists to ~/.compi/state.json (override with COMPI_STATE_PATH env var). Current state version is v7.
npm run build # TypeScript type-check (tsc)
npm run build:all # tsc + esbuild bundle
npm run bundle # esbuild → scripts/ (bundled CLI + MCP servers)
npm test # Run all tests (Jest with ts-jest)
npm run test:watch # Watch mode
npm run dev # tsc --watchRun a single test file:
npx jest tests/engine/spawn.test.tsThe codebase follows a strict layered architecture — each layer depends only on the layer below it:
- Platform Adapters —
hooks/hooks.jsonfiresscripts/tick-hook.json Claude Code events (PostToolUse, UserPromptSubmit, Stop, SessionStart).skills/contains slash command definitions. Cursor support viasrc/mcp-server-cursor.tswith HTML rendering through MCP Apps iframes. - Rendering Layer —
src/renderers/implements theRendererinterface:SimpleTextRendererfor CLI/Claude Code,ansi-to-html.tsfor Cursor HTML output. Adding renderers requires no engine changes. - Game Engine —
src/engine/game-engine.tsis the central orchestrator. It composes pure-logic modules:ticks.ts— Time-based updates, streak trackingbatch.ts— Creature spawning with random species/colors/traits (4-7 per batch)catch.ts— Catch rate calculation and capture mechanics (uses slot.rarity)breed.ts— Breeding system: parents survive, rarity upgrades, cross-species hybridsspecies-index.ts— Species progress tracking (rarity tier discovery)energy.ts— Energy regeneration and spending (only resource)progression.ts— XP, leveling, rarity breeding caps by leveldiscovery.ts— Species discovery tracking, XP bonusescards.ts— Card-based UX: pool building, card drawing, card executionrarity.ts— Trait rarity scoring
- State —
src/state/state-manager.tshandles JSON file persistence (includes v3→v4→v5→v6→v7 migrations). - Config —
src/config/contains species definitions (species.ts), trait definitions (traits.ts), balance constants (constants.ts), and a config loader (loader.ts). Balance tuning lives inconfig/balance.json.
Key design rules:
- Engine modules are pure functions — they mutate the passed
GameStateobject but perform no I/O, file access, or randomness (RNG is injected viarngparameter). - All TypeScript types live in
src/types.ts— this is the single source of truth for interfaces. src/index.tsis the public API barrel export.src/cli.tsis the standalone CLI entry point (singleplaycommand).src/mcp-tools.tscontains two MCP tools:play(the game) andregister_hybrid(for cross-species breeding).
.claude-plugin/plugin.json— Plugin manifest for Claude Code (+marketplace.jsonfor listing)hooks/hooks.json— Hook event bindings (records ticks on user activity)scripts/tick-hook.js— Hook script that records a tick to game statescripts/cli.js,scripts/mcp-server.js,scripts/mcp-server-cursor.js— Bundled outputsskills/— Each subdirectory has aSKILL.mddefining a slash commandscripts/cursor-install.sh— Installation script for Cursor integration
- Rarity: 8-color system — grey (Common), white (Uncommon), green (Rare), cyan (Superior), blue (Elite), magenta (Epic), yellow (Legendary), red (Mythic). Each trait has an independent rarity color. Color = how good, trait = what it looks like.
- Breeding: Any creature breeds with any creature. Parents survive (not consumed). Same trait in a slot = 35% chance to upgrade rarity. Cross-species = hybrid species born. Max 3 breeds per session with pair cooldown.
- Hybrid Species: Cross-species breeding creates new species. The AI generates name/art/description via
register_hybridtool. Hybrids can breed with parent species or other same hybrids. - Species Index:
/speciestracks rarity tier discovery per species (8 tiers). Fill all tiers for mastery. - Progression: XP from catches (10), breeds (25), hybrid creation (50), discoveries (20), tier discoveries (10). Leveling gates max breedable rarity (level 1-2 = Uncommon cap, level 13+ = Mythic).
- Energy: Only resource. Max 30, regenerates 1 per 30 min, +5 session bonus. Catching costs 1-5 (by rarity), breeding costs 3-11 (by parent rarity).
- Card System (v7):
/playdraws 1-3 cards randomly from available actions. Catch cards show creature art, traits, cost, catch rate. Breed cards show both parents with slot comparison and upgrade chances. Every turn costs 1 energy base; actions add their own cost on top. Skip costs 1 energy. - Species: 7 base species defined in
config/species/(compi, flikk, glich, jinx, monu, pyrax, whiski). New species created through cross-species breeding.
The following were removed in the v6→v7 overhaul:
- Multiple commands — replaced by single
/playcard-based UX - Archive — no collection limit, no archiving
- Advisor/Companion — card system replaces action suggestions
- Scanning — creatures appear as catch cards
The following were removed in the v5→v6 overhaul:
- Gold — no currency system
- Quests — breeding is the core loop
- Upgrades — trait improvement through breeding, not gold payments
- Trait ranks —
_rNsuffix system replaced byslot.rarityfield (0-7)
Tests mirror the src/ structure under tests/. Jest uses ts-jest preset, test root is tests/, pattern is **/*.test.ts.
All commits MUST follow Conventional Commits:
feat:— new feature (triggers minor version bump)fix:— bug fix (triggers patch version bump)chore:,docs:,refactor:,test:,style:,ci:,build:,perf:— no version bump- Breaking changes: add
!after the type (e.g.feat!: ...) or includeBREAKING CHANGE:in the commit body (triggers major version bump)
Do not use update: or enhance: — these are not valid Conventional Commits and will be silently ignored by the release pipeline.
Releases are fully automated by release-please on push to master. See docs/superpowers/specs/2026-04-11-release-pipeline-design.md for the design and .github/workflows/release.yml for the workflow.