Magic Tools
AI TutorialsBy CooconMarch 29, 20261820 views2 min read

Claude Code Memory and Commands: CLAUDE.md, Slash Commands, and Workflow Shortcuts

Claude Code gets much more useful when you stop repeating the same instructions in every session. Anthropic's memory system and slash commands are the two features that make that possible. One preserves context across sessions. The other gives you fast controls for common actions while you are working.

The result is a more stable workflow: project rules stay in CLAUDE.md, personal preferences stay in your user memory, and session commands let you adjust Claude without rewriting the prompt from scratch.

How Claude Code memory works

Anthropic documents memory as a hierarchy with several layers:

  1. Enterprise policy memory for organization-wide instructions
  2. Project memory in ./CLAUDE.md
  3. User memory in ~/.claude/CLAUDE.md

That structure matters because it separates team-wide conventions from your own preferences. In practice, it lets Claude read the right instructions automatically when you open a project.

Claude Code also looks up memory files recursively from the current working directory, which is useful in larger repositories. You can see loaded memories with the /memory command.

What belongs in project memory

Use CLAUDE.md for instructions that should travel with the codebase:

  • Build and test commands
  • Naming conventions
  • Architecture notes
  • Team-specific coding rules
  • Common workflow reminders

The goal is to store the instructions you would otherwise keep repeating at the start of every session. That saves time and reduces inconsistency.

How to add or edit memory quickly

Anthropic provides two easy paths:

  • Start a message with # to add a memory quickly
  • Use /memory to open the relevant memory file in your editor

Example:

# Always prefer small, reviewable changes

That is enough to capture a simple preference without interrupting your flow.

Slash commands that matter most

The built-in slash commands Anthropic highlights are especially practical for day-to-day work:

  • /init to initialize a project with a CLAUDE.md guide
  • /clear to clear conversation history
  • /compact to compress the conversation when it gets too long
  • /config to view or modify configuration
  • /mcp to manage MCP connections
  • /model to switch models
  • /permissions to review or update permissions
  • /help to see what is available

These commands let you adjust the session without breaking your flow or retyping large instructions.

Custom commands for repetitive work

Anthropic also supports custom slash commands stored as Markdown files. That is useful when your team repeats the same tasks often.

Project commands live in .claude/commands/, and personal commands live in ~/.claude/commands/. You can use them for things like:

  • Code review checklists
  • Security review prompts
  • Refactor instructions
  • Documentation update workflows

If you routinely ask Claude to do the same kind of task, a command is often better than a long prompt because it is easier to reuse and easier to keep consistent.

A simple memory strategy

Use a three-layer rule:

  1. Put team rules in project memory
  2. Put personal defaults in user memory
  3. Put one-off instructions in the current session

That keeps Claude Code predictable. It also reduces the temptation to stuff everything into a single prompt.

Official References

Sources reviewed on March 29, 2026. Feature availability, plan limits, and interface details can change, so confirm current behavior in the linked official Anthropic resources.

Related Articles

Blocking rm -rf in Claude Code: A Deny Rule Stopped 14 Deletes in Two Weeks, 7 Other Spellings Still Get Through, and a Hook That Closes the Gap

To keep Claude Code from deleting things by accident, I added a deny rule, Bash(rm -rf *), to my global settings. Across my sessions from October 7 to 21 it blocked 14 deletes. After each denial the model picked a new directory name 8 times and dropped the delete 6 times. It never tried another spelling. Then I replayed 22 delete commands verbatim against Claude Code 2.1.285 through a stub. rm -fr, rm -r -f, rm -Rf and rm -r deleted the directory in manual, auto and bypass mode alike. /bin/rm, find -delete and bash -c deleted it in manual and bypass mode. In auto mode, rm -fr inside the working directory skips the classifier because it 'would be allowed in acceptEdits mode'. A second, built-in dangerous-rm check fires on targets like $D/*, even in bypass mode, but loses track of a variable assignment when a heredoc comes earlier in the same command. The post ends with a PreToolUse hook that blocks every recursive spelling in all three modes and tells the model what to do instead.

claude-codehooks+5
pitfallsOct 21, 20268 min
208

Claude Code Auto Mode with DeepSeek, GLM or Kimi: What Each "temporarily unavailable" Reason Means and When Retrying Is Pointless (Fault-Injection Test)

On a third-party model, Claude Code auto mode sends one extra classifier request per side-effecting action, from your session model to the same backend: a 132,470-character system prompt, about 29.7K input tokens per check. When it fails, you see "xxx is temporarily unavailable, so auto mode cannot determine the safety of Bash". We injected faults and recorded each message: 500 (server error), 429 (rate-limited), 529 (overloaded) and connection resets (connection failed) are retried 5 times; no reply in 60 s gives (timed out). **No parentheses means a 4xx rejection: tried once, and retrying never helps.** A reply with no verdict gives "could not evaluate"; three in a row bring back manual approval. CLAUDE_CODE_AUTO_MODE_MODEL has no effect. Claude Code 2.1.285, real DeepSeek v4-pro and MiMo v2.5 backends.

claude-codedeepseek+7
pitfallsOct 11, 202612 min
422

Claude Code "Prompt is too long" vs "maximum context length": Why Auto-Compact Works for One and Not the Other (Tested)

Claude Code decides a request was too long by matching the error text. If the backend says prompt is too long or input is too long for requested model, it auto-compacts the conversation and retries — invisible to you. DeepSeek and OpenAI-style gateways say This model's maximum context length is …, which it doesn't recognize: you get API Error: 400 on every turn. Manual /compact works; the better fix is to declare the real window with CLAUDE_CODE_MAX_CONTEXT_TOKENS (non-claude- model IDs) or CLAUDE_CODE_AUTO_COMPACT_WINDOW (claude- IDs) so it compacts before hitting the limit. Tested on Claude Code 2.1.285 against a local stub.

claude-codedeepseek+6
pitfallsOct 5, 20267 min
437

Claude Code Stuck on a Spinner With No Response: It Waits 6 Minutes per Attempt, and 10 Retries Can Hang It for Over an Hour (Tested)

When Claude Code spins without output or sits at Retrying in 0s, the backend is usually not sending anything. Tested on 2.1.285 (API key + ANTHROPIC_BASE_URL): with no response headers it waits 6 minutes (360 s) per attempt before timing out — setting API_TIMEOUT_MS to 600000 or 900000 doesn't change that; only lower values work. With the default 10 retries it can hang for over an hour. A gateway that buffers the reply until generation finishes will never deliver a reply that takes over 6 minutes. Press Esc to interrupt. All tested against a local stub.

claude-codetroubleshooting+5
pitfallsOct 5, 20269 min
377

Published by Magic Tools