Skip to content

Initialize Your First Project

Master the art of project initialization with Claude Code. This guide covers creating effective CLAUDE.md files, managing project memory, configuring MCP servers, and establishing clear context for AI-assisted development.

What Makes Claude Code Different

Unlike traditional coding tools, Claude Code maintains persistent memory across sessions through CLAUDE.md files. Think of these as your project’s DNA - they tell Claude everything it needs to know about your codebase, standards, and workflows.

Key benefits:

  • Zero repetition - Document once, use forever
  • Team consistency - Share knowledge across developers
  • Context awareness - Claude understands your project deeply
  • Evolving memory - Update as your project grows

Claude Code uses a sophisticated memory hierarchy that loads context based on your working directory:

Location: ./CLAUDE.md

Your team’s shared knowledge base. Check this into Git to ensure everyone works with the same context.

# Project: E-commerce Platform
## Architecture
- Next.js 15 with App Router
- Turso database with Drizzle ORM
- Stripe for payments
- Clerk for authentication
## Key Commands
- `pnpm dev` - Start development server
- `pnpm test` - Run test suite
- `pnpm db:push` - Push schema changes
## Coding Standards
- Use TypeScript strict mode
- Prefer named exports
- Follow React Server Components patterns
- IMPORTANT: Never import client code in server components
  1. Claude starts in your current working directory
  2. Recursively searches up to (but not including) root /
  3. Loads all CLAUDE.md and CLAUDE.local.md files found
  4. Discovers nested CLAUDE.md files in subdirectories on demand
  5. Merges all memories with proper precedence (local → project → user)

The fastest way to bootstrap your project context:

Terminal window
claude
> /init

This command analyzes your project and generates a comprehensive CLAUDE.md file. Here’s what it typically includes:

