Agent rules

Agent rules file

The MCP server gives your agent the tools. This file tells it when to use them: search before digging, save what a colleague would want to know.

The rules file

context-vault setup writes MCP config only. It does not install this file, so add it yourself. It is plain markdown, about 60 lines.

agent-rules.md · v1.1
<!-- context-vault-rules v1.1 -->
# Context Vault — Agent Rules

You have access to a persistent knowledge vault via MCP tools (`get_context`, `save_context`, `list_context`, `delete_context`). Use it to build lasting memory across sessions.

## When to Retrieve

Check the vault when you're about to invest effort that past knowledge could shortcut. Apply this test: "Might I or a previous session have encountered this before?" If yes, search first.

Retrieval triggers:
- **Starting a session**: call `get_context(query: "<project or task context>")` to load relevant prior knowledge
- **Hitting an error**: search for the error message or root cause before debugging from scratch
- **Making a decision**: check if this architectural or design choice was already made and why
- **Integrating with an API, library, or service**: search for known quirks, gotchas, or working patterns
- **Entering an unfamiliar area of the codebase**: check for prior insights about that module or domain
- **Before saving**: search to avoid duplicates and to update existing entries instead

A vault search takes milliseconds. Debugging from scratch takes minutes. Always check first.

## When to Save

Save when you encounter something a future session would benefit from knowing. Apply this test: "Would I tell a colleague about this to save them time?" If yes, save it.

Save triggers:
- Solved a non-obvious bug (root cause was not apparent from the error)
- Discovered undocumented API/library/tool behavior
- Found a working integration pattern requiring non-obvious configuration
- Hit a framework limitation and found a workaround
- Made an architectural decision with tradeoffs worth preserving

## When NOT to Save

- Facts derivable from reading the current code or git history
- The fix itself (that belongs in the commit, not the vault)
- Generic programming knowledge you already know
- Session-specific state (files edited, commands run)

## How to Save

Every entry must have:
- `title`: clear, specific (not "auth fix" but "Express 5 raw body parser breaks Stripe webhook verification")
- `tags`: at minimum a `bucket:<project>` tag for scoping
- `kind`: insight, pattern, reference, decision, or event
- `tier`: `working` for active context, `durable` for long-term reference

Capture what was learned (the insight), why it matters (what problem it prevents), and when it applies (what context makes it relevant).

## Session Review

At the end of significant work sessions, review what you learned. If the session produced novel knowledge (not every session does), save 1-3 consolidated entries. Prefer one solid entry over multiple fragments.

What each section does

When to Retrieve
Search before debugging, deciding or integrating. The test: might a past session have seen this?
When to Save
Save non-obvious bugs, undocumented behavior, working integration patterns, workarounds and decisions with tradeoffs.
When NOT to Save
Skip anything derivable from code or git history, the fix itself, generic knowledge and session-only state.
How to Save
Every entry gets a specific title, a bucket tag, a kind and a tier, so it can be found later.
Session Review
At the end of real work, save one to three consolidated entries instead of many fragments.

Install by client

Copy the file above, then put it where your client reads instructions.

Save the rules as ~/.claude/rules/context-vault.md.

shell
mkdir -p ~/.claude/rules
pbpaste > ~/.claude/rules/context-vault.md

The second line is macOS: it writes the text you copied with Copy rules. On other systems, paste into the file with an editor.

Claude Code loads every markdown file in ~/.claude/rules/ at session start. You can also paste the text into a project CLAUDE.md.

Any other MCP client: paste the text into its system prompt or agent instructions.

Edit it

Nothing rewrites the file after you save it, so change it freely: add save triggers for your own modules, narrow the retrieval triggers, add things not to save. To remove it, delete the file.