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
Project Memory
Location:<project-root>/QWEN.md
Purpose: Project-specific information
Use for:
- Project conventions
- Architecture decisions
- Team preferences
- Build instructions
When to Use save_memory
Good Use Cases
✅ User preferencesWhen NOT to Use
❌ Conversational contextHow It Works
Memory Storage
Facts are appended to a markdown file under a special section:Memory Loading
Memory files are automatically loaded:- On startup: Contents included in initial context
- Every session: Available to the model
- Project-specific: Project memories only load in that project
- Global always: Global memories load in all projects
Memory Format
Memories are stored as:Configuration
Custom Memory Files
Change the memory file name:Multiple Context Files
You can have multiple context files:contextFileNames.
User Interaction
Scope Selection
Ifscope 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:2. Choose Appropriate Scope
3. Keep Facts Concise
✅ Good: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:.gitignore
Consider ignoring memory files:Troubleshooting
Memory Not Loaded
Problem: Saved memory doesn’t appear in context Solutions:- Restart Qwen Code
- Check file location:
- Verify
contextFileNamessetting - 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
- File System Tools - Reading and writing files
- Task Tool - Delegating tasks
- Configuration System - Configuring context files
- Subagents System - Subagent context
