Beyond the Basics: Configuring Claude Code
In Part 1, you got Claude Code running. Now it is time to configure it for real work. Claude Code has several configuration layers that control how it behaves, which tools it can access, and how it interacts with your project.
The Three Configuration Layers
Claude Code reads settings from three places, in this priority order:
- Project-level (
.claude/settings.jsonin your project) — overrides everything else - User-level (
~/.claude/settings.json) — applies to all projects for your user - Environment variables — API keys, proxy settings, feature flags
Setting Up the Claude Configuration File
Create a project-level settings file to control Claude Code's behavior for your specific project:
# Create the .claude directory in your project root
mkdir -p .claude
# Create the settings file
cat > .claude/settings.json << 'EOF'
{
"permissions": {
"allow": ["bash", "read", "edit", "glob", "grep"],
"deny": []
},
"model": {
"name": "claude-sonnet-4-20250514",
"maxTokens": 8192,
"temperature": 0.3
}
}
EOF
MCP Tools: Extending Claude Code's Capabilities
MCP (Model Context Protocol) is how Claude Code connects to external tools and data sources. It can access databases, APIs, file systems, and more through MCP servers.
To add MCP tools, edit your project's .claude/settings.json and add an mcpServers section:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "your_github_pat_here"
}
}
}
}
Popular MCP servers include:
- Filesystem: Read, write, and search files with advanced permissions
- GitHub: Manage repos, issues, PRs, and code reviews
- PostgreSQL: Query databases directly from your Claude session
- Puppeteer: Browser automation for testing and web scraping
- Slack: Send and read messages in Slack channels
API Key Management Best Practices
Never hard-code API keys in project files. Use environment variables:
Option 1: .env file (simplest for single projects)
echo 'ANTHROPIC_API_KEY=sk-ant-***' > .env
echo '.env' >> .gitignore # prevent committing secrets
Claude Code reads .env automatically if present.
Option 2: System environment variable (for global use)
# Add to ~/.zshrc or ~/.bashrc
export ANTHROPIC_API_KEY="sk-ant-***"
export ANTHROPIC_BASE_URL="https://api.anthropic.com/v1"
Controlling Claude Code with .claudeignore
Similar to .gitignore, a .claudeignore file tells Claude Code which files to skip when reading your project:
# .claudeignore
node_modules/
dist/
build/
*.min.js
*.map
package-lock.json
*.log
.env
This keeps Claude Code focused on your source code and prevents it from wasting context on generated files.
Next Steps in Configuration
Try these commands to verify your configuration:
# Show current configuration
claude config list
# Test MCP server connection
claude mcp list
# Start a session with verbose logging
claude --verbose
FAQ
Q: What is the difference between MCP and regular tools?
Regular tools (read, edit, bash, glob, grep) are built into Claude Code and available by default. MCP servers are external integrations that add capabilities like database access, API calls, or browser control. You choose which MCP servers to install based on your project needs.
Q: Can I have different settings for different projects?
Yes. Project-level settings in .claude/settings.json override user-level settings in ~/.claude/settings.json. This lets you have strict permissions for work projects and relaxed settings for personal projects.
Q: Do MCP servers have risks?
Yes. MCP servers can access any system they connect to (databases, APIs, file systems). Only install MCP servers from trusted sources. Check each server requested permissions before installing.
Frequently Asked Questions
Q: What is MCP and why do I need to configure it for Claude Code?
MCP (Model Context Protocol) lets Claude Code connect to external tools like databases, file systems, and APIs. Without MCP it only reads project files. With MCP it can query databases or create GitHub issues.
Q: Do all MCP servers need to be installed globally or per-project?
Both. Global config in claude.json applies to all projects. Per-project in .claude/settings.local.json. Per-project is recommended for sensitive tools like database access.
Q: Is it safe to give Claude Code MCP access to my production database?
Generally no. Use a read-only database user or a staging database. Create a dedicated user with SELECT-only if Claude Code only needs to read. For writes, implement human approval steps.