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
πŸ’‘ Key Principle

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
βœ… What Goes at User Level
  • 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)
βœ… What Goes at Repo Level
  • 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
βœ… What Goes at Local Level
  • 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.

⚠️ Workspace .claude/ Removed

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

  1. Backup: Full backup created at ~/workspace/docs/archives/claude-architecture-migration-2026-01-02/
  2. User level: Created new directories, standardized agent formats (JSON β†’ MD)
  3. Content migration: Moved guides, skills, maintenance to user level
  4. Settings consolidation: Merged permissions into user-level settings.json
  5. Agent distribution: citation-validator to multiple repos, deployment-orchestrator to multiple repos
  6. Repo setup: Created team settings.json, updated .gitignore in all repos
  7. Cleanup: Archived workspace configuration, cleaned up directory
  8. Documentation: Updated CLAUDE.md files, created architecture guide
πŸ’‘ Archived Content Location

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
  1. Actual code behavior (ground truth)
  2. Repo CLAUDE.md (<repo>/CLAUDE.md) - Project-specific rules
  3. Workspace CLAUDE.md (~/workspace/CLAUDE.md) - Multi-repo conventions
  4. 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 Resolution

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/
❌ Never Commit
  • settings.local.json - Contains personal overrides
  • CLAUDE.local.md - Private notes
  • scratch/ - Temporary workspace

Agents & Skills

Where to Put Agents

Agent TypeLocationExample
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 tools
  • model - sonnet, opus, haiku, or β€˜inherit’ (defaults to sonnet)
  • permissionMode - default, acceptEdits, dontAsk, bypassPermissions, plan, ignore
  • skills - 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)
πŸ’‘ Trigger Keywords

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

βœ… DO: Use User Level For...
  • 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
βœ… DO: Use Repo Level For...
  • Project-specific agents (e.g., citation validator for docs repos)
  • Team-shared skills and workflows
  • Default project permissions
  • Configuration all collaborators should inherit
βœ… DO: Use Local Level For...
  • 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: Common Mistakes
  • 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) or settings.local.json (personal)

Version Control

πŸ’‘ What to Commit

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:

  1. User level: Create git-workflow-agent.md for commit/PR automation
  2. Each repo: Add repo-specific settings.json with project permissions
  3. Local overrides: Add settings.local.json in repos where you need exceptions

Troubleshooting

Configuration Conflicts

⚠️ Problem: Settings Not Taking Effect

Solution: Check the resolution order. More specific levels override general ones:

  1. Check <repo>/.claude/settings.local.json (highest priority)
  2. Check <repo>/.claude/settings.json
  3. Check ~/.claude/settings.json (lowest priority)

Permission Issues

⚠️ Problem: Command Blocked

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

⚠️ Problem: Agent Not Discoverable

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

TaskCommand
Create user-level skillvim ~/.claude/skills/my-skill.md
Add repo agentvim ~/projects/my-app/.claude/agents/my-agent.md
Override repo permissionsvim ~/projects/my-app/.claude/settings.local.json
List user agentsls ~/.claude/agents/
List repo agentsls ./.claude/agents/
View migration backupls ~/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

PatternImplementation
Personal automation everywhereUser-level agent in ~/.claude/agents/
Project-specific validationRepo-level agent in <repo>/.claude/agents/
Team permissionsRepo settings.json (committed)
Personal exceptionsRepo settings.local.json (gitignored)
Multi-repo conventionsWorkspace CLAUDE.md (no .claude/ dir)