# Qwen Code Memory: QWEN.md, Auto-Memory and Hindsight

> How Qwen Code remembers: QWEN.md files in three places, auto-memory that Qwen writes itself, the on-demand context_search tool, and adding Hindsight with native hooks. Limits included.

Source: https://aiagentmemory.org/articles/qwen-code-memory/ · Updated 2026-12-02 · aiagentmemory.org


## What is Qwen Code memory?

**Qwen Code keeps knowledge across sessions in three places: instruction files you write, notes it writes
itself, and an optional search tool for outside memory.** Each session starts with an empty context window,
so these files are how facts reach the next session. The Qwen Code memory docs
(qwenlm.github.io/qwen-code-docs, read 2 December 2026) describe all three.

| Layer | Who writes it | Loaded |
|---|---|---|
| QWEN.md | You or your team | Every session |
| Auto-memory | Qwen, from what you tell it | Every session, as a MEMORY.md index by default |
| `context_search` tool | Mem0 or a local index | Only when the model calls it |

## Where QWEN.md goes

| File | Applies to | Shared? |
|---|---|---|
| `~/.qwen/QWEN.md` | You, in all your projects | No |
| `QWEN.md` in the project root | The whole team | Yes, commit it |
| `.qwen/QWEN.local.md` | You, in this project only | No, keep it out of git |

Qwen loads all of them that exist. It loads `.qwen/QWEN.local.md` after the shared project file, so
your local rules can add to the team's. If the repo already has an `AGENTS.md` for other AI tools, Qwen
reads that too, so you do not need to copy the rules.

The docs suggest what to put in QWEN.md: build and test commands, team conventions, architecture
decisions, and personal preferences. They also say the file works best when it is short. The longer it
gets, the less reliably Qwen follows it.

## Auto-memory: notes Qwen writes itself

Auto-memory is **on by default**. Qwen writes notes about you and the project as it works, and it can
turn that off in two parts: the automatic saving and the periodic cleanup. Open `/memory` to flip the
switches, or set them in `~/.qwen/settings.json` (all projects) or `.qwen/settings.json` (this project).

By default the notes are private and live under your home directory. Team memory is a separate opt-in
tier. When you turn it on, notes go to `.qwen/team-memory/` inside the repo, and you share them with
`git pull` and `git push`. The docs say secrets are blocked there, but the scan is a backstop, not a
guarantee, so keep sensitive data out.

Qwen also runs a periodic cleanup that removes duplicates and outdated entries from its saved memories.

Commands you can use:

- `/memory`: open the memory switches and view what is saved.
- `/remember <text>`: save a note.
- `/forget <text>`: remove a note on request. The docs also say you can edit the memory files directly.

Structured recall is an opt-in mode. It replaces the flat `MEMORY.md` index with a tree and gives Qwen a
`search_memory` tool, which the docs say costs fewer tokens once a collection grows past a handful of files.

## External memory: context_search

The third layer is a tool, not a file. Qwen Code can call a `context_search` tool that queries an outside
service. The docs list Mem0 as a built-in adapter, configured in `~/.qwen/settings.json` under `memory.mem0`.
Any MCP server that implements `context_search` also works.

Unlike QWEN.md and auto-memory, the model calls this tool only when it decides to. Matches it returns go
into the model's context and to the model provider. Calls need approval unless you allow them.

## Adding Hindsight to Qwen Code

The Hindsight Coding Agents package supports Qwen Code. Its page
(hindsight.vectorize.io/sdks/integrations/coding-agents, read 2 December 2026) describes the setup:

1. Run `npx @vectorize-io/hindsight-coding-agents install qwen-code`.
2. The installer adds native hooks to `~/.qwen/settings.json`, plus MCP and a companion skill.
3. Capture is automatic. Repo history and conversations go to the repo's memory bank in the background.

Qwen's hook timeouts are in milliseconds, so the installer sets them to 30000, 30000 and 60000.

The default bank is `coding-agent::{gitProject}`, shared with OpenCode, Claude Code and Codex on the same
repo. Coding Agents 0.9.0 (30 November 2026) says memory comes back after a compaction for Qwen Code.
Source: hindsight.ai/oss/blog/2026/11/30/coding-agents-090.

**Limits:**

- **Headless runs do not recall.** `qwen -p`, `serve`, the SDK and ACP sessions save new memory but do not pull it back. Only interactive sessions recall once per prompt.
- Memory lives in Hindsight Cloud (an API key is needed), a server you run, or a local daemon.
- We found no independent benchmark of Hindsight with Qwen Code in the sources we checked, so this page makes no performance claim.

## Where this fits

QWEN.md is the right place for rules that do not change. Auto-memory fits small personal notes. A memory
bank fits facts that come out of the work, such as a root cause or a past decision, when you want them
to survive many sessions and many agents. Start with the files, and add a bank only when the notes get
too long to keep by hand.

For the same question on other tools, see [AI coding agent memory](/articles/ai-coding-agent-memory/),
[Claude Code memory](/articles/claude-code-memory/) and [OpenCode memory](/articles/opencode-memory/).

## Sources

- Qwen Code memory: https://qwenlm.github.io/qwen-code-docs/en/users/features/memory/ (read 2 December 2026)
- Hindsight Coding Agents, Qwen Code entry: https://hindsight.vectorize.io/sdks/integrations/coding-agents (read 2 December 2026)
- Hindsight Coding Agents 0.9.0: https://hindsight.ai/oss/blog/2026/11/30/coding-agents-090 (30 November 2026)


## FAQ

### Does Qwen Code have memory?

Yes, in three layers. QWEN.md files hold instructions you write, and Qwen loads them every session. Auto-memory, on by default, saves notes Qwen writes itself and keeps them private under your home directory. An optional context_search tool searches Mem0 or a local session index only when the model calls it.

### Where do I put QWEN.md?

In ~/.qwen/QWEN.md for every project, in QWEN.md at the project root for the whole team, or in .qwen/QWEN.local.md for you in one project (keep that one out of git). Qwen also reads an AGENTS.md file if the repo has one.

### How do I add Hindsight memory to Qwen Code?

Run npx @vectorize-io/hindsight-coding-agents install qwen-code. It adds native hooks to ~/.qwen/settings.json, plus MCP and a companion skill. Headless runs (qwen -p), serve, SDK and ACP sessions save memory but do not recall it.

