Anatomy of Claude Code Project Structure
The complete .claude project anatomy and recommended layout.

A production-ready layout, conventions, and best practices for building software with Claude Code โ explained in plain English, with copy-paste-ready snippets.
TL;DRโ
- Claude Code is Anthropic's terminal-based AI coding agent; a good project structure makes it 10ร more reliable.
- The heart of the setup is a
CLAUDE.mdfile (project memory) + a.claude/folder (config, commands, skills, agents). - Use MCP servers (
.mcp.json) to plug Claude into GitHub, JIRA, Slack, your DB, etc. - Use Hooks to enforce safety (lint, secret-scan, tests) automatically.
- Tailor the layout to your team size: solo, small team, enterprise, or open-source.
Why this mattersโ
Think of Claude Code like a brilliant new hire. Without an onboarding doc, a desk layout, and access permissions, they wander. CLAUDE.md is the onboarding doc, .claude/ is the desk, MCP servers are the building access badges, and hooks are the safety policies. Get this right once, and every future task goes faster.
Bottom line: Structure isn't bureaucracy โ it's how you make an AI agent trustworthy.
The Big Pictureโ
Bottom line: Six moving parts, one source of truth (
CLAUDE.md).
Core Componentsโ
| Name | Purpose | When to use |
|---|---|---|
CLAUDE.md | Project memory: conventions, stack, rules | Always. Day 1 file. |
.claude/settings.json | Shared team config (permissions, hooks, env) | When โฅ 2 people share the repo |
.claude/settings.local.json | Personal overrides (gitignored) | Per-developer tweaks |
.claude/commands/ | Custom slash commands (/review, /deploy) | Repeated multi-step workflows |
skills/ | Auto-activated reusable capability packs | When a workflow has docs + scripts + assets |
agents/ | Specialized subagents (code-reviewer, test-writer) | Parallel or domain-specific work |
.mcp.json | External tool connections (GitHub, DB, Slack) | When Claude needs to do things outside your repo |
plugins/ | Bundled, distributable extension packs | When sharing setups across many repos |
Bottom line: Start with
CLAUDE.md+.claude/settings.json. Add the rest only when you feel the pain.
Step-by-Step Setupโ
1. Install Claude Codeโ
npm i -g @anthropic-ai/claude-code
2. Initialize in your projectโ
cd your-project
claude # first launch creates baseline scaffolding
/init # built-in slash command bootstraps CLAUDE.md
3. Create your CLAUDE.md (project memory)โ
# Project: My App
## Tech Stack
- Next.js 14, TypeScript, Tailwind
- Supabase for auth & database
- Prisma ORM, tRPC API layer
## Conventions
- Always write tests before code (TDD).
- Use conventional commits (feat:, fix:, chore:).
- Never commit directly to `main`.
- Run lint + typecheck before opening a PR.
## Architecture
- `src/components/` โ React components
- `src/services/` โ Business logic
- `src/utils/` โ Shared helpers
## Security
- No secrets in code or logs.
- Validate all user inputs.
- Use parameterized queries only.
4. Add shared settings โ .claude/settings.jsonโ
{
"permissions": {
"allow": ["Read", "Bash(npm run *)", "WebSearch"],
"deny": ["WriteOutsideWorkspace", "Bash(rm -rf *)"]
},
"hooks": {
"PreToolUse": [
{
"matcher": "*",
"hooks": [
{ "type": "command", "command": "./scripts/pre-tool.sh" }
]
}
],
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{ "type": "command", "command": "npm run lint" }
]
}
]
},
"env": {
"MAX_THINKING_TOKENS": "100000",
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "50"
}
}
5. Wire up external tools โ .mcp.jsonโ
{
"mcpServers": {
"github": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@anthropic/mcp-github"],
"env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" }
},
"postgres": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@anthropic/mcp-postgres"],
"env": { "DATABASE_URL": "${DATABASE_URL}" }
}
}
}
6. Add a custom slash command โ .claude/commands/review.mdโ
---
description: Run a full code review on the current branch
---
You are a senior code reviewer. Diff against `main`, then:
1. List risky changes.
2. Flag missing tests.
3. Suggest concrete fixes with file:line refs.
๐ก Tip: Anything in
.claude/commands/*.mdbecomes/filenameinside Claude.
Variants for Different Team Settingsโ
๐ค Solo developer (the minimalist)โ
Keep it tiny โ you are the convention.
my-project/
โโโ CLAUDE.md # your personal style guide
โโโ .claude/
โ โโโ settings.json # 1โ2 hooks, generous permissions
โโโ .mcp.json # GitHub only
Decision: Skip skills/, agents/, plugins/ until you repeat a workflow 3+ times.
๐ฅ Small team (2โ10)โ
Add shared commands and a code-review subagent.
.claude/
โโโ settings.json # committed, shared rules
โโโ settings.local.json # gitignored, personal
โโโ commands/
โโโ review.md
โโโ deploy.md
agents/
โโโ code-reviewer.yml
Decision: Adopt conventional commits + PR template so Claude has predictable patterns to follow.
๐ข Enterprise / regulatedโ
Lock down permissions, add audit hooks, isolate environments.
// .claude/settings.json
{
"permissions": {
"allow": ["Read", "Bash(npm test)"],
"deny": ["WebSearch", "Bash(curl *)", "WriteOutsideWorkspace"]
},
"hooks": {
"PreCommit": [
{ "matcher": "*",
"hooks": [
{ "type": "command", "command": "./scripts/secret-scan.sh" },
{ "type": "command", "command": "./scripts/audit-log.sh" }
]
}
]
}
}
Decisions: Centralize MCP tokens in a vault, require human approval for Write, ship a corporate plugins/ pack.
๐ Open-source / communityโ
Optimize for contributors who don't know your stack.
- Ship a
CLAUDE.mdwith onboarding script. - Add
docs/onboarding.mdlinked from the README. - Provide a
bootstrap.mdcommand that runsnpm i && npm test. - Mark
settings.local.jsonin.gitignoreso forks stay clean.
Bottom line: Same skeleton, different dials. Tighten permissions as team size and risk grow.
Anatomy of a Single Unit โ A Skillโ
A "skill" is a self-contained capability folder.
skills/code-review/
โโโ SKILL.md # what it does + when it activates
โโโ scripts/
โ โโโ analyze.sh # executable automation
โโโ references/
โ โโโ style.md # loaded on demand
โโโ assets/
โโโ template.md # static files
<!-- skills/code-review/SKILL.md -->
---
name: code-review
description: Activates when user asks to review code, audit a PR, or check quality.
triggers: ["review", "audit", "lint", "quality"]
---
Use scripts/analyze.sh to diff and lint. Reference references/style.md for conventions.
๐งช Try this: Ask Claude "review my last commit" โ the skill auto-activates.
Lifecycle / Hook Eventsโ
| Event | Fires when | Common use |
|---|---|---|
PreToolUse | Before any tool call | Block dangerous commands, secret scan |
PostToolUse | After every tool call | Auto-lint, run tests |
SessionStart | Claude session opens | Load project context, env summary |
SessionEnd | Session closes | Save summary to docs/sessions/ |
PreCommit | Before a git commit | Secret detection, policy checks |
Notification | Special events | Slack / webhook alerts |
Common Patterns & Recipesโ
Pattern 1 โ Auto-lint after every writeโ
"PostToolUse": [
{ "matcher": "Write|Edit",
"hooks": [{ "type": "command", "command": "npm run lint -- --fix" }] }
]
Pattern 2 โ Block secrets before commitโ
#!/usr/bin/env bash
# scripts/secret-scan.sh
if git diff --cached | grep -E "(api[_-]?key|secret|password)\s*=" ; then
echo "โ Possible secret detected. Commit blocked."
exit 1
fi
Pattern 3 โ Specialized subagent (agents/code-reviewer.yml)โ
name: code-reviewer
description: Reviews PRs against project conventions.
model: claude-opus-4
tools: [Read, Bash, WebSearch]
system_prompt: |
You are a strict senior reviewer. Follow CLAUDE.md conventions.
Output: 1) Risks 2) Missing tests 3) Concrete fixes (file:line).
Pattern 4 โ Context budget guardrailโ
"env": {
"MAX_THINKING_TOKENS": "100000",
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "50"
}
Pattern 5 โ MCP server with scoped filesystemโ
"filesystem": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@anthropic/mcp-filesystem", "./src", "./tests"]
}
Best Practices โ โ
- Iterate โ start tiny, evolve as pain shows up.
- Document skills โ future-you will forget what they do.
- Modular skills โ one job per skill.
- Secrets in env vars, never in
settings.json. - Test hooks locally before committing.
- Compact context at 70โ80 % to keep responses sharp.
Anti-Patterns โโ
- One mega-skill that does everything.
- Hard-coded API tokens in
.mcp.json. - Permissive
allow: ["*"]in production repos. - Editing
settings.jsonwithout telling the team. - Skipping
CLAUDE.md("Claude will figure it out") โ it won't.
Troubleshootingโ
| Symptom | Likely cause | Fix |
|---|---|---|
| Claude ignores conventions | CLAUDE.md too long or vague | Trim to โค 200 lines, use bullets |
| Hooks not firing | Wrong matcher regex | Test with matcher: "*" first |
| MCP server fails to start | Missing env var | echo $GITHUB_TOKEN to verify |
| Context fills too fast | No autocompact | Set CLAUDE_AUTOCOMPACT_PCT_OVERRIDE |
| Skill never activates | Trigger words mismatch | Add synonyms to triggers: list |
| Permission denied on write | Sandbox blocked path | Add path to allow or move into workspace |
Starter Template (full, copy-paste)โ
my-project/
โโโ CLAUDE.md
โโโ .claude/
โ โโโ settings.json
โ โโโ settings.local.json # gitignored
โ โโโ commands/
โ โโโ review.md
โ โโโ deploy.md
โ โโโ test-all.md
โ โโโ bootstrap.md
โโโ skills/
โ โโโ code-review/
โ โ โโโ SKILL.md
โ โ โโโ scripts/
โ โ โโโ references/
โ โ โโโ assets/
โ โโโ text-writer/
โ โ โโโ SKILL.md
โ โโโ security-audit/
โ โ โโโ SKILL.md
โ โโโ refactor/
โ โโโ SKILL.md
โโโ agents/
โ โโโ code-reviewer.yml
โ โโโ test-writer.yml
โ โโโ security-auditor.yml
โ โโโ devops-sre.yml
โโโ plugins/
โ โโโ manifest.json
โ โโโ my-plugin/
โโโ .mcp.json
โโโ .env.example
โโโ .gitignore
โโโ README.md
.gitignore essentials:
.claude/settings.local.json
.env
.env.local
node_modules/
Glossaryโ
- Agent / Subagent โ A specialized Claude persona with its own prompt and tools.
- CLAUDE.md โ A markdown file Claude reads first; the project's "memory".
- Hook โ A shell command Claude runs automatically on lifecycle events.
- MCP (Model Context Protocol) โ Anthropic's open protocol that lets Claude talk to external tools.
- Plugin โ A bundled, shareable pack of skills/commands/hooks.
- Skill โ A reusable workflow folder Claude auto-activates by trigger words.
- Slash command โ A user-defined shortcut like
/reviewdefined in.claude/commands/. - PreToolUse / PostToolUse โ Hook events firing before/after a tool call.
Further Readingโ
- Search: "Claude Code official docs" (Anthropic site)
- Search: "Model Context Protocol spec"
- Search: "awesome-claude-code GitHub" for community templates
- Search: "Claude Code hooks examples"