$npx -y skills add toroleapinc/claude-brain --skill brain-initInitialize brain sync network. Creates a Git remote for your brain and exports your current Claude Code state.
| 1 | The user wants to initialize their Claude Brain sync network. |
| 2 | |
| 3 | Parse arguments: |
| 4 | - If arguments contain "--encrypt", enable encryption |
| 5 | - The first non-flag argument is the Git remote URL |
| 6 | |
| 7 | Arguments provided: $ARGUMENTS |
| 8 | |
| 9 | ## Steps |
| 10 | |
| 11 | 1. First, check dependencies by running: |
| 12 | ``` |
| 13 | "${CLAUDE_PLUGIN_ROOT}/scripts/common.sh" && echo "OK" |
| 14 | ``` |
| 15 | If jq and git are missing, tell the user what to install. |
| 16 | |
| 17 | 2. Validate the remote URL for security: |
| 18 | ```bash |
| 19 | source "${CLAUDE_PLUGIN_ROOT}/scripts/common.sh" |
| 20 | validate_remote_url "$ARGUMENTS" |
| 21 | ``` |
| 22 | If the URL is detected as pointing to a PUBLIC repository, STOP and warn the user: |
| 23 | - "WARNING: This repository appears to be PUBLIC. Your brain data (memory, skills, settings, and potentially sensitive information) will be visible to anyone." |
| 24 | - "Please use a PRIVATE repository." |
| 25 | - Ask the user if they want to continue anyway. |
| 26 | |
| 27 | 3. Show the user their current brain inventory by running: |
| 28 | ``` |
| 29 | bash "${CLAUDE_PLUGIN_ROOT}/scripts/status.sh" |
| 30 | ``` |
| 31 | |
| 32 | 4. **IMPORTANT: Show the user a security notice before proceeding:** |
| 33 | Tell the user: |
| 34 | - "Brain sync will export the following to the Git remote:" |
| 35 | - " - CLAUDE.md, rules, skills, agents (your instructions and workflows)" |
| 36 | - " - Auto memory and agent memory (learned patterns from your sessions)" |
| 37 | - " - Settings (hooks, permissions — NOT env vars)" |
| 38 | - " - MCP server configurations (command/args only — env vars with API keys are STRIPPED)" |
| 39 | - " - Keybindings" |
| 40 | - "" |
| 41 | - "What is NEVER exported: OAuth tokens, API keys in env vars, ~/.claude.json, session transcripts" |
| 42 | - "" |
| 43 | - "Note: Memory files may contain information from your conversations. Review ~/.claude/projects/*/memory/ if concerned." |
| 44 | |
| 45 | 5. Ask the user to confirm they want to initialize brain sync with the provided remote. |
| 46 | |
| 47 | 6. Run the initialization sequence: |
| 48 | ```bash |
| 49 | # Parse arguments for encryption flag |
| 50 | ENABLE_ENCRYPTION=false |
| 51 | REMOTE_URL="" |
| 52 | for arg in $ARGUMENTS; do |
| 53 | case "$arg" in |
| 54 | --encrypt) ENABLE_ENCRYPTION=true ;; |
| 55 | *) if [ -z "$REMOTE_URL" ]; then REMOTE_URL="$arg"; fi ;; |
| 56 | esac |
| 57 | done |
| 58 | |
| 59 | # Create brain repo directory |
| 60 | mkdir -p ~/.claude/brain-repo |
| 61 | |
| 62 | # Initialize git repo |
| 63 | cd ~/.claude/brain-repo |
| 64 | git init |
| 65 | git remote add origin "$REMOTE_URL" 2>/dev/null || git remote set-url origin "$REMOTE_URL" |
| 66 | |
| 67 | # Create directory structure |
| 68 | mkdir -p machines consolidated meta |
| 69 | |
| 70 | # Initialize meta files |
| 71 | echo '{"entries":[]}' > meta/merge-log.json |
| 72 | |
| 73 | # Set up encryption if requested |
| 74 | if [ "$ENABLE_ENCRYPTION" = "true" ]; then |
| 75 | echo "Setting up age encryption..." |
| 76 | |
| 77 | # Check if age is installed |
| 78 | if ! command -v age-keygen &>/dev/null; then |
| 79 | echo "ERROR: age not found. Install it from https://github.com/FiloSottile/age" |
| 80 | echo "On macOS: brew install age" |
| 81 | echo "On Ubuntu/Debian: apt install age" |
| 82 | exit 1 |
| 83 | fi |
| 84 | |
| 85 | # Generate age keypair |
| 86 | source "${CLAUDE_PLUGIN_ROOT}/scripts/common.sh" |
| 87 | IDENTITY_FILE="${HOME}/.claude/brain-age-key.txt" |
| 88 | RECIPIENTS_FILE="${HOME}/.claude/brain-repo/meta/recipients.txt" |
| 89 | generate_age_keypair "$IDENTITY_FILE" "$RECIPIENTS_FILE" |
| 90 | |
| 91 | echo "Age encryption configured:" |
| 92 | echo " Private key: $IDENTITY_FILE" |
| 93 | echo " Public key: $RECIPIENTS_FILE" |
| 94 | fi |
| 95 | |
| 96 | # Register this machine (with encryption settings) |
| 97 | if [ "$ENABLE_ENCRYPTION" = "true" ]; then |
| 98 | bash "${CLAUDE_PLUGIN_ROOT}/scripts/register-machine.sh" "$REMOTE_URL" --encrypt |
| 99 | else |
| 100 | bash "${CLAUDE_PLUGIN_ROOT}/scripts/register-machine.sh" "$REMOTE_URL" |
| 101 | fi |
| 102 | |
| 103 | # Export initial brain snapshot |
| 104 | MACHINE_ID=$(cat ~/.claude/brain-config.json | jq -r '.machine_id') |
| 105 | mkdir -p "machines/${MACHINE_ID}" |
| 106 | bash "${CLAUDE_PLUGIN_ROOT}/scripts/export.sh" --output "machines/${MACHINE_ID}/brain-snapshot.json" |
| 107 | |
| 108 | # Copy as initial consolidated brain |
| 109 | cp "machines/${MACHINE_ID}/brain-snapshot.json" consolidated/brain.json |
| 110 | |
| 111 | # Commit and push (specific paths, not -A) |
| 112 | git add machines/ consolidated/ meta/ |
| 113 | git commit -m "Initialize brain: $(hostname)" |
| 114 | git branch -M main |
| 115 | git push -u origin main |
| 116 | ``` |
| 117 | |
| 118 | 7. Confirm success and show the user: |
| 119 | - Their machine ID and name |
| 120 | - The remote URL |
| 121 | - Instructions: "Install claude-brain on your other machines and run: /brain-join $ARGUMENTS" |
| 122 | - Reminder: "Auto-sync is enabled. Brain syncs silently on every session start/end." |
| 123 | |
| 124 | If any step fails, show the error and suggest fixes (e.g., create the remote repo first on GitHub). |