Claude Code Initial Setup Complete Guide: Installation, CLAUDE.md, MCP Servers & Custom Slash Commands

Claude Code Initial Setup Complete Guide

Claude Code is Anthropic’s agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster through natural language. This guide walks you through every step—from installation to advanced configuration—so you can unlock its full potential from day one.

Step 1: Install Claude Code

Claude Code requires Node.js 18+ and runs on macOS, Linux, and Windows (via WSL or native). Install it globally using npm: # Install Claude Code globally npm install -g @anthropic-ai/claude-code

Verify installation

claude —version

Launch Claude Code in your project directory

cd /path/to/your/project claude

On first launch, Claude Code will guide you through authentication. You can authenticate via your Anthropic Console account or by setting an API key: # Option A: Interactive login (opens browser) claude login

Option B: Set API key directly

export ANTHROPIC_API_KEY=YOUR_API_KEY

Option C: Use a configuration file

claude config set apiKey YOUR_API_KEY

Step 2: Create and Configure CLAUDE.md

The CLAUDE.md file is the single most important configuration file for Claude Code. It acts as persistent instructions that Claude reads at the start of every conversation. You can place it at multiple levels: - **Project root** — ./CLAUDE.md (checked into version control, shared with team)- **User-level** — ~/.claude/CLAUDE.md (private, applies to all projects)- **Nested directories** — ./src/CLAUDE.md (loaded when working in that subtree)Here is a practical CLAUDE.md template: # Project Instructions for Claude Code

Project Overview

  • Stack: Next.js 14 + TypeScript + Tailwind CSS + Prisma
  • Node version: 20.x
  • Package manager: pnpm

Code Conventions

  • Use functional components with TypeScript interfaces
  • Prefer named exports over default exports
  • Use server components by default; add “use client” only when needed
  • Test files live alongside source: Component.test.tsx

Commands

  • Build: pnpm build
  • Test: pnpm test
  • Lint: pnpm lint —fix
  • Dev: pnpm dev

Important Rules

  • NEVER modify migration files directly
  • Always run “pnpm test” after making changes
  • Use environment variables from .env.local, never hardcode secrets

Tips for Effective CLAUDE.md Files

  • Keep instructions actionable and specific—avoid vague guidance- Include the commands Claude should run for building, testing, and linting- Document project-specific conventions that differ from common defaults- Update it as your project evolves; treat it like living documentation

Step 3: Connect MCP Servers

Model Context Protocol (MCP) servers extend Claude Code with external tool integrations—databases, APIs, design tools, and more. Configure them in .mcp.json at your project root or in ~/.claude/settings.json globally. // .mcp.json (project-level MCP configuration) { "mcpServers": { "context7": { "command": "npx", "args": ["-y", "@upstash/context7-mcp"] }, "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"] }, "postgres": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres"], "env": { "DATABASE_URL": "postgresql://user:password@localhost:5432/mydb" } } } }

You can also add MCP servers interactively: # Add an MCP server via CLI claude mcp add context7 -- npx -y @upstash/context7-mcp

List configured MCP servers

claude mcp list

Remove an MCP server

claude mcp remove context7

Step 4: Set Up Custom Slash Commands

Custom slash commands let you create reusable prompt templates. Store them as Markdown files in .claude/commands/ at the project level or ~/.claude/commands/ for global access. # Create the commands directory mkdir -p .claude/commands

Create a code review command

cat > .claude/commands/review.md << ‘EOF’ Review the current git diff for:

  1. Security vulnerabilities (injection, XSS, secrets)
  2. Performance issues (N+1 queries, memory leaks)
  3. Logic errors and edge cases
  4. Adherence to project conventions in CLAUDE.md

Provide a summary with severity ratings: critical, warning, info. EOF

Create a test generation command

cat > .claude/commands/gen-tests.md << ‘EOF’ Generate comprehensive tests for $ARGUMENTS:

  • Unit tests for pure functions
  • Integration tests for API endpoints
  • Edge cases and error scenarios
  • Use the testing conventions from CLAUDE.md EOF

    Use them in Claude Code by typing /review or /gen-tests src/utils/auth.ts. The $ARGUMENTS placeholder captures any text you type after the command name.

Step 5: Configure Permissions and Settings

Fine-tune Claude Code’s behavior through settings: # Set permission mode (default: normal) claude config set permissions.mode auto-accept # Trust all tools claude config set permissions.mode normal # Ask before risky actions

Configure preferred model

claude config set model claude-opus-4-6

Set default context

claude config set maxContext 200000

View all current settings

claude config list

Pro Tips for Power Users

