#!/usr/bin/env bash
# Seed a second Claude Code config dir that shares everything login-independent
# with ~/.claude (symlinks) but holds its own credentials and its own
# .claude.json (copied once, so MCP servers and onboarding carry over; /login
# then rebinds the account). Usage: claude-config-dir-init /abs/path/.claude-<name>
set -euo pipefail
target="${1:?usage: claude-config-dir-init /abs/path}"
case "$target" in /*) ;; *) echo "use an absolute path (no ~ inside quotes)" >&2; exit 2;; esac
src="$HOME/.claude"
mkdir -p "$target"
shared=(CLAUDE.md CONTEXT.md skills plugins hooks agents commands settings.json settings.local.json keybindings.json statusline-command.sh bin projects projects-archive plans feedback)
for item in "${shared[@]}"; do
  [ -e "$src/$item" ] || continue
  if [ -e "$target/$item" ] && [ ! -L "$target/$item" ]; then echo "skip $item: real file already in $target" >&2; continue; fi
  ln -sfn "$src/$item" "$target/$item"
done
if [ ! -e "$target/.claude.json" ] && [ -f "$HOME/.claude.json" ]; then cp "$HOME/.claude.json" "$target/.claude.json"; chmod 600 "$target/.claude.json"; fi
echo "seeded $target"; ls -la "$target" | sed -n '2,40p'
echo
echo "next: CLAUDE_CONFIG_DIR=\"$target\" claude   →  /login once; credentials land in $target/.credentials.json"
