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

4 min read

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.

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.

LayerWho writes itLoaded
QWEN.mdYou or your teamEvery session
Auto-memoryQwen, from what you tell itEvery session, as a MEMORY.md index by default
context_search toolMem0 or a local indexOnly when the model calls it

Where QWEN.md goes

FileApplies toShared?
~/.qwen/QWEN.mdYou, in all your projectsNo
QWEN.md in the project rootThe whole teamYes, commit it
.qwen/QWEN.local.mdYou, in this project onlyNo, 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.

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, Claude Code memory and OpenCode memory.

Sources