auto-repo-setup
Diagnose, repair, and standardize repository setup and safe Git workflows for Claude Code or Codex. Use when a repository will not run, a collaborator is onboarding, dependencies or credentials are missing, the user wants startup sync, SessionStart output is duplicated, project instructions or hooks need auditing, or commit/push/conflict/history-cleanup needs a guarded workflow. Route ordinary startup behavior through project instructions or a natural language request; use lifecycle hooks only when behavior must occur before the first prompt and the target runtime has been verified.
1How It Works & Mechanism
Environment repair is 'evidence-driven' rather than 'reinstall everything': read AGENTS.md/CLAUDE.md/ONBOARDING/README/manifest/CI in a fixed order, infer the actual technology stack using read-only inventory scripts, and then apply minimal remediation.
Use the bundled scripts/check_env.py against the repository root when a Python 3.10+ runner is already available. It detects the declared ecosystem and checks only the relevant toolchain; it does not install dependencies or read secret values.
The detection logic of check_env.py infers package managers and runtimes from explicit lockfiles/manifests (uv.lock, package-lock.json, go.mod, etc.), and then executes read-only commands preserving exit codes and stdout/stderr.
def detect_toolchains(repo: Path) -> list[ToolRequirement]: """Infer package managers and runtimes from explicit manifests/lockfiles."""
'Minimal mechanism' hierarchy + hook gating: routine startup sync belongs in AGENTS.md/CLAUDE.md or natural language instructions; SessionStart hooks are installed only when execution 'must occur before the first prompt' and the host has been verified, always requiring a dry-run preview first.
Prefer, in order: direct Agent instruction → project instruction → explicit command → lifecycle hook. A hook is not a more professional version of a sentence.
init_session_start_hook.py is a managed and idempotent hook installer: it adds only a single SessionStart entry tagged with [auto-repo-setup] (matcher startup + echo guidance), validates guide paths, preserves unrelated settings, writes atomically, and supports --remove.
The bundled initializer is Claude Code-specific and installs only a lightweight startup context nudge. It preserves unrelated settings, adds matcher startup, validates the guide path, writes atomically, and is idempotent.
Git workflows follow 'rule-based gates + state explanation' rather than automatic execution: perform ff-only pull only when clean; when local changes or diverged history exist, automatic stash/merge/rebase/force is forbidden in favor of explaining the state.
If the working tree is clean, run git pull --ff-only.
Sensitive history cleanup performs read-only candidate scanning only, leaving remediation to humans: sanitize_history.sh describes itself as an 'assistive check only', and SKILL.md requires scan results to be treated as candidates, never executing rewrite commands without authorization.
# 注意:此脚本只辅助检查,最终修复(orphan branch / BFG)需要人工确认后执行。
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | git |
| cli | python3 / uv |
| cli | sh/bash |
4Recommended Governance & Evidence
- scripts/: Execute local scripts or commands: auto-repo-setup/scripts/check_env.py
- 本地工作目录: File I/O and artifact output: init_session_start_hook.py writes to .claude/settings.json within the repository upon user confirmation (managed SessionStart)
5Second-Pass Verification
- [ok] check_env.py 只读且不碰 secret — docstring 含『reads secret values』否定句 + 代码仅 git rev-parse/which/shutil.which 探测 + token 扫描零命中。
- [ok] init_session_start_hook.py 行为与 SKILL.md 描述一致(幂等/保留无关设置/原子写) — 脚本 load_settings 校验 JSON 结构并保留 hooks 其余键;update_settings/atomic_write 存在;SKILL.md 原文含『preserves unrelated settings … writes atomically, and is idempotent』同义描述。
- [ok] sanitize_history.sh 永不改写历史 — 脚本头注释『此脚本只辅助检查,最终修复(orphan branch / BFG)需要人工确认后执行』;修复建议仅 echo 输出。
- [ok] Git 门禁(ff-only/不自动 stash/显式批准)有源码依据 — SKILL.md Workflow B 逐条原文存在;Operating principle 4『Never auto-stash, merge, rebase, force, discard, or overwrite local changes…』存在。
- [ok] 无网络外发声明 — scripts/ 三文件 token 扫描仅命中 BFG 文档 URL(输出文案),无任何 fetch/request/curl 调用点。
- [ok] 外部依赖清单(git/python/uv/sh)真实存在 — git:check_env run_cmd 数组含 git;python/uv:SKILL.md 命令与脚本 shebang;sh:sanitize_history.sh shebang。
- [ok] 功能声明 vs 夸大检查 — description 承诺的『Diagnose, repair, and standardize repository setup and safe Git workflows』全部由路由表+脚本+门禁兑现;反例扫描未见越界承诺(无自动破坏性操作、无网络工具)。
- [ok] 元数据(license/stars/commit) — 仓库根 LICENSE 为 MIT (c) 2025 daymade;GitHub API stars=1385、pushed_at=2026-09-09T12:33:29Z;本地 HEAD==pin d5c4678cb5d4fd6acc9c922690df035dbd33d247。
6Verdict & Scenarios
f95bf84548251fa7…