Configuration Reference
Tags: claude-code configuration settings hooks reference
This guide consolidates all configuration options for Claude Code, including settings, hooks, and environment configuration.
Table of Contents
- Configuration Files
- Settings Structure
- Hooks Configuration
- Environment Variables
- MCP Configuration
- TypeScript Configuration
- Project Setup
Configuration Files
File Locations and Priority
Claude Code uses a hierarchical configuration system:
- User-level:
~/.claude/settings.json- Global settings - Project-level:
.claude/settings.json- Shared project settings - Local overrides:
.claude/settings.local.json- Local, untracked settings
Settings are merged with local overrides taking precedence over project settings, which take precedence over user settings.
Authentication Configuration
Method 1: Environment Variable (Recommended)
export ANTHROPIC_API_KEY="your-api-key-here"Method 2: Configuration File
~/.config/claude/settings.json:
{
"api_key": "your-api-key-here"
}Settings Structure
Complete Settings Template
{
"api_key": "your-api-key-here",
"model": "claude-sonnet-4-20250514",
"permission_mode": "cautious",
"max_turns": 3,
"working_directory": "/path/to/project",
"system_prompt": "You are a helpful assistant",
"hooks": {
// Hook configurations (see Hooks Configuration section)
},
"mcp_servers": {
// MCP server configurations (see MCP Configuration section)
}
}Core Settings
| Setting | Type | Default | Description |
|---|---|---|---|
api_key | string | - | Your Anthropic API key |
model | string | claude-sonnet-4-20250514 | Model to use |
permission_mode | string | cautious | File operation permission mode |
max_turns | number | 3 | Maximum conversation turns |
working_directory | string | Current directory | Default working directory |
system_prompt | string | - | Custom system prompt |
Permission Modes
- strict: Requires explicit confirmation for all file operations
- cautious: Asks for confirmation on potentially destructive operations (default)
- relaxed: Minimal confirmations, suitable for trusted environments
Available Models
claude-sonnet-4-20250514- Default balanced modelclaude-haiku-4-20250514- Faster, lightweight modelclaude-opus-4-20250514- Most capable model
Hooks Configuration
Hook Events Overview
| Event | When It Fires | Can Block? | Common Use Cases |
|---|---|---|---|
| PreToolUse | Before tool execution | ✅ Yes (exit 2) | Validation, security checks |
| PostToolUse | After tool success | ❌ No | Formatting, logging, notifications |
| UserPromptSubmit | User submits prompt | ✅ Yes | Input validation, preprocessing |
| Notification | Claude sends notification | ❌ No | Custom alerts, logging |
| Stop | Main agent finishes | ❌ No | Cleanup, commits, summaries |
| SubagentStop | Subagent completes | ❌ No | Task tracking, logging |
| PreCompact | Before context compaction | ❌ No | Context management |
Hook Configuration Structure
{
"hooks": {
"EVENT_NAME": [
{
"matcher": "TOOL_PATTERN",
"hooks": [
{
"type": "command",
"command": "YOUR_COMMAND",
"timeout": 30000
}
]
}
]
}
}Hook Matcher Patterns
| Pattern | Matches | Example |
|---|---|---|
.* | All tools | Universal hooks |
Edit|Write | Multiple tools | File modifications |
^Bash$ | Exact match | Only Bash tool |
mcp__.* | MCP tools | All MCP integrations |
Complete Hooks Example
{
"hooks": {
"PreToolUse": [
{
"matcher": "Write|Edit|MultiEdit",
"hooks": [
{
"type": "command",
"command": "/path/to/validation-script.sh",
"timeout": 30000
}
]
}
],
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "prettier --write $CLAUDE_FILE_PATHS",
"timeout": 10000
}
]
}
],
"Stop": [
{
"matcher": ".*",
"hooks": [
{
"type": "command",
"command": "notify-send 'Claude Code' 'Task completed'",
"timeout": 5000
}
]
}
]
}
}Hook Environment Variables
Variables available to hook scripts:
$CLAUDE_TOOL_NAME- Name of the tool being executed$CLAUDE_TOOL_INPUT- Input parameters passed to the tool$CLAUDE_TOOL_OUTPUT- Tool’s output (PostToolUse only)$CLAUDE_FILE_PATHS- Space-separated list of relevant file paths$CLAUDE_NOTIFICATION- Notification message content
Hook Input Structure
Hooks receive JSON input via stdin:
{
"session_id": "unique-session-id",
"transcript_path": "/path/to/conversation.json",
"cwd": "/current/working/directory",
"hook_event_name": "PreToolUse",
"tool_name": "Edit",
"tool_input": {
"file_path": "/path/to/file",
"old_string": "original",
"new_string": "modified"
}
}Hook Exit Codes
| Code | Effect | Use Case |
|---|---|---|
| 0 | Continue normally | Success |
| 2 | Block operation | Validation failure (PreToolUse only) |
| Other | Warning, continue | Non-critical errors |
Environment Variables
Claude Code Environment Variables
| Variable | Description | Example |
|---|---|---|
ANTHROPIC_API_KEY | API authentication key | sk-ant-... |
CLAUDE_MODEL | Override default model | claude-opus-4-20250514 |
CLAUDE_PERMISSION_MODE | Override permission mode | relaxed |
CLAUDE_WORKING_DIR | Override working directory | /home/user/project |
CLAUDE_MAX_TURNS | Override max turns | 5 |
CLAUDE_DEBUG | Enable debug logging | true |
Development Environment
.env file example:
ANTHROPIC_API_KEY=your-api-key
NODE_ENV=development
CLAUDE_DEBUG=true
CLAUDE_MODEL=claude-haiku-4-20250514MCP Configuration
Claude Desktop Configuration
Location: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
{
"mcpServers": {
"my-tools": {
"command": "node",
"args": ["/path/to/your/mcp-server.js"],
"env": {
"DATABASE_URL": "postgresql://localhost/mydb",
"API_KEY": "your-api-key"
}
},
"file-tools": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/me/projects"]
},
"github-tools": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_..."
}
}
}
}MCP Server Configuration Options
| Field | Type | Description |
|---|---|---|
command | string | Command to start the server |
args | string[] | Command arguments |
env | object | Environment variables for the server |
cwd | string | Working directory (optional) |
TypeScript Configuration
Recommended tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"lib": ["ES2022"],
"types": ["node"],
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}Package.json Configuration
{
"name": "claude-code-app",
"version": "1.0.0",
"type": "module",
"main": "dist/index.js",
"scripts": {
"dev": "tsx src/index.ts",
"build": "tsc",
"start": "node dist/index.js",
"test": "vitest",
"lint": "eslint src --ext .ts",
"format": "prettier --write src/**/*.ts"
},
"dependencies": {
"@anthropic-ai/claude-code": "^1.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.0.0",
"prettier": "^3.0.0",
"tsx": "^4.0.0",
"typescript": "^5.0.0",
"vitest": "^1.0.0"
}
}Project Setup
Directory Structure
project/
├── .claude/
│ ├── settings.json # Shared project settings
│ └── settings.local.json # Local overrides (gitignored)
├── .env # Environment variables
├── .env.example # Example environment file
├── .gitignore # Include .claude/settings.local.json
├── src/
│ └── index.ts # Main application
├── hooks/
│ ├── pre-tool-use.sh # Pre-tool validation
│ └── post-tool-use.sh # Post-tool formatting
├── mcp-servers/
│ └── custom-tools.js # Custom MCP server
├── package.json
└── tsconfig.json
.gitignore Configuration
# Claude Code
.claude/settings.local.json
.claude/logs/
.claude/cache/
# Environment
.env
.env.local
# Dependencies
node_modules/
# Build outputs
dist/
build/
# IDE
.vscode/
.idea/
# OS
.DS_Store
Thumbs.dbExample Project Settings
.claude/settings.json:
{
"working_directory": ".",
"permission_mode": "cautious",
"hooks": {
"PreToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "./hooks/pre-tool-use.sh",
"timeout": 10000
}
]
}
],
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "./hooks/post-tool-use.sh",
"timeout": 15000
}
]
}
]
}
}Common Configuration Patterns
Development Configuration
{
"model": "claude-haiku-4-20250514",
"permission_mode": "relaxed",
"max_turns": 10,
"system_prompt": "You are helping with development. Be concise.",
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "npm run lint:fix",
"timeout": 20000
}
]
}
]
}
}Production Configuration
{
"model": "claude-sonnet-4-20250514",
"permission_mode": "strict",
"max_turns": 3,
"hooks": {
"PreToolUse": [
{
"matcher": ".*",
"hooks": [
{
"type": "command",
"command": "./security-check.sh",
"timeout": 30000
}
]
}
],
"Stop": [
{
"matcher": ".*",
"hooks": [
{
"type": "command",
"command": "./audit-log.sh",
"timeout": 10000
}
]
}
]
}
}Testing Configuration
{
"model": "claude-haiku-4-20250514",
"permission_mode": "cautious",
"working_directory": "./test-workspace",
"system_prompt": "You are writing and running tests. Focus on test coverage.",
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "npm test -- --related $CLAUDE_FILE_PATHS",
"timeout": 60000
}
]
}
]
}
}Debugging Configuration
Enable Debug Mode
export CLAUDE_DEBUG=trueCheck Current Configuration
# View merged configuration
cat ~/.claude/settings.json
# Test hook execution
echo '{"tool_name": "Edit"}' | /path/to/your/hook.sh
# Validate JSON syntax
jq '.' ~/.claude/settings.jsonCommon Issues
- Hooks not firing: Check matcher patterns and file permissions
- Settings not applying: Verify file locations and JSON syntax
- Authentication failing: Check API key in environment or config
- MCP tools not available: Restart Claude Desktop after config changes