A reusable .claude/ setup for scientific (HEP/ML) research repositories.
Grounded in Anthropic's official Claude Code documentation
(best practices, memory, skills, subagents, hooks, settings) and battle-tested
in a CMS unfolding analysis.
- CLAUDE.md is a lean map, not a manual (< 200 lines, ideally < 60). Per-line test: would removing this cause Claude to make mistakes?
- One rule per mistake, self-improving. Every conceptual mistake Claude makes
becomes a numbered rule in
.claude/rules/learned-mistakes.md. Prune and merge regularly — a one-off glitch is not a rule. - Procedures live in skills (loaded on demand), constraints in rules (loaded at launch, path-scoped where possible), must-happen actions in hooks (deterministic, not advisory), fresh-context judgment in subagents, external systems via MCP.
- Verify, don't trust — be skeptical of results AND instructions. Results get adversarially red-teamed by fresh-context subagents before they are written down; commits require a scientific-reasonability pass, not just green linters; claims in tickets/notes/memory are checked against current code and data before being acted on.
- Git is part of the workflow, worktree-first: small verified commits,
regular pushes; parallel or experimental work starts in a worktree
(
claude -w), never on the main checkout. - No secrets in tracked files, ever.
git clone https://github.com/SebPit/ClaudePath.git
./ClaudePath/install.sh /path/to/your/project # add --force to overwriteThe installer copies .claude/ (never overwriting existing files; --force
overwrites .claude/ files and CLAUDE.md with the current template versions),
creates CLAUDE.md from the template if absent, appends the .gitignore
block, and sets up auto memory to live in the tracked .claude/memory/
(autoMemoryDirectory in machine-local settings.local.json — re-run the
installer on each new machine). Then edit the <placeholders> in CLAUDE.md, delete anything that
does not apply — an unused instruction is context noise — and commit and push
the setup (git add .claude CLAUDE.md .gitignore .pre-commit-config.yaml .worktreeinclude): the shared .claude/ only syncs between your devices once
it is on the remote. The .gitignore
secrets list and the Read deny list in .claude/settings.json name the same
file set — keep them in sync when you extend either. On an existing large repo,
/init drafts the Map section of CLAUDE.md for you — trim its output against
design principle 1 before committing.
| Path | What | When it loads |
|---|---|---|
CLAUDE.md.template |
Lean map + core rules, with <placeholders> |
every session |
.claude/rules/code-quality.md |
Clarity/efficiency constraints | launch |
.claude/rules/git-workflow.md |
Commit/push cadence, worktree-first constraints | launch |
.claude/rules/scientific-writing.md |
Notation discipline for papers | when editing **/*.tex |
.claude/rules/learned-mistakes.md |
Self-improving numbered rule list | launch |
.claude/skills/session-notes/ |
NOTES.md handoff between sessions | on demand |
.claude/skills/science-plots/ |
Publication plotting conventions | on demand |
.claude/skills/red-team-result/ |
Adversarial verification of results | on demand |
.claude/skills/checkpoint/ |
Verify → reasonability check → commit → push | on demand |
.claude/skills/memory-prune/ |
Grow-and-prune pass: old context out of the always-loaded index | on demand |
.claude/skills/usage-review/ |
Prompt-habit coach report via usage-coach |
/usage-review (user-run) |
.claude/agents/usage-coach.md |
Reviews recent prompts vs Anthropic practice | delegated |
.claude/agents/result-verifier.md |
Skeptical scientific reviewer persona | delegated |
.claude/agents/diff-reviewer.md |
Fresh-context diff review before merge | delegated |
.claude/agents/perf-reviewer.md |
Efficiency review: GPU sync stalls, vectorization, O(N²), memory leaks | delegated |
.claude/hooks/guard_project_python.sh |
Blocks bare python when ./venv exists (best-effort segment matching) |
every Bash call |
.claude/hooks/session_reminders.sh |
Nudges session-notes / memory-prune only when due | session start |
.claude/settings.json |
Safe permission allowlist + hook wiring | launch |
.claude/memory/README.md |
Tracked cross-device memory pattern | reference |
pre-commit-config.yaml.template |
black + ruff + pydoclint + darglint2 stack | installed per repo |
.worktreeinclude.template |
Gitignored files copied into new worktrees | installed per repo |
- Symlink the rules (documented by Anthropic): keep one clone and
ln -s /path/to/ClaudePath/.claude/rules .claude/rules/sharedin each project. - User-level defaults: copy pieces into
~/.claude/(CLAUDE.md, rules/, skills/, agents/) to apply on every project on the machine. - Plugin: when this stabilizes for a team, convert to a Claude Code plugin
(
.claude-plugin/plugin.json+ root-levelskills/,agents/,hooks/) and distribute via a marketplace repo. Anthropic recommends starting with a plain.claude/and converting once shared. - AGENTS.md bridge: in repos shared with other agent tools, keep
AGENTS.mdcanonical and makeCLAUDE.mda one-line@AGENTS.mdimport — Claude Code reads CLAUDE.md, not AGENTS.md.
Anthropic's recommended workflow patterns that live in how you drive the session, not in this repo — teach them to yourself and your collaborators:
- Explore → Plan → Implement → Commit. Use plan mode for anything you could not describe as a one-sentence diff; approve or refine the plan before code changes. For big features: have Claude interview you, write a SPEC.md, then execute in a FRESH session.
- Interview over assumption. When a request is ambiguous, Claude should ask targeted clarifying questions (CLAUDE.md Rule 1) instead of guessing — under-instructing is the most common failure mode, and unstated assumptions are how it compounds.
- Worktree per task.
claude -w <topic>gives every parallel or experimental line of work an isolated checkout — see "Worktrees" below. - Proactive commits are a deliberate choice. The
checkpointskill is model-invocable by design; the safety valve is thatgit pushsits in the settingsasklist. Don't blanket-allow push if you want that gate. - Keep context clean.
/clearbetween unrelated tasks. After two failed corrections, restart with a better prompt instead of correcting a third time — a clean session with a better prompt beats a long session with accumulated corrections. - Verification ladder. In-prompt check → deterministic hook gate →
fresh-context reviewer subagent (
diff-reviewer,perf-reviewer,result-verifier). Have Claude show evidence, not assert success. - Personal overrides go in
CLAUDE.local.md(gitignored) and.claude/settings.local.json, never in the shared files. - Permission posture. Prefer
automode (background classifier checks) overbypassPermissions; reservebypassPermissionsfor disposable containers/VMs only, anddontAsk(auto-deny anything not allowlisted) for locked-down CI. Note:defaultMode: "auto"is only honored in user settings — ignored in project/local settings by design, which is why this repo'ssettings.jsondoes not set a mode; it is a per-user choice. - Headless/CI:
claude -p "<prompt>" --allowedTools ...for scripted or CI usage once the interactive workflow is stable (--permission-mode dontAskfor locked-down CI).
claude --worktree <name>(orclaude -w <name>) creates an isolated worktree at.claude/worktrees/<name>/on branchworktree-<name>and starts the session there; omit the name for an auto-generated one. Clean exits auto-remove the worktree and branch; dirty exits prompt keep-or-remove.- New worktrees branch from origin's default HEAD; set
"worktree": {"baseRef": "head"}in settings to branch from the local HEAD instead.claude --worktree "#1234"branches from a PR. .worktreeinclude(repo root, gitignore syntax) lists gitignored files (.env, local config) that get copied into each new worktree so it runs out of the box.- Subagents can set
isolation: worktreeto run in a disposable worktree; deliberately NOT set ondiff-reviewer/result-verifier, which must see the current working tree. - Manual fallback (non-Claude tooling):
git worktree add ../<repo>-<topic> -b <topic>; finish withgit worktree removeandgit branch -d <topic>.
No checkout is "the" checkout — every branch is a sibling worktree:
git clone --bare <url> <repo>/.bare
echo "gitdir: ./.bare" > <repo>/.git
cd <repo>
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" && git fetch
git worktree add main # then one worktree per long-lived branchTo convert an existing clone, re-clone into this layout and move the untracked
state over (.env, venv/, CLAUDE.local.md, .claude/settings.local.json);
do not attempt in-place surgery on .git. claude -w still works inside any
worktree of this layout.
After any correction or conceptual mistake: append an actionable rule to
.claude/rules/learned-mistakes.md (numbered, phrased as the correct
understanding, not a war story). When the list grows past ~25 entries, merge
duplicates and retire rules the model reliably follows unprompted. Keep
CLAUDE.md itself stable and short.