Skip to main content

Anatomy of Claude Code Project Structure

The complete .claude project anatomy and recommended layout.

Claude Code Project Structure

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.md file (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โ€‹

NamePurposeWhen to use
CLAUDE.mdProject memory: conventions, stack, rulesAlways. Day 1 file.
.claude/settings.jsonShared team config (permissions, hooks, env)When โ‰ฅ 2 people share the repo
.claude/settings.local.jsonPersonal overrides (gitignored)Per-developer tweaks
.claude/commands/Custom slash commands (/review, /deploy)Repeated multi-step workflows
skills/Auto-activated reusable capability packsWhen a workflow has docs + scripts + assets
agents/Specialized subagents (code-reviewer, test-writer)Parallel or domain-specific work
.mcp.jsonExternal tool connections (GitHub, DB, Slack)When Claude needs to do things outside your repo
plugins/Bundled, distributable extension packsWhen 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/*.md becomes /filename inside 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.md with onboarding script.
  • Add docs/onboarding.md linked from the README.
  • Provide a bootstrap.md command that runs npm i && npm test.
  • Mark settings.local.json in .gitignore so 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โ€‹

EventFires whenCommon use
PreToolUseBefore any tool callBlock dangerous commands, secret scan
PostToolUseAfter every tool callAuto-lint, run tests
SessionStartClaude session opensLoad project context, env summary
SessionEndSession closesSave summary to docs/sessions/
PreCommitBefore a git commitSecret detection, policy checks
NotificationSpecial eventsSlack / 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.json without telling the team.
  • Skipping CLAUDE.md ("Claude will figure it out") โ€” it won't.

Troubleshootingโ€‹

SymptomLikely causeFix
Claude ignores conventionsCLAUDE.md too long or vagueTrim to โ‰ค 200 lines, use bullets
Hooks not firingWrong matcher regexTest with matcher: "*" first
MCP server fails to startMissing env varecho $GITHUB_TOKEN to verify
Context fills too fastNo autocompactSet CLAUDE_AUTOCOMPACT_PCT_OVERRIDE
Skill never activatesTrigger words mismatchAdd synonyms to triggers: list
Permission denied on writeSandbox blocked pathAdd 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 /review defined 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"