Generated CLAUDE.md
# Project Overview
Automatically detected project type and structure
## Technology Stack
- Language: TypeScript
- Framework: Next.js 15.0.3
- Database: PostgreSQL with Prisma
- Testing: Jest + React Testing Library
## Project Structure
- `/src` - Application source code
- `/src/components` - React components
- `/src/app` - Next.js app router pages
- `/src/lib` - Utility functions and shared code
- `/tests` - Test files
## Available Scripts
- `npm run dev` - Start development server on port 3000
- `npm run build` - Build for production
- `npm run test` - Run test suite
- `npm run lint` - Run ESLint
## Environment Variables
Required variables detected in .env.example:
- DATABASE_URL - PostgreSQL connection string
- NEXT_PUBLIC_API_URL - API endpoint
## Dependencies
Key packages:
- next: 15.0.3
- react: 19.0.0
- @prisma/client: 5.22.0
- tailwindcss: 3.4.1
## Git Workflow
- Main branch: main
- Feature branches: feature/*
- Commit style: Conventional Commits
## Additional Notes
- Using TypeScript strict mode
- Tailwind CSS for styling
- Server Components by default

After running /init, refine the generated file:

  1. Add team conventions not detected automatically
  2. Document architectural decisions and their rationale
  3. Include common gotchas specific to your project
  4. Add frequently used commands with explanations
  5. Specify coding patterns you want Claude to follow

The quickest way to add memory during development:

Terminal window
# Always use Radix UI for dropdowns, not native select elements

Claude will prompt you to choose where to save this memory:

Memory Location Prompt
Where should this memory be saved?
> 1. Project memory (./CLAUDE.md)
2. Frontend module (./frontend/CLAUDE.md)
3. User memory (~/.claude/CLAUDE.md)
4. Local project memory (./CLAUDE.local.md)

For complex projects, use imports to keep memories modular:

CLAUDE.md with imports
# Main Project Configuration
See @README.md for project overview
Review @docs/ARCHITECTURE.md for system design
## Module-Specific Guidelines
- Frontend: @frontend/STYLE_GUIDE.md
- Backend: @backend/API_CONVENTIONS.md
- Database: @docs/database/SCHEMA_DESIGN.md
## Personal Overrides
- @~/.claude/my-project-preferences.md

Imports support:

  • Relative paths: @./docs/guide.md
  • Absolute paths: @/home/user/standards.md
  • Home directory: @~/documents/notes.md
  • Recursive imports (max depth: 5)

Essential Settings (.claude/settings.json)

Section titled “Essential Settings (.claude/settings.json)”

Configure Claude’s behavior for your project:

.claude/settings.json
{
"model": "claude-opus-4",
"maxTurns": 30,
"allowedTools": [
"Edit",
"View",
"Bash(git:*)",
"Bash(npm:*)",
"Bash(pnpm:*)",
"WebFetch",
"mcp__*"
],
"hooks": [
{
"matcher": "Edit",
"hooks": [
{
"type": "command",
"command": "pnpm prettier --write \"$CLAUDE_FILE_PATHS\""
}
]
}
],
"ignoredFiles": [
"*.env*",
"*.key",
"*.pem",
"node_modules/**",
".next/**",
"dist/**"
]
}

Set up Model Context Protocol servers for enhanced capabilities:

Create .mcp.json in your project root (shareable via Git):

{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "./"]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
}
},
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"CONNECTION_STRING": "${DATABASE_URL}"
}
}
}
}

For monorepos or multi-service architectures:

  1. Start Claude in the root directory

    Terminal window
    cd ~/projects/my-monorepo
    claude
  2. Add additional directories

    Terminal window
    > /add-dir ../shared-lib
    > /add-dir ../design-system
  3. Or use CLI flags

    Terminal window
    claude --add-dir ../backend ../frontend ../shared
  4. Make it permanent

    Terminal window
    claude config add addDirs "../backend,../frontend"

Monorepo Organization

project-root/
├── CLAUDE.md # Overall project context
├── .mcp.json # Shared MCP servers
├── frontend/
│ ├── CLAUDE.md # Frontend-specific rules
│ └── src/
├── backend/
│ ├── CLAUDE.md # Backend patterns
│ └── src/
└── shared/
├── CLAUDE.md # Shared library context
└── src/

Run Claude from project-root/ with all subdirectories accessible.

Store reusable workflows as slash commands:

.claude/commands/new-feature.md
# Create a new feature following our architecture
Please create a new feature called: $ARGUMENTS
Follow these steps:
1. Create feature folder in src/features/$ARGUMENTS
2. Set up the standard structure:
- index.ts (public exports)
- types.ts (TypeScript interfaces)
- $ARGUMENTS.tsx (main component)
- $ARGUMENTS.test.tsx (tests)
- $ARGUMENTS.stories.tsx (Storybook)
3. Add feature to the main exports
4. Create initial tests with 100% coverage
5. Add to feature flags configuration
Use our standard patterns:
- Container/Presenter pattern
- Custom hooks for logic
- Styled components for styling
- React Query for data fetching

Usage: /project:new-feature user-profile

.claude/commands/
├── new-feature.md # /project:new-feature
├── api/
│ └── endpoint.md # /project:api:endpoint
├── db/
│ ├── migration.md # /project:db:migration
│ └── seed.md # /project:db:seed
└── test/
└── e2e.md # /project:test:e2e

Here’s how a senior developer sets up a new Next.js project:

  1. Initialize the project

    Terminal window
    cd ~/projects/saas-app
    claude
    > /init
  2. Refine the generated CLAUDE.md

    Terminal window
    > Edit CLAUDE.md and add our team's specific conventions
  3. Configure MCP servers

    Terminal window
    > /mcp add github --transport sse https://github.com/api/mcp
    > /mcp add postgres --transport stdio npx @modelcontextprotocol/server-postgres
  4. Set up project configuration

    Terminal window
    > Create .claude/settings.json with our preferred tools and hooks
  5. Add custom commands

    Terminal window
    > Create .claude/commands/new-component.md for our component generator
    > Create .claude/commands/deploy.md for deployment workflow
  6. Configure multi-directory access

    Terminal window
    > /add-dir ../design-system
    > /add-dir ../shared-types
  7. Test the setup

    Terminal window
    > Create a new user authentication feature following our patterns

Golden Rules for CLAUDE.md Files

  1. Be specific over general - “Use Zod for validation” not “validate inputs”
  2. Include examples - Show Claude exactly what you want
  3. Document the why - Explain reasoning behind conventions
  4. Update regularly - Use # to add learnings as you code
  5. Review periodically - Clean up outdated information monthly
  6. Test effectiveness - Ask Claude to explain your conventions back

Too vague: “Write good code”
Specific: “Use early returns, max 3 levels of nesting, extract complex conditions”

No context: “Use our API style”
With context: “Follow REST conventions: GET /api/users, POST /api/users, use kebab-case”

Outdated info: “We use React 16 class components”
Current: “React 19 with Server Components, use function components only”

Symptom: Claude doesn’t seem aware of your CLAUDE.md content

Solutions:

  1. Check file location - must be in project root or parent directories
  2. Verify file name - exactly CLAUDE.md (case-sensitive on Linux/Mac)
  3. Run /memory to see what’s loaded
  4. Restart Claude Code after adding new memory files

Now that your project is initialized with rich context:

Remember: Great context leads to great code. Invest time in your CLAUDE.md files and watch your productivity soar!