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

Antigravity AI Content Pipeline Automation Guide: Google Docs to WordPress Publishing Workflow Guide Bolt.new Case Study: Marketing Agency Built 5 Client Dashboards in One Day Case Study Bolt.new Best Practices: Rapid Full-Stack App Generation from Natural Language Prompts Best Practices ChatGPT Advanced Data Analysis (Code Interpreter) Complete Guide: Upload, Analyze, Visualize Guide ChatGPT Custom GPTs Advanced Guide: Actions, API Integration, and Knowledge Base Configuration Guide ChatGPT Voice Mode Guide: Build Voice-First Customer Service and Internal Workflows Guide Claude API Production Chatbot Guide: System Prompt Architecture for Reliable AI Assistants Guide Claude Artifacts Best Practices: Create Interactive Dashboards, Documents, and Code Previews Best Practices Claude Code Hooks Guide: Automate Custom Workflows with Pre and Post Execution Hooks Guide Claude MCP Server Setup Guide: Build Custom Tool Integrations for Claude Code and Claude Desktop Guide Cursor Composer Complete Guide: Multi-File Editing, Inline Diffs, and Agent Mode Guide Cursor Case Study: Solo Founder Built a Next.js SaaS MVP in 2 Weeks with AI-Assisted Development Case Study Cursor Rules Advanced Guide: Project-Specific AI Configuration and Team Coding Standards Guide Devin AI Team Workflow Integration Best Practices: Slack, GitHub, and Code Review Automation Best Practices Devin Case Study: Automated Dependency Upgrade Across 500-Package Python Monorepo Case Study ElevenLabs Case Study: EdTech Startup Localized 200 Course Hours to 8 Languages in 6 Weeks Case Study ElevenLabs Multilingual Dubbing Guide: Automated Video Localization Workflow for Global Content Guide ElevenLabs Voice Design Complete Guide: Create Consistent Character Voices for Games, Podcasts, and Apps Guide Gemini 2.5 Pro vs Claude Sonnet 4 vs GPT-4o: AI Code Generation Comparison 2026 Comparison Gemini API Multimodal Developer Guide: Image, Video, and Document Analysis with Code Examples Guide