Claude Code Settings & Configuration
Claude Code has three layers of configuration that stack on top of each other: environment variables (highest priority), settings.json files (project and global), and CLAUDE.md files (instruction context). This page covers all of them.
Configuration Priority Order
| Layer | File / mechanism | Scope | Priority |
|---|---|---|---|
| CLI flags | --model, --print, etc. | Single run | Highest |
| Environment variables | ANTHROPIC_MODEL, ANTHROPIC_API_KEY, etc. | Shell session | 2nd |
| Project local settings | .claude/settings.local.json | One developer in one project | 3rd |
| Project settings | .claude/settings.json | All team members in one project | 4th |
| Global settings | ~/.claude/settings.json | All projects on this machine | Lowest |
settings.json Full Reference
// .claude/settings.json — annotated example
{
// Model to use (overridable per-session with --model)
"model": "claude-sonnet-4-6",
// Pre-approve specific tools to reduce confirmation prompts
"permissions": {
"allow": [
"Read", // Read files
"Bash(git *)", // Any git command
"Bash(npm *)", // Any npm command
"Bash(python *)" // Any python command
],
"deny": [
"Bash(rm -rf *)" // Never allow recursive delete
]
},
// Environment variables injected into every Bash command
"env": {
"NODE_ENV": "development",
"LOG_LEVEL": "debug"
},
// Hooks — shell commands that fire at lifecycle events
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [{"type": "command", "command": "echo 'Running: $CLAUDE_TOOL_INPUT'"}]
}
],
"Stop": [
{
"hooks": [{"type": "command", "command": "notify-send 'Claude Code done'"}]
}
]
},
// Disable specific features
"theme": "dark",
"autoUpdates": false,
"verbose": false
}
File Locations
# Global settings — applies to all projects
~/.claude/settings.json
# Project settings — committed to git (team-shared)
.claude/settings.json
# Project local settings — NOT committed (add to .gitignore)
.claude/settings.local.json
# CLAUDE.md — instructions for Claude (not config)
CLAUDE.md # project root (loaded always)
src/CLAUDE.md # subdirectory (loaded when working in src/)
~/.claude/CLAUDE.md # global (loaded in every project)
.claude/settings.local.json to your .gitignore. This file is for personal overrides (your preferred model, local API keys) that shouldn't be shared with the team.Model Configuration
# In settings.json
{"model": "claude-opus-4-7"}
# Via environment variable
export ANTHROPIC_MODEL=claude-haiku-4-5-20251001
# Per-session override
claude --model claude-sonnet-4-6
| Model ID | Best for | Relative cost |
|---|---|---|
| claude-haiku-4-5-20251001 | Bulk tasks, fast summaries, formatting | 1× |
| claude-sonnet-4-6 | Most tasks — best value/quality balance | ~5× |
| claude-opus-4-7 | Complex reasoning, large refactors, architecture | ~15× |
Permissions Configuration
Reduce confirmation prompts by pre-approving tools in settings.json. Use specific patterns to grant narrow permissions rather than broad ones:
{
"permissions": {
"allow": [
"Read", // allow all file reads
"Write", // allow all file writes
"Edit", // allow all edits
"Bash(git *)", // allow any git command
"Bash(npm test)", // allow only 'npm test'
"Bash(npm run *)" // allow any 'npm run ...' command
],
"deny": [
"Bash(rm -rf *)", // never allow recursive delete
"Bash(git push *)" // require manual push confirmation
]
}
}
Environment Variables Reference
| Variable | Purpose | Example value |
|---|---|---|
| ANTHROPIC_API_KEY | Required. Your Anthropic API key. | sk-ant-... |
| ANTHROPIC_MODEL | Default model for all sessions | claude-sonnet-4-6 |
| ANTHROPIC_BASE_URL | Custom API endpoint (proxy, AWS Bedrock) | https://... |
| CLAUDE_AUTO_ACCEPT_EDITS | Skip edit confirmation (automation) | 1 |
| NO_COLOR | Disable ANSI color in output | 1 |
| CLAUDE_CODE_MAX_OUTPUT_TOKENS | Override max output tokens | 4096 |
Hooks Configuration
Hooks run shell commands at lifecycle events. The available events are:
| Event | When it fires |
|---|---|
| PreToolUse | Before Claude calls any tool (Bash, Read, Write, etc.) |
| PostToolUse | After a tool completes |
| PreCompact | Before context compaction runs |
| PostCompact | After context compaction |
| Stop | When Claude finishes responding |
| SubagentStop | When a spawned subagent completes |
{
"hooks": {
// Log every bash command to a file
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "echo \"$(date -u) $CLAUDE_TOOL_INPUT\" >> ~/.claude-audit.log"
}]
}],
// Desktop notification when Claude stops
"Stop": [{
"hooks": [{
"type": "command",
"command": "osascript -e 'display notification \"Done\" with title \"Claude Code\"' 2>/dev/null || true"
}]
}]
}
}
CLAUDE.md vs settings.json
Use CLAUDE.md for…
Instructions to Claude: "always use TypeScript strict mode", "this repo uses Tailwind, not Bootstrap", "never modify the src/vendor/ directory", "the test command is 'pnpm test:unit'". CLAUDE.md shapes Claude's behavior within your project.
Use settings.json for…
Runtime configuration: which model to use, which tools are pre-approved, environment variables to inject, hooks to run. settings.json shapes how Claude Code operates (the process) rather than what Claude does (the behavior).
Frequently Asked Questions
Where is Claude Code's settings.json?
Global: ~/.claude/settings.json. Project-shared: .claude/settings.json in your project root. Personal overrides: .claude/settings.local.json (gitignored).
How do I change the model in Claude Code?
Three ways: set "model": "claude-haiku-4-5-20251001" in settings.json; export ANTHROPIC_MODEL=claude-haiku-4-5-20251001; or use claude --model claude-haiku-4-5-20251001 for one session.
How do I stop permission prompts?
Add tools to permissions.allow in settings.json. Use specific patterns like "Bash(git *)" for narrow grants or "Bash" for all bash commands. Keep denies explicit for destructive operations.
What's the difference between CLAUDE.md and settings.json?
CLAUDE.md = instructions for Claude (what to do, how to behave). settings.json = configuration for the Claude Code process (model, allowed tools, env vars, hooks). They serve different purposes and both matter.
How do I add environment variables?
In settings.json under "env": {"VAR": "value"}. These are injected into every Bash command. For secrets, use settings.local.json (gitignored) or system env vars instead of committed settings.json.
How do I configure hooks?
In settings.json under "hooks". Choose an event (PreToolUse, PostToolUse, Stop, etc.), optionally add a matcher for specific tool names, and specify a shell command to run. See our full hooks guide.
→ CLAUDE.md Guide — write effective project instructions