Claude Code /init: Generate CLAUDE.md in 10 Seconds
Table of Contents
What is /init
If you’ve used Claude Code, you know about CLAUDE.md — the file that tells Claude Code everything about your project so it doesn’t start every session from scratch.
But writing CLAUDE.md by hand can be tedious, especially when you’re picking up a new project or dealing with a legacy codebase where even you don’t have the full picture yet.
That’s where /init comes in.
/init is a slash command in Claude Code’s interactive mode. It automatically scans your entire codebase and generates a CLAUDE.md file for you.
In short: you don’t have to write it yourself — let Claude Code do it.
What It Does
When you run /init in your project root, Claude Code will:
- Scan the project structure — traverse the directory tree, identify the project type (Next.js? Express? Python? Monorepo?)
- Analyze config files — read
package.json,tsconfig.json,pyproject.toml,Cargo.toml, etc., extracting the tech stack, dependencies, and scripts - Understand the architecture — identify source directories, core modules, and entry points
- Detect coding standards — check ESLint, Prettier, lint-staged, and other configs to extract code style conventions
- Generate CLAUDE.md — compile all of the above into a structured Markdown file and write it to the project root
The whole process is automatic. You just review the output and confirm.
How to Use It
Basic Usage
Navigate to your project directory, start Claude Code, and type:
/init
That’s it. Claude Code will analyze your project — taking anywhere from a few seconds to half a minute depending on project size — and present the generated CLAUDE.md for your review.
Once you confirm, the file is written to your project root.
When to Use It
- Picking up a new project — unfamiliar with the code? Let
/initgive you a structured overview. The generated CLAUDE.md doubles as a solid project summary - Adding docs to a legacy project — been running for years with no CLAUDE.md? One command fixes that
- Exploring open source projects — clone it, run
/init, and instantly get the big picture - Team collaboration — commit the generated file so everyone on the team benefits when using Claude Code
Things to Keep in Mind
/initonly works in Claude Code’s interactive mode — you can’t runclaude /initdirectly from the command line- If a CLAUDE.md already exists,
/initwill update it based on the current codebase rather than overwriting it - The generated content is a great starting point, but you should manually refine and supplement it
What the Generated CLAUDE.md Looks Like
A typical /init output includes these sections:
# CLAUDE.md
## Project Overview
Brief description of the project, tech stack, and core functionality.
## Commands
Common build, test, lint, and deploy commands.
## Architecture
Directory structure, core modules, and data flow.
## Code Style
Coding conventions, formatter config, naming rules.
## Development Workflow
Dev process, branching strategy, CI/CD details.
The specifics vary by project type and complexity. A simple Node.js app might get a few dozen lines; a large monorepo will be more detailed.
Real-World Examples
Example 1: Next.js Project
Running /init in a Next.js 15 project generates something like:
# CLAUDE.md
## Project Overview
A Next.js 15 application using App Router with TypeScript and Tailwind CSS.
## Commands
| Command | Purpose |
| --------------- | ------------------- |
| `npm run dev` | Start dev server |
| `npm run build` | Production build |
| `npm run lint` | Run ESLint |
| `npm run test` | Run tests with Jest |
## Architecture
- `src/app/` - App Router pages and layouts
- `src/components/` - Reusable UI components
- `src/lib/` - Utility functions and shared logic
- `src/styles/` - Global styles and Tailwind config
## Code Style
- TypeScript strict mode enabled
- Prettier with 2-space indent, single quotes
- ESLint with Next.js recommended rules
Example 2: Monorepo
Running /init in a Lerna + Nx monorepo:
# CLAUDE.md
## Project Overview
A frontend monorepo managed by Lerna + Nx with npm workspaces.
## Commands
| Command | Purpose |
| --------------- | ------------------------------------ |
| `npm run build` | Build all packages (lerna run build) |
| `npm run test` | Test all packages |
| `npm run lint` | Full pipeline: build → lint → test |
## Monorepo Rules
- Install deps from root: `npm i <pkg> -w <sub-package>`
- Run scripts from root: `npm run <script> -w <sub-package>`
- Never cd into sub-packages to install or run scripts.
## Packages
- `packages/app` - Main web application (Next.js)
- `packages/ui` - Shared UI component library
- `packages/utils` - Common utility functions
Example 3: Python Project
Running /init in a FastAPI project:
# CLAUDE.md
## Project Overview
A FastAPI REST API with SQLAlchemy ORM and PostgreSQL.
## Commands
| Command | Purpose |
| ------------------------------- | ----------------- |
| `uvicorn app.main:app --reload` | Start dev server |
| `pytest` | Run tests |
| `alembic upgrade head` | Run DB migrations |
## Architecture
- `app/main.py` - Application entry point
- `app/routers/` - API route handlers
- `app/models/` - SQLAlchemy models
- `app/schemas/` - Pydantic schemas
- `alembic/` - Database migrations
## Code Style
- Black formatter, line length 88
- isort for import sorting
- Type hints required on all functions
/init vs Writing CLAUDE.md by Hand
| /init (auto-generated) | Manual | |
|---|---|---|
| Speed | Seconds | 30+ minutes |
| Accuracy | Based on code analysis, objectively accurate | Based on personal understanding, may miss things |
| Depth | Broad coverage, but may lack business context | Can include domain logic, known pitfalls |
| Maintenance | Re-run after project changes | Must update manually |
| Best practice | Use /init as a base, then refine manually | — |
My recommendation: start with /init to generate a baseline, then manually add the things code analysis can’t capture — business-specific gotchas, known pitfalls, team conventions, and architectural decisions.
Final Thoughts
/init is a small but practical command in Claude Code. The problem it solves is simple: you don’t have to write CLAUDE.md from scratch.
For new projects, it quickly establishes Claude Code’s understanding of your codebase. For legacy projects, it fills in the “AI-friendly” documentation that’s always been missing.
Next time you pick up a new project, try typing /init in Claude Code and see how well it understands your code. You might be surprised by how accurate it is — after all, code doesn’t lie.
Related Articles
Claude Code Agent Loop: Dissecting the Heart of an AI Coding Assistant
How does Claude Code understand your requests, invoke tools, and self-recover step by step? A source-code deep dive into the Agent Loop's core architecture — streaming responses, parallel tool execution, auto-compaction, and error recovery.
Claude Code settings.json Explained (1): Where Config Files Live and Who Wins
A complete guide to Claude Code's configuration file system — five config sources, their file paths, priority rules, array merging vs value overriding, and enterprise managed settings delivery.
Claude Code settings.json Deep Dive (Part 2): The Permissions System
A thorough breakdown of Claude Code's permissions configuration — allow/deny/ask rule arrays, wildcard syntax, MCP tool permissions, defaultMode options, and additionalDirectories.
Claude Code settings.json Deep Dive (Part 3): The Hooks System
A thorough breakdown of Claude Code's hooks configuration — four hook types, core events (PreToolUse/PostToolUse/Stop/Notification), stdin/stdout protocol, exit code semantics, and practical examples.
Claude Code settings.json Deep Dive (4): env, Models, Auth, and Other Useful Fields
A comprehensive guide to the remaining settings.json fields in Claude Code — env variable injection, model configuration, authentication helpers, Git attribution, session cleanup, language and UI, thinking depth, auto-updates, memory system, and more.