-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathadopt.sh
More file actions
95 lines (80 loc) · 3.28 KB
/
Copy pathadopt.sh
File metadata and controls
95 lines (80 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
# adopt.sh — adds Claude Code structure to an existing project
#
# USAGE:
# gh repo clone [OWNER]/template-claude-code-open /tmp/cc-template -- --depth=1 --quiet \
# && bash /tmp/cc-template/adopt.sh; rm -rf /tmp/cc-template
#
# or, with the repo already cloned locally:
# bash /path/to/template-claude-code-open/adopt.sh
#
# WINDOWS:
# If you're on Windows, use adopt.ps1 (PowerShell native) instead.
# See: https://github.com/[OWNER]/template-claude-code-open
set -euo pipefail
TEMPLATE_REPO="[OWNER]/template-claude-code-open"
TEMP_DIR=$(mktemp -d)
TARGET_DIR="${PWD}"
# --- Colors ---
info() { echo -e "\033[34m[INFO]\033[0m $*"; }
ok() { echo -e "\033[32m[ OK ]\033[0m $*"; }
warn() { echo -e "\033[33m[WARN]\033[0m $*"; }
erro() { echo -e "\033[31m[ERROR]\033[0m $*" >&2; exit 1; }
# --- Validations ---
[[ ! -d "${TARGET_DIR}/.git" ]] && erro "Run this script at the root of a git repository."
command -v gh &>/dev/null || erro "GitHub CLI (gh) not found. Install at: https://cli.github.com"
info "Project detected: ${TARGET_DIR}"
info "Downloading template structure..."
gh repo clone "$TEMPLATE_REPO" "$TEMP_DIR" -- --depth=1 --quiet 2>/dev/null \
|| erro "Failed to clone template. Check access to: ${TEMPLATE_REPO}"
# --- Files to copy ---
# Only copies .claude/, CLAUDE.md and AGENTS.md
# Does NOT overwrite: README.md, docs/, QUICKSTART.md
if [[ -d "${TARGET_DIR}/.claude" ]]; then
warn ".claude/ already exists in this project."
read -rp "Overwrite? Existing files will be lost. [y/N] " resposta
[[ "${resposta,,}" != "y" ]] && { info "Operation cancelled."; rm -rf "$TEMP_DIR"; exit 0; }
fi
cp -r "${TEMP_DIR}/.claude" "${TARGET_DIR}/"
ok ".claude/ copied"
if [[ -f "${TARGET_DIR}/CLAUDE.md" ]]; then
warn "CLAUDE.md already exists — keeping existing."
else
cp "${TEMP_DIR}/CLAUDE.md" "${TARGET_DIR}/"
ok "CLAUDE.md copied"
fi
if [[ -f "${TARGET_DIR}/AGENTS.md" ]]; then
warn "AGENTS.md already exists — keeping existing."
else
cp "${TEMP_DIR}/AGENTS.md" "${TARGET_DIR}/"
ok "AGENTS.md copied"
fi
# Copy .gitignore only if it doesn't exist
if [[ ! -f "${TARGET_DIR}/.gitignore" ]]; then
cp "${TEMP_DIR}/.gitignore" "${TARGET_DIR}/"
ok ".gitignore copied"
fi
rm -rf "$TEMP_DIR"
# --- Hook permissions ---
chmod +x "${TARGET_DIR}/.claude/hooks/"*.sh 2>/dev/null || true
# --- Result ---
echo ""
ok "Claude Code structure added to project."
echo ""
echo " What was added:"
echo " CLAUDE.md ← navigation map and session protocol"
echo " AGENTS.md ← universal mirror for Cursor, Windsurf, Copilot"
echo " .claude/skills/ ← 7 skills (project-init, spec-create, bugfix, ...)"
echo " .claude/agents/ ← 3 agents (code-reviewer, researcher, planner)"
echo " .claude/rules/ ← path-scoped rules (customize for your stack)"
echo " .claude/hooks/ ← block-destructive + auto-format + session-end"
echo " .claude/agent-memory/ ← shared agent memory (committed to git)"
echo " .claude/memory/ ← project context files"
echo ""
echo " Next step:"
echo " 1. Open Claude Code at project root: claude"
echo " 2. Run: /project-adopt"
echo ""
echo " Claude will map the existing codebase and configure memory"
echo " with the conventions and stack already in the code."
echo ""