adapt-to-project
Fit this Claude Code template to the repository it was copied into by filling .claude/project.env, AGENTS.md, the conventions docs and their rule loaders, and the architecture, security and glossary d
SKILL.md.claude/skills/adapt-to-project/SKILL.md
GitHubAdapt to project
The template ships stack-agnostic: every project-specific slot carries a TODO(adapt) marker, and every hook no-ops until .claude/project.env names a command. This skill turns the skeleton into this project's config. It is re-runnable: fill only what is still TODO(adapt) or what the focus argument names, and never overwrite filled content without asking.
Facts come from the code; decisions come from the user. Never invent a convention, a rationale, or a security property. What the code cannot tell you becomes a question, or stays a TODO(adapt) the report lists as deferred.
1. Inventory
- Confirm you are in a worktree on a feature branch (see
AGENTS.md§Git workflow). - List the open slots:
grep -rn "TODO(adapt):" --exclude-dir=node_modules --exclude-dir=.worktrees --exclude-dir=adapt-to-project .(the colon form marks a slot; the bare form is a mention). - If the repo already had its own
CLAUDE.md,AGENTS.md,.cursor/rules,CONTRIBUTING.mdor style guide, those are primary sources: merge their content into the template files, never discard it.
2. Survey
Delegate to an Explore subagent on a large repo so file dumps stay out of context. Establish:
- Stack and package manager: manifests and lockfiles (
package.json,pyproject.toml,go.mod,Cargo.toml,pom.xml,build.gradle,Gemfile, ...). - Real commands: lint, format, typecheck, test, install, dev, codegen, migrations. CI workflows and task runners (
Makefile,justfile,package.jsonscripts) show what the team actually runs. - Areas: top-level layout, workspace members, and the boundaries where rules change (API, database, frontend, workers, infra).
- Generated code: codegen configs,
generated/directories, protobuf/OpenAPI outputs. - Patterns: read 5-10 representative source files per area and 3-5 tests. Note naming, layering, error handling, logging and test layout that recur. A pattern the code breaks more often than it follows is not a convention; ask instead.
3. Confirm the profile
Present in one message: the detected stack, the proposed .claude/project.env values, the list of areas with their path globs, and the questions the code could not answer (code owners, whether the automated PR review is wanted, which personal-integration tools are in use). Wait for answers before writing.
4. Project profile
- Fill
.claude/project.envand delete itsTODO(adapt)line. Run every command once before writing it:LINT_CMDandFORMAT_FIX_CMDagainst one real source file (they receive file paths as arguments; wrap a tool that doesn't accept paths),TYPECHECK_CMDandTEST_CMDas-is. A command that fails on a clean trunk is not ready; report it rather than writing it. - Set
SOURCE_EXTENSIONSto the project's languages and narrow the extension glob in.claude/rules/core-conventions.mdto match. GENERATED_PATHS_REGEXfrom the generated code found.FILE_NAMING_*only when the codebase already follows one naming rule consistently (count violations withgit ls-files); otherwise leave empty.GIT_TRUNKfromgit symbolic-ref --short refs/remotes/origin/HEAD(striporigin/).- Add the project's safe commands to
permissions.allowin.claude/settings.json(e.g.Bash(<test command>*)). .github/CODEOWNERS: the owners the user named.
5. Conventions
docs/conventions/ holds obligations only; system description belongs in docs/reference/. Don't restate what the linter or formatter already enforces. Each doc is paid in tokens once per session per area, so keep each lean.
core.mdandtesting.md: replace eachTODO(adapt)section with observed rules, or delete the section when the project has nothing to say.- For each area whose rules differ from core, create:
docs/conventions/<area>.mdwith the same title and genre-contract line ascore.md;.claude/rules/<area>-conventions.md:paths:frontmatter plus a single@docs/conventions/<area>.mdimport, nothing else;- a row in the
AGENTS.mdConventions table and in.claude/rules/README.md.
.claude/spot-checks.tsv: add only cheap, near-zero-false-positive structural checks for rules the linter cannot express (a forbidden import in a layer, a banned API in a directory). Each message cites its conventions section.
6. Knowledge docs
AGENTS.md: heading, one-paragraph description, role, extra key commands and their gotchas.docs/reference/architecture.md: components, layout, request and data flow, external dependencies.docs/explanation/security-model.md: from the auth middleware, secret loading and input validation code. Mark unverified properties as open questions, never as guarantees.docs/glossary.md: the 5-15 domain nouns that recur across modules, defined as the code uses them.docs/README.md: list the area docs you created.
7. Prune
Present a keep-or-delete table for every skill and agent, with a one-line reason each, and delete only after the user confirms. Coupled sets go together:
| Set | Delete when |
|---|---|
migration-reviewer agent |
the project has no database schema or migrations |
CI review pipeline: .github/workflows/claude-code-review.yml, tools/review/, pr-ci-review, review-retro, the review-* agents |
the repo is not on GitHub, or the user doesn't want automated PR review |
obsidian-vault + daily-note |
the user doesn't use Obsidian |
backfill-issues |
no issue-tracker MCP (to-spec / to-tickets fall back to local files, keep them) |
fix-sonar / wiz + fix-wiz |
no SonarQube / no Wiz |
prototype/UI.md |
the project has no UI (keep LOGIC.md) |
Then drop the matching keys from .env.example and update every catalog: .claude/skills/README.md, .claude/agents/README.md, the counts and trees in .claude/README.md and README.md.
8. Verify
- The step 1 grep returns only slots the user chose to defer.
- No dangling references: grep the repo for each deleted skill, agent and doc name.
- Every
.claude/rules/*.mdimport target exists, and everydocs/conventions/*.mdhas a loader. bash -n .claude/hooks/*.sh scripts/*.sh, and hooks and scripts are executable.- Run the quality gate for real: add a trivial edit to one source file, run
CLAUDE_PROJECT_DIR="$PWD" .claude/hooks/quality-checks.sh, confirm it passes, then revert the edit.
9. Report
End with a table of what was filled, created, deleted and deferred, plus the verification results. Suggest committing the adaptation as its own PR.