TipDetails
Use /compact regularlyCompresses conversation context when working on long tasks, preserving key information while freeing token space
Pipe input to Claudegit diff | claude "Review this diff for bugs" sends the diff as context for a one-shot response
Multi-turn with --continueclaude --continue resumes the most recent conversation from where you left off
Headless mode for CIclaude --print "Generate changelog from recent commits" outputs the response and exits—perfect for pipelines
Memory systemTell Claude to "remember" preferences; it stores them in ~/.claude/projects//memory/ for future sessions
Parallel tool callsClaude Code can read multiple files and run independent operations simultaneously for faster execution
## Troubleshooting Common Errors
ErrorCauseSolution
ANTHROPIC_API_KEY not setMissing or invalid API keyRun claude login or export ANTHROPIC_API_KEY=YOUR_API_KEY
MCP server failed to startServer binary not found or missing depsRun the MCP server command manually to check for errors; ensure npx has network access
CLAUDE.md not loadedFile is outside the project root or misspelledVerify filename is exactly CLAUDE.md (case-sensitive) and is in the working directory
Permission denied on tool executionPermission mode is restrictiveApprove the action when prompted, or set permissions.mode to auto-accept for trusted projects
Slow startupToo many MCP servers or large CLAUDE.mdRemove unused MCP servers; keep CLAUDE.md concise and under 2000 words
## Frequently Asked Questions

Can I use Claude Code with an existing project that already has other AI tool configurations?

Yes. Claude Code's configuration files (CLAUDE.md, .mcp.json, .claude/commands/) are independent and will not conflict with configurations for tools like GitHub Copilot, Cursor, or Cody. You can run Claude Code alongside any other AI-assisted development tool. Simply add its config files to your project and optionally add .claude/ to your .gitignore if you prefer to keep personal settings private.

How do I share CLAUDE.md and custom commands with my team?

Commit the project-level CLAUDE.md and .claude/commands/ directory to your repository. These files serve as shared team conventions that Claude Code will follow for every team member. For personal preferences—like your own slash commands or user-specific instructions—use the global /.claude/CLAUDE.md and /.claude/commands/ directory, which are not checked into version control.

Do MCP servers consume API tokens or add to the cost?

MCP server tool definitions and their results are included in the context sent to the model, so they do contribute to token usage. However, tools are only invoked when relevant to your task. To minimize cost, remove MCP servers you are not actively using from your .mcp.json configuration, and prefer project-level configuration over global so servers only load when needed.

Explore More Tools

Grok Best Practices for Academic Research and Literature Discovery: Leveraging X/Twitter for Scholarly Intelligence Best Practices Grok Best Practices for Content Strategy: Identify Trending Topics Before They Peak and Create Content That Captures Demand Best Practices Grok Case Study: How a DTC Beauty Brand Used Real-Time Social Listening to Save Their Product Launch Case Study Grok Case Study: How a Pharma Company Tracked Patient Sentiment During a Drug Launch and Caught a Safety Signal 48 Hours Before the FDA Case Study Grok Case Study: How a Disaster Relief Nonprofit Used Real-Time X/Twitter Monitoring to Coordinate Emergency Response 3x Faster Case Study Grok Case Study: How a Political Campaign Used X/Twitter Sentiment Analysis to Reshape Messaging and Win a Swing District Case Study How to Use Grok for Competitive Intelligence: Track Product Launches, Pricing Changes, and Market Positioning in Real Time How-To Grok vs Perplexity vs ChatGPT Search for Real-Time Information: Which AI Search Tool Is Most Accurate in 2026? Comparison How to Use Grok for Crisis Communication Monitoring: Detect, Assess, and Respond to PR Emergencies in Real Time How-To How to Use Grok for Product Improvement: Extract Customer Feedback Signals from X/Twitter That Your Support Team Misses How-To How to Use Grok for Conference Live Monitoring: Extract Event Insights and Identify Networking Opportunities in Real Time How-To How to Use Grok for Influencer Marketing: Discover, Vet, and Track Influencer Partnerships Using Real X/Twitter Data How-To How to Use Grok for Job Market Analysis: Track Industry Hiring Trends, Layoff Signals, and Salary Discussions on X/Twitter How-To How to Use Grok for Investor Relations: Track Earnings Sentiment, Analyst Reactions, and Shareholder Concerns in Real Time How-To How to Use Grok for Recruitment and Talent Intelligence: Identifying Hiring Signals from X/Twitter Data How-To How to Use Grok for Startup Fundraising Intelligence: Track Investor Sentiment, VC Activity, and Funding Trends on X/Twitter How-To How to Use Grok for Regulatory Compliance Monitoring: Real-Time Policy Tracking Across Industries How-To NotebookLM Best Practices for Financial Analysts: Due Diligence, Investment Research & Risk Factor Analysis Across SEC Filings Best Practices NotebookLM Best Practices for Teachers: Build Curriculum-Aligned Lesson Plans, Study Guides, and Assessment Materials from Your Own Resources Best Practices NotebookLM Case Study: How an Insurance Company Built a Claims Processing Training System That Cut Errors by 35% Case Study