CLAUDE.md's four-level scope system, custom slash commands, and Skills system can establish persistent project memory and reusable workflows for Claude Opus 4.7, avoiding the need to repeat project conventions in every session.
Suitable tasks: Long-term development that requires project consistency, team collaboration, standardized development processes, and complex multistep tasks
Unsuitable tasks: One-off simple tasks and temporary scripts that do not require project context
Applicable model version: Claude Opus 4.7
Applicable client, Agent, or API: Claude Code
Recommended reasoning levels and parameters: Use xhigh for complex workflows and high for everyday commands
# 1. User-level (shared across all projects)
~/.claude/CLAUDE.md
# Example: personal preferences
cat > ~/.claude/CLAUDE.md << 'EOF'
# My preferences
- Use TypeScript strict mode
- Prefer a functional programming style
- During code review, check security, performance, and readability
- Use pnpm, not npm or yarn
EOF
# 2. Project-level (for a specific project)
./CLAUDE.md
# Example: project configuration
cat > CLAUDE.md << 'EOF'
# 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 database models
- src/middleware/ → Authentication, rate limiting, and error handling
- tests/ → Jest unit and integration tests
## Coding standards
- Always use TypeScript strict mode
- Use named exports only (no default exports)
- Use Zod for all request validation
- Use the Result pattern for error handling (do not throw exceptions)
- Every new function requires a JSDoc comment
- Every new file requires a corresponding test file
## Database
- ORM: Prisma
- Run migrations: npx prisma migrate dev
- Seed data: npx prisma db seed
- Do not write raw SQL; use the Prisma query builder
## Testing
- Run tests: npm test
- Run a single file: npx jest src/routes/users.test.ts
- Coverage target: at least 80%
## Git
- Branch naming: feat/, fix/, chore/, docs/
- Commit format: conventional commits (feat: add user endpoint)
- Do not commit directly to main
## Common commands
- Start development: npm run dev
- Build: npm run build
- Lint: npm run lint
- Type check: npm run typecheck
EOF
# 3. Directory-level (for a specific directory)
./src/CLAUDE.md
# 4. Git-ignored level (not shared)
./.claude/CLAUDE.md
echo ".claude/CLAUDE.md" >> .gitignore# Create the command directory
mkdir -p .claude/commands
# Command 1: code review
cat > .claude/commands/code-review.md << 'EOF'
Review staged git changes (`git diff --staged`) and check:
1. **Bugs** - Logic errors, null pointer risks, and boundary errors
2. **Security** - Injection risks, unvalidated input, and exposed secrets
3. **Performance** - Unnecessary loops, missing indexes, and N+1 queries
4. **Code quality** - Naming, duplication, and complexity
5. **Test coverage** - Are new functions tested?
Output format:
## Summary
One-sentence overview.
## Findings
- [Critical] Description
- [Warning] Description
- [Suggestion] Description
## Conclusion
Pass / Changes required
EOF
# Command 2: new feature development
cat > .claude/commands/new-feature.md << 'EOF'
Create a new feature based on the following description: $ARGUMENTS
Execution steps:
1. Create a route handler in src/routes/
2. Create a service layer in src/services/
3. If the Prisma model needs updating, modify schema.prisma
4. Add a Zod validation schema
5. Write unit tests in tests/
6. Update the API documentation in docs/api.md
7. Run npm test to verify that all tests pass
Strictly follow the conventions in CLAUDE.md.
EOF
# Command 3: security audit
cat > .claude/commands/security-audit.md << 'EOF'
Perform a security audit of the codebase and check for:
- SQL injection vulnerabilities
- XSS vectors
- Unvalidated user input reaching the database
- Hardcoded keys or credentials
- Missing authentication on protected routes
- Insecure direct object references (IDOR)
- Missing rate limits on public endpoints
- Dependency vulnerabilities (run: npm audit)
Output a prioritized list of findings with file:line references.
Mark each as: Critical / High / Medium / Low
EOF
# Command 4: debugging
cat > .claude/commands/debug.md << 'EOF'
Debug the following issue: $ARGUMENTS
Steps:
1. Read the relevant files
2. Identify the root cause
3. Fix the issue
4. Add tests to prevent regression
EOF
# Use the commands
# Enter in Claude Code:
# /code-review
# /new-feature "Upload user avatars to S3"
# /security-audit
# /debug "TypeError: Cannot read property 'id' of undefined"# Create the global command directory
mkdir -p ~/.claude/commands
# Global command 1: explain code
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 pitfalls.
Code: $ARGUMENTS
EOF
# Global command 2: PR description
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:
## Changes
## Rationale
## Testing method
## Breaking changes (if any)
EOF
# Use in any project
# /explain "Binary search implementation in src/utils.ts"
# /pr-desc#!/bin/bash
# setup-claude.sh - Configure Claude Code for a new project
PROJECT_NAME=$1
STACK=$2 # Example: "Node.js TypeScript PostgreSQL"
mkdir -p .claude/commands
# Create CLAUDE.md
cat > CLAUDE.md << EOF
# CLAUDE.md - ${PROJECT_NAME}
Tech stack: ${STACK}
## Architecture
(Describe your directory structure here)
## Coding standards
- (List your standards)
## Testing
- Run tests: npm test
## Common commands
- Development: 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), ## Conclusion
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 finished.
EOF
cat > .claude/commands/debug.md << 'EOF'
Debug the following issue: $ARGUMENTS
1. Read the relevant files. 2. Identify the root cause. 3. Fix it. 4. Add tests to prevent regression.
EOF
echo "Claude Code configuration complete!"
echo "Created files: CLAUDE.md, .claude/commands/"
echo "Next step: run claude and use /init to have Claude improve CLAUDE.md"Initialize the project: Run the setup script or manually create CLAUDE.md and .claude/commands/
Configure personal preferences: Set global preferences in ~/.claude/CLAUDE.md
Define project conventions: Document the architecture, standards, and commands in detail in the project-root CLAUDE.md
Create common commands: Create commands such as code-review and new-feature based on the team's workflow
Test commands: Run /command-name in Claude Code to verify the results
Iterate and optimize: Adjust CLAUDE.md and command definitions based on actual use
Share with the team: Commit CLAUDE.md and .claude/commands/ to Git (excluding personal configuration)
The article provides a detailed demonstration of the four-level CLAUDE.md scope system
It provides complete examples of custom commands (code-review, new-feature, security-audit, and debug)
It demonstrates how global commands and user-level configuration can be reused
It includes a complete project initialization script
All code examples are complete implementations that can be copied and used directly
CLAUDE.md loading order: inner scopes take precedence over outer scopes (directory level > project level > user level)
Custom commands use the $ARGUMENTS placeholder to pass parameters
The command filename is the command name (code-review.md → /code-review)
Global commands (~/.claude/commands/) are available in all projects
Project commands (.claude/commands/) are available only in the current project
CLAUDE.md and command definitions require team maintenance and updates
Some complex workflows may require the Skills system (more advanced)
Article title: "Claude Code Memory: How to Use CLAUDE.md, Custom Slash Commands and Skills"
The article emphasizes: "Give Claude permanent project context" (giving Claude permanent project context), using CLAUDE.md and custom commands to provide persistent memory and standardized workflows.
Claude Opus 4.7