All posts

· Updated · By

Claude Code Slash Commands & Memory (Part 2)

claude-codeaitutorialproductivity

If you’ve been following along from Part 1, you know how to run Claude Code and execute basic workflows. But here’s where things get really interesting: slash commands and memory are the features that transform Claude Code from a useful tool into your personal AI copilot.

Think of slash commands as your custom shortcuts—quick invocations that trigger Claude with context-specific instructions. And memory? That’s how you teach Claude about your project, your coding style, and your preferences so it remembers them across every session. Together, they create a workflow tailored entirely to you.

Let me walk you through both, using real examples I’ve built in my own projects.

Slash Commands: Custom Shortcuts at Your Fingertips

What Are Slash Commands?

Slash commands are user-defined shortcuts you invoke with a forward slash—like /optimize or /pr—that trigger Claude Code with predefined instructions. They’re stored as Markdown files in your .claude/commands/ directory (or ~/.claude/commands/ for personal ones).

2026 update: Anthropic has merged custom commands into skills. Files in .claude/commands/ keep working exactly as described here, but for new commands that need supporting files, use .claude/skills/<name>/SKILL.md. The folder name becomes the command, so you still type /<name>. Part 3 covers skills.

When you type a slash command, Claude Code loads the corresponding .md file, which contains:

  • A description of what the command does
  • The prompt instructions Claude should follow
  • Optional arguments, available as $ARGUMENTS (everything you typed after the command) or $0, $1, … for individual arguments

This is fundamentally different from running general prompts. You’re bundling expertise into reusable packages.

Creating Your First Command: /optimize

Let’s say you’re constantly reviewing code for performance improvements. Instead of explaining the optimization task every time, you can create an /optimize command once and use it everywhere.

Here’s how:

Step 1: Create the command file

mkdir -p .claude/commands
touch .claude/commands/optimize.md

Step 2: Write the command with a clear prompt

# Optimize Code Performance

Analyze the provided code for performance improvements. Focus on:
- Time complexity issues
- Unnecessary allocations or loops
- Caching opportunities
- Algorithm optimization

Provide:
1. Specific bottlenecks you identified
2. Concrete improvements with code examples
3. Performance impact (e.g., "reduces from O(n²) to O(n log n)")
4. Risk assessment (is this change safe? do we need tests?)

Keep the tone technical but clear for other developers to understand.

Step 3: Use it in Claude Code

claude code /optimize
# Claude now runs with your optimization instructions

You can also pass context:

claude code /optimize src/utils/sorting.js

Claude Code will read your sorting utility, understand it should optimize it, and deliver analysis without you explaining the task each time.

Practical Examples for Your Workflow

Here are commands I’ve created that I use weekly:

Pull Request Descriptions (/pr)

# Generate PR Description

Analyze the git diff and create a clear PR description. Include:

## What Changed
Brief summary of the changes (2-3 sentences).

## Why
Explain the motivation. Is this a bug fix? Feature? Refactor?

## Testing
What tests should reviewers run? Any manual QA steps?

## Checklist
- Tests pass
- No console errors
- Documentation updated (if applicable)

Code Review Feedback (/review)

# Code Review

Review the provided code for:
1. Correctness - will this work as intended?
2. Readability - is it clear to other developers?
3. Performance - any red flags?
4. Security - any vulnerabilities?
5. Maintainability - will this be easy to modify later?

Format feedback as:
- **Issue**: What's the problem?
- **Impact**: Why does it matter?
- **Suggestion**: How would you fix it?

Be constructive. Assume good intent.

Generate API Docs (/generate-api-docs)

# Generate API Documentation

Create comprehensive API documentation for the provided code. Include:

## Overview
What does this API do?

## Methods
For each public method:
- Full signature
- Parameters with types
- Return value
- Example usage

## Errors
What exceptions can this raise?

## Examples
Provide 2-3 realistic usage examples.

Use clear, professional language. Target developers who haven't seen this code.

Tips for Effective Commands

Keep them focused. A command should handle one specific task. Don’t try to make /review do code review, optimization, security checks, and documentation. Separate concerns.

Use template variables. If your command needs specific filenames or parameters, you can include them:

# Optimize {{filename}}

Review {{filename}} for performance bottlenecks...

Then invoke: claude code /optimize src/utils/sorting.js

Version your commands. As you refine what works, update your commands. Your future self will thank you for commands that get better over time.

Document the intent, not just the task. Include context about why the command exists: “This is for initial code reviews where speed matters—be thorough but concise.”

Memory: Teaching Claude About Your Project

Slash commands are about how you work. Memory is about what Claude needs to know—your coding standards, your architecture, your preferences.

Three Levels of Memory

Claude Code supports three memory scopes:

1. Project Memory (./CLAUDE.md)

Lives in your project root. This is shared context for everyone on the team.

# ZenoLab Frontend Standards

## Architecture
We use Next.js with:
- App Router (not Pages Router)
- Server Components by default
- Client Components only when needed
- TailwindCSS for styling

## Code Style
- TypeScript strict mode required
- Prefer `const` over `let`
- No `var`
- Named exports, not defaults

