Join our Discord Server
Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).

Claude Code Memory: How to Use CLAUDE.md, Custom Slash Commands and Skills

2 min read

AI brain circuit - Claude Code Memory and Custom Commands

One of the most-searched Claude Code topics in 2026 is how to give Claude persistent memory and custom commands. This tutorial covers CLAUDE.md, the memory system, and custom slash commands (skills) – the trio that makes Claude Code truly feel like a team member who knows your project.

1. CLAUDE.md – Give Claude Permanent Project Context

CLAUDE.md is a markdown file Claude reads at the start of every session. Think of it as a system prompt for your project.

# Initialize CLAUDE.md automatically
cd my-project
claude
> /init
# Claude reads your codebase and generates a CLAUDE.md for you

Here is a production-quality CLAUDE.md template:

# CLAUDE.md

## Project: E-Commerce API
Node.js 20 + Express + PostgreSQL + TypeScript

## Architecture
- src/routes/     → API route handlers
- src/services/   → Business logic
- src/models/     → Prisma DB models
- src/middleware/ → Auth, rate limiting, error handling
- tests/          → Jest unit and integration tests

## Coding Standards
- Use TypeScript strict mode always
- Named exports only (no default exports)
- Use Zod for all request validation
- Use Result pattern for error handling (never throw)
- Every new function needs a JSDoc comment
- Every new file needs a corresponding test file

## Database
- ORM: Prisma
- Run migrations: npx prisma migrate dev
- Seed: npx prisma db seed
- Never write raw SQL  -  use Prisma query builder

## Testing
- Run tests: npm test
- Run single file: npx jest src/routes/users.test.ts
- Coverage target: 80% minimum

## Git
- Branch naming: feat/, fix/, chore/, docs/
- Commit format: conventional commits (feat: add user endpoint)
- Never commit directly to main

## Common Commands
- Start dev: npm run dev
- Build: npm run build
- Lint: npm run lint
- Type check: npm run typecheck

2. The Memory System – Four Levels

Claude Code has a four-tier memory hierarchy. Understanding it helps you put the right info in the right place:

# Memory file locations and their scope:

~/.claude/CLAUDE.md          # Global  -  applies to ALL projects
./CLAUDE.md                  # Project root  -  applies to this project
./src/CLAUDE.md              # Subdirectory  -  applies when working in src/
./.claude/CLAUDE.md          # Alternative project location

# Claude reads them all, innermost takes priority

# Global CLAUDE.md example (~/.claude/CLAUDE.md)
cat ~/.claude/CLAUDE.md
# My name is Alex. I prefer concise explanations.
# Always use pnpm, never npm or yarn.
# I work in TypeScript. Prefer functional patterns over OOP.
# When reviewing code, check for: security, performance, readability.

# Add a memory mid-session
> /memory add "We decided to use Redis for session storage, not JWT"

# View all current memories
> /memory

3. Custom Slash Commands (Skills)

Custom slash commands let you create reusable prompt templates. They live in .claude/commands/ as markdown files.

# Create the commands directory
mkdir -p .claude/commands

# Commands become available as /project:command-name
# File name = command name
ls .claude/commands/
# code-review.md
# new-feature.md
# debug.md
# security-audit.md
# release-notes.md
# .claude/commands/code-review.md
Review the staged git changes (`git diff --staged`) for:

1. **Bugs**  -  logic errors, null pointer risks, off-by-one errors
2. **Security**  -  injection risks, unvalidated input, exposed secrets
3. **Performance**  -  unnecessary loops, missing indexes, N+1 queries
4. **Code quality**  -  naming, duplication, complexity
5. **Test coverage**  -  are new functions tested?

Format your output as:
## Summary
One sentence overview.

## Issues Found
- [CRITICAL] description
- [WARNING] description
- [SUGGESTION] description

## Verdict
APPROVE / REQUEST CHANGES
# .claude/commands/new-feature.md
Create a new feature based on this description: $ARGUMENTS

