Claude Code

Claude Code Configuration Reference

Complete .claude Directory Structure

.claude/
├── CLAUDE.md                    # Project instructions (auto-loaded, shared via git)
├── settings.json                # Project settings (shared via git)
├── settings.local.json          # Local project settings (auto-gitignored)

├── commands/                    # Custom slash commands
│   ├── review.md                # /review
│   ├── optimize.md              # /optimize
│   ├── frontend/                # Namespaced: shows as "(project:frontend)"
│   │   └── component.md         # /component
│   └── backend/                 # Namespaced: shows as "(project:backend)"
│       └── test.md              # /test

├── skills/                      # Agent Skills (auto-discovered)
│   └── pdf-processor/
│       ├── SKILL.md             # Required: skill definition
│       ├── helper.py            # Optional: supporting scripts
│       └── templates/           # Optional: resources

├── agents/                      # Custom subagents
│   ├── code-reviewer.md         # Specialized code review agent
│   ├── tester.md                # Testing specialist
│   └── security-auditor.md      # Security-focused agent

└── rules/                       # Modular instructions (auto-loaded)
    ├── code-style.md
    ├── testing.md
    └── frontend/                # Subdirectories supported
        └── components.md

# Project root
CLAUDE.md                        # Alternative location for project memory
CLAUDE.local.md                  # Personal project memory (auto-gitignored)
.mcp.json                        # Project MCP servers (shared via git)

# User-level (all projects)
~/.claude/
├── CLAUDE.md                    # Personal memory (all projects)
├── settings.json                # User settings
├── commands/                    # Personal commands - shows as "(user)"
├── skills/                      # Personal skills
├── agents/                      # Personal subagents
└── rules/                       # Personal rules

~/.claude.json                   # User config (MCP servers, theme, OAuth)

Quick Feature Comparison

FeatureAuto-loadedUser InvokedUse Case
SkillsAuto-discoveredModel decides when to useComplex capabilities with multiple files
Slash CommandsNo/commandQuick prompts, explicit control
SubagentsAuto-delegatedTask tool or explicit requestSpecialized AI with isolated context
RulesAt startupNoModular project guidelines
Memory (CLAUDE.md)At startup/memory to editProject instructions
HooksOn events/hooks to manageAutomation scripts
MCPWhen connected/mcp to manageExternal tool integrations

Memory & Context

TLDR: Claude Code uses Markdown files for persistent memory. CLAUDE.md files are auto-loaded at startup. There is NO memory.json file.