## Testing
- Jest + React Testing Library
- Aim for 80%+ coverage
- Test user behavior, not implementation details

## Preferred Libraries
- React Query for data fetching
- Zustand for state (not Redux)
- next/link for navigation

## Common Gotchas
- Don't forget `use client` when creating interactive components
- Server Components can't use hooks

When Claude Code runs in your project, it automatically loads this. Now Claude understands your tech stack, your standards, and your preferences without you explaining it every time.

2. Directory Memory (./api/CLAUDE.md)

Specific to a subdirectory. Useful for modules with distinct conventions.

# API Module Standards

## Structure

api/ routes/ middleware/ controllers/ services/ types/


## Patterns
- All routes should go through middleware chain
- Controllers handle request validation
- Services handle business logic
- Keep routes thin

## Error Handling
Always return consistent error format:
```json
{
  "error": "error_code",
  "message": "Human readable message",
  "status": 400
}

**3. Personal Memory (`~/.claude/CLAUDE.md`)**

Your personal preferences, across all projects. This lives in your home directory.

```markdown
# My AI Assistant Configuration

## Writing Style
- Conversational, not robotic
- Use "we" when collaborating
- Concise—get to the point fast
- Use metaphors when explaining complex concepts

## Code Style Preferences
- I prefer functional programming patterns
- Favor readability over cleverness
- Comments should explain *why*, not *what*

## Common Patterns I Use
- Custom React hooks for logic extraction
- Repository pattern for data access
- Feature flags for releases

## Don't Do This
- Never suggest I use frameworks I haven't approved
- Don't generate boilerplate without asking
- Don't create files without confirmation

How Memory Gets Loaded

Claude Code loads memory files like this:

  1. Personal memory (~/.claude/CLAUDE.md) loads in every session.
  2. CLAUDE.md (and a gitignored CLAUDE.local.md) in your working directory and every directory above it load at launch.
  3. CLAUDE.md files in subdirectories load on demand, the first time Claude reads or edits a file in that subdirectory. That is why ./api/CLAUDE.md costs nothing until Claude touches the API code.

The files are concatenated, not overridden: instructions closer to where you are working are read last. Run /memory in a session to see which files loaded and open one for editing, or /init to have Claude draft a starter CLAUDE.md from your codebase.

What Makes This Powerful

Imagine you’re pairing on a new project. Instead of spending 30 minutes explaining your architecture, you point Claude Code at your CLAUDE.md:

“Here’s our project memory. Now when I ask you to build a new API endpoint, you’ll understand where it goes, how it integrates, what patterns we use, and what we’re avoiding.”

Better yet: it works across sessions. You write memory once. Every future conversation has it automatically.

For indie developers especially, this is a game-changer. You can build increasingly sophisticated internal mental models—how your codebase is organized, your preferred patterns, your quality standards—and have them available instantly when you need to move fast.

The Memory + Slash Command Combo

Here’s where it gets really powerful. Your slash commands can reference your memory:

# Optimize Code Performance

Consider these architectural patterns from our project memory:
- We prefer functional patterns
- We avoid premature optimization
- Performance should be measurable, not theoretical

[rest of command...]

Now your /optimize command respects your philosophy. You’re not just automating the task—you’re automating the task your way.

Next: Skills & Subagents

We’ve covered slash commands and memory—the personalization layer of Claude Code. Next in Part 3, we’ll explore skills and subagents: how to build reusable workflows that operate autonomously and can collaborate with each other.

Subagents are where things get really exciting. Imagine spawning a code review agent, a test-writing agent, and a documentation agent, and having them work together on your PR. That’s what’s coming.


Have you built any slash commands? Drop by my email or ping me on Twitter if you’ve found patterns that work well. I’m always curious what workflows others have discovered.

Frequently asked questions

How do I create a custom slash command in Claude Code?

Create a Markdown file such as .claude/commands/optimize.md with the prompt you want, then type /optimize in a session. Use $ARGUMENTS for everything typed after the command, or $0, $1 for individual arguments. For commands that need extra files, use a skill folder at .claude/skills/optimize/SKILL.md instead.

Are slash commands and skills the same thing now?

Custom commands have been merged into skills. Files in .claude/commands/ keep working, and a skill in .claude/skills/<name>/SKILL.md is invoked the same way with /<name>. Skills can also bundle supporting files and can be loaded by Claude automatically.

What is CLAUDE.md?

CLAUDE.md is a Markdown file of persistent instructions that Claude Code loads into context: your architecture, code style, preferred libraries, and things to avoid. ~/.claude/CLAUDE.md applies to every project, and ./CLAUDE.md applies to one repo.

How does Claude Code load CLAUDE.md files?

At launch it loads CLAUDE.md and CLAUDE.local.md from the working directory and every parent directory, plus your personal ~/.claude/CLAUDE.md. CLAUDE.md files in subdirectories load on demand when Claude first reads or edits a file there. The files are concatenated, not overridden. Run /memory to see what loaded.

More from the studio.

The apps this workflow ships live on the ZenoLab apps page, with every release in the shiplog.