Steps to follow:
1. Create the route handler in src/routes/
2. Create the service in src/services/
3. Add Prisma model updates to schema.prisma if needed
4. Add Zod validation schema
5. Write unit tests in tests/
6. Update API documentation in docs/api.md
7. Run npm test to verify everything passes

Follow the conventions in CLAUDE.md exactly.
# .claude/commands/security-audit.md
Perform a security audit on the codebase. Check for:

- SQL injection vulnerabilities
- XSS vectors
- Unvalidated user input reaching the database
- Hardcoded secrets or credentials
- Missing authentication on protected routes
- Insecure direct object references (IDOR)
- Missing rate limiting on public endpoints
- Dependency vulnerabilities (run: npm audit)

Output a prioritized list of findings with file:line references.
Mark each: CRITICAL / HIGH / MEDIUM / LOW

Use them inside a session:

# Inside claude session
> /project:code-review
> /project:new-feature "user profile picture upload with S3"
> /project:security-audit
> /project:release-notes

# List all available project commands
> /project:

4. Global Commands – Reuse Across All Projects

Store commands in ~/.claude/commands/ to make them available in every project:

mkdir -p ~/.claude/commands

# ~/.claude/commands/explain.md
cat > ~/.claude/commands/explain.md << EOF
Explain the following code to a senior engineer.
Be concise. Focus on: what it does, why it works this way, and any gotchas.
Code: $ARGUMENTS
EOF

# ~/.claude/commands/pr-desc.md
cat > ~/.claude/commands/pr-desc.md << EOF
Generate a pull request description for the current git branch.
Run: git log main..HEAD --oneline and git diff main...HEAD --stat

Format:
## What Changed
## Why
## How to Test
## Breaking Changes (if any)
EOF

# Use from any project
> /user:explain "the binary search implementation in src/utils.ts"
> /user:pr-desc

5. Complete Project Setup Script

Here is a shell script to bootstrap the full Claude Code memory and commands setup for any new project:

#!/bin/bash
# setup-claude.sh  -  Bootstrap Claude Code for a new project

PROJECT_NAME=$1
STACK=$2  # e.g. "Node.js TypeScript PostgreSQL"

mkdir -p .claude/commands

# Create CLAUDE.md
cat > CLAUDE.md << EOF
# CLAUDE.md  -  ${PROJECT_NAME}
Stack: ${STACK}

## Architecture
(describe your folder structure here)

## Coding Standards
- (list your conventions)

## Testing
- Run tests: npm test

## Common Commands
- Dev: npm run dev
EOF

# Create default commands
cat > .claude/commands/code-review.md << EOF
Review git diff --staged for bugs, security issues, and code quality.
Format: ## Summary, ## Issues (CRITICAL/WARNING/SUGGESTION), ## Verdict
EOF

cat > .claude/commands/new-feature.md << EOF
Build a new feature: $ARGUMENTS
Follow all conventions in CLAUDE.md. Write tests. Run npm test when done.
EOF

cat > .claude/commands/debug.md << EOF
Debug the following issue: $ARGUMENTS
1. Read relevant files. 2. Identify root cause. 3. Fix it. 4. Add a test to prevent regression.
EOF

echo "Claude Code setup complete!"
echo "Files created: CLAUDE.md, .claude/commands/"
echo "Next: run claude and use /init to let Claude refine CLAUDE.md"
# Run it
chmod +x setup-claude.sh
./setup-claude.sh "My API" "Node.js TypeScript PostgreSQL"

With CLAUDE.md, a layered memory system, and custom slash commands, Claude Code becomes a context-aware collaborator that understands your project conventions, architecture, and preferences from the very first message of every session.

Found this helpful? Share it!

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Distinguished Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 700+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 9800+ members and discord server close to 2600+ members. You can follow him on Twitter(@ajeetsraina).

Istio vs Linkerd vs Cilium: Best Kubernetes Service Mesh…

Explore Istio, Linkerd, and Cilium, three leading Kubernetes service meshes in 2025, analyzing their architectures, features, and practical applications.
Collabnix Team
3 min read
Join our Discord Server
Index