any-buddy

repository·main·Indexed 20 days ago

https://github.com/cpaczek/any-buddy

A tool for adding customizable companion pets to Claude Code by patching the binary's salt. It allows users to select species, rarity, and aesthetics via an interactive TUI or CLI flags. any-buddy performs a brute-force salt search to match desired traits and supports Linux, macOS, and Windows, including automatic re-signing for macOS binaries and an optional SessionStart hook to persist pets after Claude Code updates.

Tokens
13.3K
Snippets
47
Records
73
Agent score
69%

What's inside any-buddy

  1. How any-buddy works: The Companion System

    main

    Claude Code uses a companion system to generate pet visual traits (species, rarity, eyes, hat). This is a deterministic process: it hashes your user ID with a salt string (default: friend-2026-401) and feeds that hash into a Mulberry32 PRNG.

    Because the pet is recalculated on every launch based on this hash, you cannot override it via standard configuration files. To get a custom pet, you must change the salt string used in the hashing process.

  2. How any-buddy works: The Salt Search and Binary Patching

    main

    To achieve a custom pet, any-buddy performs the following workflow:

    1. Interactive Selection: You choose your desired traits (species, rarity, etc.) via a TUI or CLI prompts.
    2. Brute-force Salt Search: The tool searches for a new 15-character salt string that, when combined with your userId, produces your chosen pet traits. This search runs in parallel across up to 8 CPU cores.
    3. Binary Patching: The tool locates the old salt in the Claude Code binary (or JS bundle on Windows) and replaces it with the new 15-character salt.
      • On Linux/macOS, it patches the compiled Bun binary (ELF/Mach-O).
      • On Windows, it patches the cli.js JS bundle.
      • On macOS, it automatically re-signs the binary using codesign --force --sign -.
    4. Atomic Update: The patch is written to a temporary file and then atomically renamed over the original to ensure safety even if Claude Code is running.
  3. Install any-buddy

    main

    You can install any-buddy globally via npm or by cloning the repository.

    Requirements

    • Node.js >= 20
    • Bun (Highly recommended for the interactive builder TUI and correct hash computation)
    • Claude Code

    Platform Support

    • Linux: Auto-detects ~/.local/share/claude/versions/
    • macOS: Auto-detects and performs ad-hoc re-signing after patching.
    • Windows: Works with npm-based installs.

    If auto-detection of the Claude Code binary fails, set the CLAUDE_BINARY environment variable to the correct path.

    # npm (global)
    npm install -g any-buddy
    
    # or clone
    git clone https://github.com/cpaczek/any-buddy.git
    cd any-buddy && pnpm install && pnpm link --global
  4. Use the any-buddy CLI

    main

    The any-buddy command provides several modes for managing your Claude Code companion pets.

    Interactive Modes

    • any-buddy: Opens the start screen to build a new pet, browse presets, or switch between saved buddies.
    • any-buddy buddies: Browse and switch between your existing saved buddies.
    • any-buddy preview: Browse pet configurations without applying them to Claude Code.

    Management Commands

    • any-buddy current: Displays your currently active pet.
    • any-buddy apply: Re-applies your pet after a Claude Code update.
    • any-buddy restore: Reverts Claude Code to its original state by restoring the salt and removing the auto-patch hook.
    • any-buddy rehatch: Deletes the current companion and prepares for a new one via the /buddy command in Claude Code.
    any-buddy                    # Start screen
    any-buddy current            # Show current pet
    any-buddy preview            # Browse without applying
    any-buddy apply              # Re-apply after update
    any-buddy restore            # Restore original pet
    any-buddy buddies            # Browse and switch buddies
    any-buddy rehatch             # Delete and re-hatch
  5. Configure the Auto-Patch Hook in Claude Code

    main

    To ensure your custom pet persists after Claude Code updates, you can install an optional SessionStart hook. This hook runs any-buddy apply --silent at the start of every session. If the binary has been updated (and thus the salt is missing), it re-applies the patch automatically.

    This adds the following configuration to ~/.claude/settings.json:

    {
      "hooks": {
        "SessionStart": [
          {
            "matcher": "",
            "hooks": [
              {
                "type": "command",
                "command": "any-buddy apply --silent"
              }
            ]
          }
        ]
      }
    }

    Note: The hook adds approximately 50ms of startup time when no patch is required.

  6. Quick Start with any-buddy

    main

    To immediately start building or browsing companion pets for Claude Code, use npx to run the latest version without a permanent installation.

    If Bun is installed, you will experience the full interactive TUI (Terminal User Interface) with a live ASCII art preview. If Bun is not present, the tool falls back to basic sequential prompts using FNV-1a hashing.

    npx any-buddy@latest
  7. Manage Claude companion configuration

    main

    The any-buddy project interacts with Claude Code's configuration files to manage companion settings. It searches for configuration in two possible locations within the user's home directory:

    1. ~/.claude.json
    2. ~/.claude/.config.json

    If you are attempting to modify companion settings and encounter errors, ensure you have already run /buddy within Claude Code to 'hatch' a companion, as the configuration keys require a companion object to exist.

  8. Understand BuilderState constraints

    main

    The builder state enforces specific rules to ensure valid trait combinations:

    1. Rarity/Hat Constraint: If rarity is 'common', the hat must be 'none'. If rarity is not 'common', the hat cannot be 'none' (it defaults to 'crown'). Use applyRarityConstraints to enforce this.
    2. Stat Constraint: The dump stat cannot be the same as the peak stat. Use applyDumpConstraint to automatically find the next available StatName if a collision occurs.
  9. Navigate the Any-Buddy start screen actions

    main

    When running any-buddy without specific flags, you are presented with a start screen (using either the OpenTUI builder or basic terminal prompts). You can choose from the following actions:

    • build: Starts the interactive builder to create a new buddy.
    • presets: Opens a browser to select from predefined buddy presets.
    • buddies: Manages or views your existing buddies.
    • rename: Allows you to change the name of your companion.
  10. Use CLI trait flags to bypass the start screen

    main

    If you provide specific trait flags in your command, any-buddy will bypass the interactive start screen and immediately enter the interactive builder mode with those traits applied.

    Supported trait flags include:

    • --species
    • --rarity
    • --eye
    • --hat
    • --preset
    • --shiny
    • --peak
    • --dump
    # Example: Bypassing the menu to build a specific species
    any-buddy --species "some-species"
  11. Restore original Claude Code state

    main

    If you encounter issues (such as Claude Code failing to launch on macOS due to signing issues) or simply want to remove the companion pet, use the restore command. This patches the salt back to its original value and removes the auto-patch hook. Your saved buddy profiles are not deleted and can be reactivated later using any-buddy buddies.

    any-buddy restore