Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows
—
Claude Code provides comprehensive configuration management through multiple configuration files, environment variables, and project-specific settings.
Claude Code uses a hierarchical configuration system with multiple file locations.
# Global configuration directory
~/.claude/
# Project configuration
.claude/
# Main configuration files
~/.claude/settings.json # Global settings (migrated from .claude.json)
.claude/settings.json # Project-level settings
CLAUDE.md # Project-specific context and instructions
.mcp.json # MCP server configuration (project scope)Configuration Priority (highest to lowest):
.claude/settings.json)CLAUDE.md)~/.claude/settings.json)Main configuration file for user-wide settings.
{
"model": "claude-3-sonnet-20240229",
"outputStyle": "explanatory",
"permissions": {
"allowedTools": [
"Bash(git *)",
"Read(*)",
"Write(*.js)",
"Write(*.ts)",
"Write(*.json)"
],
"blockedTools": [
"Bash(rm -rf *)",
"Bash(sudo *)"
]
},
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "python3 ~/.claude/hooks/bash-validator.py",
"timeout": 5000
}
]
}
],
"SessionStart": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "echo 'Session started in $CLAUDE_PROJECT_DIR'"
}
]
}
]
},
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["@modelcontextprotocol/server-filesystem", "/allowed/directory"]
}
},
"cleanupPeriodDays": 30,
"enableVimBindings": false,
"statusLine": {
"enabled": true,
"format": "claude[%project%] %status%"
}
}Project-specific configuration that overrides global settings.
{
"model": "claude-3-opus-20240229",
"permissions": {
"allowedTools": [
"Bash(npm *)",
"Bash(yarn *)",
"Bash(git *)",
"Read(*)",
"Write(src/**/*)",
"Write(tests/**/*)"
]
},
"customCommands": {
"test-and-commit": {
"command": "npm test && git add . && git commit",
"description": "Run tests and commit if passing"
}
},
"additionalDirectories": [
"../shared-components",
"../api-types"
]
}Markdown file containing project-specific context and instructions.
# Project Context
## Project Overview
This is a React TypeScript application with Express.js backend.
## Architecture
- Frontend: React + TypeScript + Vite
- Backend: Express.js + TypeScript + PostgreSQL
- Testing: Jest + React Testing Library
## Development Guidelines
- Use functional components with hooks
- Prefer TypeScript strict mode
- All API responses must be typed
- Tests are required for new features
## Common Commands
- `npm run dev` - Start development server
- `npm run test` - Run test suite
- `npm run build` - Build for production
- `npm run typecheck` - Type checking
## Important Files
- `src/types/` - TypeScript type definitions
- `src/api/` - API client code
- `src/components/` - React components
- `tests/` - Test filesConfigure Claude Code behavior through environment variables.
# Configuration
export CLAUDE_CONFIG_DIR="/custom/config/path"
export ANTHROPIC_API_KEY="your-api-key"
# Model selection
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-3-sonnet-latest"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-3-opus-latest"
# IDE integration
export CLAUDE_CODE_AUTO_CONNECT_IDE="true"
export CLAUDE_CODE_SHELL_PREFIX="time"
# Debugging and logging
export ANTHROPIC_LOG="debug"
export DISABLE_INTERLEAVED_THINKING="false"
# Performance and timeouts
export BASH_DEFAULT_TIMEOUT_MS="120000"
export BASH_MAX_TIMEOUT_MS="600000"
export MCP_TIMEOUT="30000"
export MCP_TOOL_TIMEOUT="10000"
# Network configuration
export NO_PROXY="localhost,127.0.0.1"
export AWS_BEARER_TOKEN_BEDROCK="your-bedrock-token"
# Advanced options
export CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR="true"
export USE_BUILTIN_RIPGREP="true"Key Environment Variables:
CLAUDE_CONFIG_DIR: Override configuration directory (supports XDG_CONFIG_HOME)ANTHROPIC_API_KEY: Direct API key authenticationANTHROPIC_DEFAULT_SONNET_MODEL: Control Sonnet model aliasANTHROPIC_DEFAULT_OPUS_MODEL: Control Opus model aliasCLAUDE_CODE_AUTO_CONNECT_IDE: Enable/disable IDE auto-connectionCLAUDE_CODE_SHELL_PREFIX: Wrap shell commands with prefixCLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR: Freeze working directoryUSE_BUILTIN_RIPGREP: Control built-in ripgrep usageNO_PROXY: Proxy bypass configurationAWS_BEARER_TOKEN_BEDROCK: Bedrock API authenticationDISABLE_INTERLEAVED_THINKING: Disable thinking modeANTHROPIC_LOG: Debug logging level (debug, info, warn, error)BASH_DEFAULT_TIMEOUT_MS / BASH_MAX_TIMEOUT_MS: Bash command timeoutsMCP_TIMEOUT / MCP_TOOL_TIMEOUT: MCP server and tool timeoutsDetailed hook system configuration for custom behaviors.
{
"hooks": {
"SessionStart": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "git status",
"timeout": 5000
}
]
}
],
"SessionEnd": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "echo 'Session ended at $(date)' >> ~/.claude/session.log"
}
]
}
],
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "python3 ~/.claude/hooks/bash-security-check.py",
"timeout": 3000
}
]
},
{
"matcher": "Write",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/file-backup.sh",
"timeout": 2000
}
]
}
],
"UserPromptSubmit": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "echo 'User prompt: $CLAUDE_USER_PROMPT' >> ~/.claude/prompts.log"
}
]
}
],
"PreCompact": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/backup-conversation.sh"
}
]
}
],
"Stop": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "echo 'Task completed successfully' | notify-send 'Claude Code'"
}
]
}
],
"SubagentStop": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "echo 'Subagent task completed'"
}
]
}
]
}
}Hook Types:
SessionStart: Executed when a new session beginsSessionEnd: Executed when session terminatesPreToolUse: Executed before any tool usageUserPromptSubmit: Executed when user submits inputPreCompact: Executed before conversation compactionStop: Executed when main task completesSubagentStop: Executed when subagent task completesConfigure Model Context Protocol servers for extended capabilities.
{
"servers": {
"filesystem": {
"command": "npx",
"args": [
"@modelcontextprotocol/server-filesystem",
"/path/to/allowed-directory"
],
"env": {
"NODE_ENV": "production"
}
},
"git": {
"command": "mcp-server-git",
"args": [
"--repository",
".",
"--branch",
"main"
]
},
"database": {
"command": "python3",
"args": [
"/path/to/mcp-database-server.py",
"--connection-string",
"postgresql://localhost/mydb"
],
"env": {
"DB_PASSWORD": "${DB_PASSWORD}"
}
},
"web-search": {
"command": "node",
"args": [
"/path/to/web-search-server.js"
],
"env": {
"SEARCH_API_KEY": "${SEARCH_API_KEY}"
}
}
}
}MCP Server Features:
Fine-grained control over tool permissions and security.
{
"permissions": {
"allowedTools": [
"Bash(git add *)",
"Bash(git commit *)",
"Bash(git push *)",
"Bash(git status *)",
"Bash(npm install *)",
"Bash(npm run *)",
"Read(*)",
"Write(src/**/*.ts)",
"Write(src/**/*.tsx)",
"Write(tests/**/*)",
"Write(docs/**/*.md)"
],
"blockedTools": [
"Bash(rm -rf *)",
"Bash(sudo *)",
"Bash(chmod 777 *)",
"Write(/etc/*)",
"Write(/usr/*)",
"Write(/bin/*)"
],
"requireConfirmation": [
"Bash(git reset --hard *)",
"Bash(git push --force *)",
"Write(package.json)",
"Write(tsconfig.json)"
]
}
}Permission Patterns:
Tool(pattern): Allow tool with specific patternTool(*): Allow tool with any arguments*: Wildcard matching for any toolCustomize how Claude presents information and responses.
{
"outputStyle": "explanatory",
"customOutputStyles": {
"learning": {
"description": "Educational style with detailed explanations",
"systemPrompt": "Explain concepts thoroughly with examples and context."
},
"concise": {
"description": "Brief, direct responses",
"systemPrompt": "Be concise and direct. Minimize explanations."
},
"expert": {
"description": "Advanced technical responses",
"systemPrompt": "Assume expert-level knowledge. Use technical terminology."
}
}
}Built-in Output Styles:
explanatory: Default style with explanationslearning: Educational style for learningconcise: Brief, direct responsesManage configuration through CLI commands.
# Edit global configuration
claude /config --edit
# Validate configuration
claude /doctor
# Reset to defaults
claude /config --reset
# Backup configuration
claude /config --backup
# Show current configuration
claude /config --show
# Import configuration
claude /config --import config-backup.json
# Export configuration
claude /config --export my-config.jsonHandle upgrades and configuration migration.
{
"version": "2.0",
"migrationNotes": {
"1.x-to-2.x": "Settings moved from .claude.json to ~/.claude/settings.json"
}
}Migration Features:
Validate configuration files for correctness.
# Validate all configuration
claude /doctor
# Validate specific config file
claude --validate-config ~/.claude/settings.json
# Check hook scripts
claude /doctor --check-hooks
# Verify MCP servers
claude /doctor --check-mcpValidation Checks:
Install with Tessl CLI
npx tessl i tessl/npm-anthropic-ai--claude-code