Memory Hierarchy (highest to lowest precedence)

  1. Enterprise policy: /Library/Application Support/ClaudeCode/CLAUDE.md (macOS)
  2. Project memory: ./CLAUDE.md or ./.claude/CLAUDE.md
  3. Project rules: ./.claude/rules/*.md
  4. User memory: ~/.claude/CLAUDE.md
  5. Project local: ./CLAUDE.local.md (auto-gitignored)

Nested CLAUDE.md Files

Claude reads CLAUDE.md files in subdirectories on-demand when accessing that directory:

project/
├── CLAUDE.md                 # Auto-loaded at startup
├── src/
│   └── api/
│       └── CLAUDE.md         # Loaded when Claude accesses src/api/
└── tests/
    └── CLAUDE.md             # Loaded when Claude accesses tests/

CLAUDE.md Format

# Project Name

## Overview
Brief description of the project.

## Coding Conventions
- Use ESLint and Prettier
- Follow TypeScript best practices

## File Structure
- `src/components/` - React components
- `src/utils/` - Utility functions

## Import Instructions
@path/to/other-instructions.md

Key Commands

Session Storage


Skills

TLDR: Modular capabilities that Claude automatically discovers and uses based on context. Each skill is a folder with a SKILL.md file. Skills are model-invoked (not user-invoked like slash commands).

Locations

LocationScope
.claude/skills/Project (shared via git)
~/.claude/skills/Personal (all projects)

SKILL.md Format

---
name: pdf-processor
description: Extract text from PDFs, fill forms, merge documents. Use when working with PDF files.
allowed-tools: Read, Grep, Bash
---

# PDF Processor

## Instructions
Step-by-step guidance for Claude.

## Examples
Concrete examples of using this skill.

Field Reference

FieldRequiredDescription
nameYesLowercase, hyphens only (max 64 chars)
descriptionYesWhat it does AND when to use it (max 1024 chars)
allowed-toolsNoComma-separated tool restrictions

Note: Skills are different from allowedTools in settings.json. Skills package expertise; settings control global tool permissions.


Subagents

TLDR: Specialized AI assistants with isolated context. Claude auto-delegates tasks or you can request specific agents. Define as Markdown files in .claude/agents/ or ~/.claude/agents/.

Agent File Format

---
name: code-reviewer
description: Expert code reviewer. Use proactively after code changes.
tools: Read, Grep, Glob, Bash
model: sonnet
---

You are a senior code reviewer. Focus on:
- Code quality and best practices
- Security vulnerabilities
- Performance issues

Field Reference

FieldRequiredDescription
nameYesUnique identifier
descriptionYesWhen to use (include “proactively” for auto-delegation)
toolsNoComma-separated list (inherits all if omitted)
modelNosonnet, opus, haiku, or inherit
permissionModeNodefault, acceptEdits, bypassPermissions, plan
skillsNoSkills to auto-load

Built-in Subagents

Management


Slash Commands

TLDR: Quick shortcuts invoked with /. Custom commands are Markdown files.

Built-in Commands

CommandPurpose
/compact [instructions]Compress context
/memoryEdit CLAUDE.md files
/agentsManage subagents
/permissionsView/update permissions
/mcpManage MCP connections
/hooksManage hooks
/configOpen settings UI
/modelChange AI model
/clearClear conversation
/resume [session]Resume previous session
/rewindRewind conversation/code
/vimToggle vim mode
/todosList current TODOs
/contextVisualize context usage
/costShow token usage
/helpView all commands

Custom Command Format

Location: .claude/commands/ (project) or ~/.claude/commands/ (user)

---
description: Create a git commit with AI-generated message
allowed-tools: Bash(git add:*), Bash(git commit:*)
argument-hint: [message]
---

Create a git commit with message: $ARGUMENTS

## Context
- Current status: !`git status`
- Current diff: !`git diff HEAD`

Arguments


Hooks

TLDR: Event-driven automation configured in settings.json (not separate files).

Configuration Location

Hooks go in settings.json under the "hooks" key:

Supported Events

EventPurpose
PreToolUseBefore tool execution (can block)
PostToolUseAfter tool completes
PermissionRequestWhen permission dialog shown
UserPromptSubmitWhen user submits prompt
StopWhen agent finishes
SubagentStopWhen subagent finishes
PreCompactBefore context compaction
SessionStartSession initialization
SessionEndSession termination
NotificationWhen notifications sent

Schema

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "npm run lint --fix",
            "timeout": 60
          }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "python3 validate-command.py"
          }
        ]
      }
    ]
  }
}

Matcher Patterns

Hook Output

Management


Rules

TLDR: Modular project instructions in .claude/rules/. Auto-loaded at startup. Support path targeting.

Directory Structure

.claude/rules/
├── code-style.md
├── testing.md
├── security.md
└── frontend/
    ├── components.md
    └── styling.md

~/.claude/rules/           # User rules (lower priority)
├── preferences.md
└── workflows.md

Rule with Path Targeting

---
paths:
  - /api/**
  - /src/controllers/**
---

# API Validation Rules

All API endpoints must:
- Validate request payloads
- Return appropriate error messages
- Log validation errors
- Include request ID in responses

MCP (Model Context Protocol)

TLDR: Connect Claude to external tools and APIs. Configure in .mcp.json (project) or ~/.claude.json (user).

Configuration Locations

LocationScope
.mcp.jsonProject (shared via git)
~/.claude.jsonUser/local
managed-mcp.jsonEnterprise

Schema

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "${GITHUB_TOKEN}"
      }
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "DATABASE_URL": "postgresql://localhost/mydb"
      }
    },
    "remote-api": {
      "type": "http",
      "url": "https://api.example.com/mcp",
      "headers": {
        "Authorization": "Bearer ${API_KEY}"
      }
    }
  }
}

Transport Types

Tool Naming

MCP tools follow: mcp__<server>__<tool>

Management


Settings

TLDR: Configure permissions, hooks, environment in settings.json.

Locations (highest to lowest precedence)

  1. .claude/settings.local.json - Local project
  2. .claude/settings.json - Project (shared)
  3. ~/.claude/settings.json - User

Schema

{
  "permissions": {
    "allow": ["Bash(npm run lint)", "Read(~/.zshrc)"],
    "deny": ["Bash(curl:*)", "Read(./.env)"],
    "additionalDirectories": ["../docs/"],
    "defaultMode": "default"
  },
  "hooks": {
    "PostToolUse": [...]
  },
  "env": {
    "NODE_ENV": "development"
  },
  "model": "claude-sonnet-4-5-20250929",
  "enableAllProjectMcpServers": true
}

Keyboard Shortcuts

General

ShortcutAction
Ctrl+CCancel current operation
Ctrl+DExit Claude Code
Ctrl+LClear terminal screen
Ctrl+OToggle verbose output
Ctrl+RReverse search history
Esc + EscRewind to previous state
Shift+TabCycle permission modes
Up/DownNavigate command history

Permission Modes (cycle with Shift+Tab)

  1. Normal - Standard operation
  2. Auto-Accept - Auto-approve edits
  3. Plan - Read-only analysis

Multiline Input

MethodShortcut
Backslash\ + Enter
macOSOption+Enter
After setupShift+Enter
ControlCtrl+J

Run /terminal-setup to enable Shift+Enter.

Quick Prefixes

PrefixAction
#Add to memory
/Slash command
!Bash mode
@File mention

Vim Mode

Enable with /vim command.

ModeKeyAction
INSERTEscEnter NORMAL
NORMALi/aInsert before/after cursor
NORMALh/j/k/lMove left/down/up/right
NORMALw/bNext/previous word
NORMALddDelete line
NORMAL.Repeat last change

Quick Reference

File Precedence

TypeProjectUser
Memory./CLAUDE.md, .claude/CLAUDE.md~/.claude/CLAUDE.md
Settings.claude/settings.json~/.claude/settings.json
Commands.claude/commands/~/.claude/commands/
Skills.claude/skills/~/.claude/skills/
Agents.claude/agents/~/.claude/agents/
Rules.claude/rules/~/.claude/rules/
MCP.mcp.json~/.claude.json

Project-level always takes precedence over user-level.

Common Workflows

# Initialize project
claude /init

# Check installation
claude /doctor

# Start in plan mode
claude --permission-mode plan

# Resume previous session
claude /resume

dev