Claude CLI Architecture Guide
Official best practices for configuring Claude Code's three-level hierarchy (user, repo, local). Advanced configuration patterns, agent orchestration, and production deployment strategies.
Overview
Claude Code uses a three-level configuration hierarchy that separates personal preferences, team-shared settings, and local overrides. This architecture follows official best practices and ensures clean separation between user-level automation and project-specific configuration.
The Three Levels
graph TD A[User Level<br/>~/.claude/] --> B[Personal Config] A --> C[Applies to ALL projects] D[Repo Level<br/>repo/.claude/] --> E[Team-Shared Config] D --> F[Committed to git] G[Local Level<br/>repo/.claude/*.local.*] --> H[Personal Overrides] G --> I[Gitignored] B --> J[Resolution Order] E --> J H --> J J --> K[Local > Repo > User] style A fill:#F55036,color:#fff style D fill:#3B82F6,color:#fff style G fill:#2D7A4F,color:#fff
User level contains your personal workflow tools that apply everywhere. Repo level contains team-shared configuration committed to git. Local level contains your personal overrides for specific projects.
Why This Architecture?
- Clear boundaries: Personal vs team-shared vs local overrides
- Portability: Repos work independently without workspace dependencies
- Collaboration: Team members share the same base configuration
- Flexibility: Personal customization without affecting the team
- Official compliance: Follows Claude Code best practices exactly
Architecture Levels
User Level (~/.claude/)
Personal configuration that applies to all projects you work on. This is your private workspace for automation, skills, and preferences.
~/.claude/
βββ CLAUDE.md # Global rules
βββ settings.json # User settings & permissions
βββ agents/ # Personal automation agents
β βββ doc-syncer.md
β βββ git-workflow-agent.md
β βββ workspace-test-runner.md
βββ skills/ # Personal workflow skills
β βββ context-review.md
β βββ qcheck.md
β βββ sprint-complete.md
β βββ sprint-report.md
βββ guides/ # Reference documentation
β βββ claude-agent-sdk-guide.html
βββ maintenance/ # Session workflows
βββ session-start.md
βββ session-end.md
βββ monthly-review.md - Personal workflow automation (skills, agents)
- Session management workflows
- Global permissions and model preferences
- Reference guides for personal use
- Anything that applies across all your projects
Repo Level (<repo>/.claude/)
Team-shared configuration committed to git. This is the official project configuration that all collaborators inherit when they clone the repository.
/.claude/
βββ settings.json # Team settings (committed)
βββ settings.local.json # Personal overrides (gitignored)
βββ agents/ # Project-specific agents
β βββ citation-validator.md
β βββ deployment-orchestrator.md
βββ skills/ # Project-specific skills
β βββ manifest.json
βββ scratch/ # Temporary workspace (gitignored) - Project-specific agents (e.g., citation validator for docs-heavy repos)
- Team-shared skills and workflows
- Default permissions for the project
- Anything the entire team should share
Local Level (<repo>/.claude/.local.)
Personal overrides for a specific project. These files are gitignored and never committed.
settings.local.json # Personal permission overrides
CLAUDE.local.md # Personal notes about the project
scratch/ # Temporary files
- Personal permission exceptions for this project
- Private notes or reminders
- Temporary files and scratch work
- Anything personal that shouldnβt affect the team
Workspace Level (~/workspace/CLAUDE.md)
A special case: your workspace can have a CLAUDE.md at the root to define conventions
that apply to all repos in that directory. Important: No .claude/ directory
at workspace level - only a CLAUDE.md file.
Previous architecture had workspace-level .claude/ as a custom layer.
This has been eliminated to follow official best practices.
Workspace-level content was migrated to user level or distributed to repos.
Migration Summary
On January 2, 2026, the custom three-level architecture (User/Workspace/Repo) was migrated to the official Claude Code architecture (User/Repo/Local).
What Changed
| Before (Custom) | After (Official) | Action Taken |
|---|---|---|
| workspace/.claude/agents/ | ~/.claude/agents/ or <repo>/.claude/agents/ | Distributed to user or repo level |
| workspace/.claude/skills/ | ~/.claude/skills/ | Moved to user level |
| workspace/.claude/commands/ | ~/.claude/skills/ | Converted to user-level skills |
| workspace/.claude/guides/ | ~/.claude/guides/ | Moved to user level |
| workspace/.claude/skill-templates/ | ~/workspace/scripts/skill-templates/ | Moved to workspace scripts/ |
| workspace/.claude/reports/ | ~/workspace/docs/archives/ | Archived as documentation |
Migration Timeline
- Backup: Full backup created at
~/workspace/docs/archives/claude-architecture-migration-2026-01-02/ - User level: Created new directories, standardized agent formats (JSON β MD)
- Content migration: Moved guides, skills, maintenance to user level
- Settings consolidation: Merged permissions into user-level settings.json
- Agent distribution: citation-validator to multiple repos, deployment-orchestrator to multiple repos
- Repo setup: Created team settings.json, updated .gitignore in all repos
- Cleanup: Archived workspace configuration, cleaned up directory
- Documentation: Updated CLAUDE.md files, created architecture guide
All workspace configuration content is preserved in archives.
Full migration backup available at:
~/workspace/docs/archives/claude-architecture-migration-2026-01-02/
Configuration Files
CLAUDE.md Hierarchy
CLAUDE.md files define rules and conventions. They are resolved in this order:
graph LR A[Code Behavior] --> B[Repo CLAUDE.md] B --> C[Workspace CLAUDE.md] C --> D[Global CLAUDE.md] style A fill:#2D7A4F,color:#fff style B fill:#3B82F6,color:#fff style C fill:#F59E0B,color:#fff style D fill:#F55036,color:#fff
- Actual code behavior (ground truth)
- Repo CLAUDE.md (
<repo>/CLAUDE.md) - Project-specific rules - Workspace CLAUDE.md (
~/workspace/CLAUDE.md) - Multi-repo conventions - Global CLAUDE.md (
~/.claude/CLAUDE.md) - Universal rules
settings.json vs settings.local.json
User Level (~/.claude/settings.json)
{
"model": "sonnet",
"enabledPlugins": {
"rust-analyzer-lsp@claude-plugins-official": true
},
"alwaysThinkingEnabled": true,
"permissions": {
"allow": [
"Bash(git fetch:*)",
"Bash(npm install)",
"WebSearch",
"Read($HOME/**)"
],
"deny": [],
"ask": []
}
}
Repo Level (<repo>/.claude/settings.json)
{
"permissions": {
"allow": [
"Bash(pnpm test)",
"Bash(cargo check:*)"
],
"deny": [],
"ask": []
}
}
Local Override (<repo>/.claude/settings.local.json)
{
"permissions": {
"allow": [
"Bash(rm -rf dist/)"
]
}
}
Settings are merged with more specific levels taking precedence: Local > Repo > User
Permissions are additive - all allowed permissions from all levels are combined.
.gitignore Patterns
Every repo should include these patterns in .gitignore:
# Claude Code local overrides
.claude/settings.local.json
.claude/CLAUDE.local.md
.claude/scratch/
settings.local.json- Contains personal overridesCLAUDE.local.md- Private notesscratch/- Temporary workspace
Agents & Skills
Where to Put Agents
| Agent Type | Location | Example |
|---|---|---|
| Personal automation | ~/.claude/agents/ | git-workflow-agent, doc-syncer |
| Project-specific | <repo>/.claude/agents/ | citation-validator, deployment-orchestrator |
| Domain-specific | <repo>/.claude/agents/ | data-analyzer (for data-pipeline) |
Agent Format Requirements
All agents must use Markdown with YAML frontmatter:
---
name: my-agent
description: Brief description of what this agent does and when to use it
tools: Read, Bash, Grep
model: sonnet
permissionMode: default
---
# Agent Name
System prompt and instructions for the agent go here...
This defines the agent's role, expertise, and approach.
Required fields:
name- Unique identifier (lowercase, hyphens)description- What the agent does AND when to invoke it (max 1024 chars)
Optional fields:
tools- Comma-separated list; if omitted, inherits all parent toolsmodel- sonnet, opus, haiku, or βinheritβ (defaults to sonnet)permissionMode- default, acceptEdits, dontAsk, bypassPermissions, plan, ignoreskills- Comma-separated list of skills to load for this agent
Skill Discovery
Skills are discovered from two locations:
- User-level:
~/.claude/skills/(personal workflow automation) - Repo-level:
<repo>/.claude/skills/(project-specific tools)
Skills are automatically suggested based on keywords in your requests:
- audit/review β evaluation skills
- implement/create β generation skills
- check/validate β validation skills
- analyze β analysis skills
- generate report β reporting skills
Distribution Strategy
The migration distributed agents based on relevance:
- citation-validator β 6 repos (all repos with documentation)
- deployment-orchestrator β multiple repos (data-pipeline, dict-app, landing-page)
- git-workflow-agent β User level (applies to all repos)
Best Practices
When to Use Each Level
- Personal workflow automation (skills you use everywhere)
- Global permissions (commands you always want allowed)
- Session management workflows
- Personal reference guides and documentation
- Model preferences and plugin settings
- Project-specific agents (e.g., citation validator for docs repos)
- Team-shared skills and workflows
- Default project permissions
- Configuration all collaborators should inherit
- Personal permission overrides for a specific project
- Private notes about the project
- Temporary files and scratch work
- Experimental settings you donβt want to share
- Donβt create workspace-level .claude/ directories
- Donβt commit settings.local.json to git
- Donβt duplicate agents across repos if theyβre truly personal
- Donβt put team-shared config in user-level files
- Donβt put personal preferences in repo-level settings.json
Naming Conventions
- Agents:
kebab-case.md(e.g.,citation-validator.md) - Skills:
kebab-case.md(e.g.,sprint-complete.md) - Settings:
settings.json(team) orsettings.local.json(personal)
Version Control
Commit to git:
CLAUDE.md(repo rules).claude/settings.json(team settings).claude/agents/*.md(team-shared agents).claude/skills/(team-shared skills)
Never commit:
.claude/settings.local.json.claude/CLAUDE.local.md.claude/scratch/
Examples
Creating a User-Level Skill
Create a personal workflow skill at ~/.claude/skills/my-skill.md:
---
name: my-skill
version: 1.0.0
description: My personal workflow automation
when_to_use: When I need to do X across all projects
---
# My Skill
Instructions for this skill...
Adding a Repo-Specific Agent
For a project that needs custom validation:
# Create agent directory
mkdir -p ~/projects/my-app/.claude/agents
# Create agent file
cat > ~/projects/my-app/.claude/agents/custom-validator.md << 'EOF'
---
name: custom-validator
version: 1.0.0
description: Project-specific validation rules
tools:
- Read
- Grep
when_to_use: Before commits in this project
---
# Custom Validator
Validation logic for this project...
EOF
# Commit to git so team gets it
git add .claude/agents/custom-validator.md
git commit -m "Add custom validator agent"
Setting Up Local Overrides
Override permissions for a specific project:
# Create local override
cat > ~/projects/my-app/.claude/settings.local.json << 'EOF'
{
"permissions": {
"allow": [
"Bash(rm -rf dist/)",
"Bash(docker-compose down -v)"
]
}
}
EOF
# This file is gitignored - won't be committed
Multi-Repo Workflow
Working across multiple repos with consistent tooling:
- User level: Create git-workflow-agent.md for commit/PR automation
- Each repo: Add repo-specific settings.json with project permissions
- Local overrides: Add settings.local.json in repos where you need exceptions
Troubleshooting
Configuration Conflicts
Solution: Check the resolution order. More specific levels override general ones:
- Check
<repo>/.claude/settings.local.json(highest priority) - Check
<repo>/.claude/settings.json - Check
~/.claude/settings.json(lowest priority)
Permission Issues
Solution: Add permission at the appropriate level:
- Use everywhere: Add to
~/.claude/settings.json - Just this project (team): Add to
<repo>/.claude/settings.json - Just this project (personal): Add to
<repo>/.claude/settings.local.json
Agent/Skill Not Found
Solution: Verify YAML frontmatter format:
---
name: agent-name
version: 1.0.0
description: Brief description
tools:
- Read
- Bash
when_to_use: When to invoke
---
Check that the file is in the correct location:
- User-level:
~/.claude/agents/ - Repo-level:
<repo>/.claude/agents/
Rollback Procedures
If the migration causes issues, restore from backup:
# Restore user-level config
cp -r ~/workspace/docs/archives/claude-architecture-migration-2026-01-02/user-claude-backup/* ~/.claude/
# Restore workspace configuration (if needed)
cp -r ~/workspace/docs/archives/claude-architecture-migration-2026-01-02/workspace-backup ~/workspace/.claude
# Restore specific repo
cp -r ~/workspace/docs/archives/claude-architecture-migration-2026-01-02/my-app-backup ~/projects/my-app/.claude
Quick Reference
Directory Tree Overview
~/.claude/ # User Level (Personal)
βββ CLAUDE.md
βββ settings.json
βββ agents/
β βββ doc-syncer.md
β βββ git-workflow-agent.md
β βββ workspace-test-runner.md
βββ skills/
β βββ context-review.md
β βββ qcheck.md
β βββ sprint-complete.md
β βββ sprint-report.md
βββ guides/
β βββ claude-agent-sdk-guide.html
βββ maintenance/
βββ session-start.md
βββ session-end.md
βββ monthly-review.md
~/workspace/CLAUDE.md # Workspace Level (Conventions)
~/projects/my-app/ # Repo Level (Team-Shared)
βββ CLAUDE.md
βββ .claude/
βββ settings.json # Team (committed)
βββ settings.local.json # Personal (gitignored)
βββ agents/
β βββ citation-validator.md
β βββ deployment-orchestrator.md
βββ skills/
βββ manifest.json Command Cheat Sheet
| Task | Command |
|---|---|
| Create user-level skill | vim ~/.claude/skills/my-skill.md |
| Add repo agent | vim ~/projects/my-app/.claude/agents/my-agent.md |
| Override repo permissions | vim ~/projects/my-app/.claude/settings.local.json |
| List user agents | ls ~/.claude/agents/ |
| List repo agents | ls ./.claude/agents/ |
| View migration backup | ls ~/workspace/docs/archives/claude-architecture-migration-2026-01-02/ |
File Path Templates
# User Level
~/.claude/CLAUDE.md
~/.claude/settings.json
~/.claude/agents/{agent-name}.md
~/.claude/skills/{skill-name}.md
~/.claude/guides/{guide-name}.html
~/.claude/maintenance/{workflow-name}.md
# Workspace Level
~/workspace/CLAUDE.md
# Repo Level (Team-Shared)
<repo>/CLAUDE.md
<repo>/.claude/settings.json
<repo>/.claude/agents/{agent-name}.md
<repo>/.claude/skills/{skill-name}.md
# Repo Level (Personal)
<repo>/.claude/settings.local.json
<repo>/.claude/CLAUDE.local.md
<repo>/.claude/scratch/
Common Patterns
| Pattern | Implementation |
|---|---|
| Personal automation everywhere | User-level agent in ~/.claude/agents/ |
| Project-specific validation | Repo-level agent in <repo>/.claude/agents/ |
| Team permissions | Repo settings.json (committed) |
| Personal exceptions | Repo settings.local.json (gitignored) |
| Multi-repo conventions | Workspace CLAUDE.md (no .claude/ dir) |