Skip to main content

Memory Tool (save_memory)

The memory tool allows Qwen Code to save and recall information across sessions, enabling personalized and context-aware assistance.

Overview

Tool Name: save_memory Display Name: Memory Kind: Edit Description: Saves specific facts or information to long-term memory that persists across sessions.

Parameters

Usage

Save to Global Memory

Save to Project Memory

Auto-select Scope

Memory Scopes

Global Memory

Location: ~/.qwen/QWEN.md Purpose: User-level preferences and information shared across all projects Use for:
  • Personal preferences
  • Coding style
  • Frequently used patterns
  • General instructions
Example:

Project Memory

Location: <project-root>/QWEN.md Purpose: Project-specific information Use for:
  • Project conventions
  • Architecture decisions
  • Team preferences
  • Build instructions
Example:

When to Use save_memory

Good Use Cases

✅ User preferences
✅ Project conventions
✅ Important facts
✅ Coding standards

When NOT to Use

❌ Conversational context
❌ Long, complex text
❌ Temporary information
❌ Uncertain information

How It Works

Memory Storage

Facts are appended to a markdown file under a special section:

Memory Loading

Memory files are automatically loaded:
  1. On startup: Contents included in initial context
  2. Every session: Available to the model
  3. Project-specific: Project memories only load in that project
  4. Global always: Global memories load in all projects

Memory Format

Memories are stored as:
Example:

Configuration

Custom Memory Files

Change the memory file name:
All specified files will be loaded as context.

Multiple Context Files

You can have multiple context files:
All are loaded if specified in contextFileNames.

User Interaction

Scope Selection

If scope is not provided, the user is prompted:

Confirmation

Memory saves show confirmation:

Managing Memories

View Memories

Read the memory file:

Edit Memories

Manually edit the markdown file:

Remove Memories

Delete specific lines from the file or remove the entire section.

Organize Memories

You can reorganize the file structure:

Best Practices

1. Be Specific and Clear

✅ Good:
❌ Bad:

2. Choose Appropriate Scope

3. Keep Facts Concise

✅ Good:
❌ Bad:

4. Avoid Duplicates

Check existing memories before adding:

5. Update Instead of Add

If information changes, edit the file manually rather than adding a new fact.

Implementation

Location: packages/core/src/tools/memoryTool.ts

Tool Class

Memory File Functions

Security

No Sensitive Data

⚠️ Warning: Don’t save sensitive information:
Memory files are plain text and may be committed to version control.

.gitignore

Consider ignoring memory files:
Or commit them if they only contain non-sensitive project information.

Troubleshooting

Memory Not Loaded

Problem: Saved memory doesn’t appear in context Solutions:
  1. Restart Qwen Code
  2. Check file location:
  3. Verify contextFileNames setting
  4. Check file permissions

Wrong Scope

Problem: Saved to wrong scope Solution: Manually move the fact between files:

Duplicate Memories

Problem: Same fact saved multiple times Solution: Edit the file and remove duplicates:

Examples

Development Preferences

Project Setup

Architectural Decisions

Next Steps