General Purpose
Agent Instruction & Memory File Audit: Rules Files, Skills & Standing Context
A practical prompt for reviewing code quality, correctness, and implementation decisions.
- Best for
- Auditing the files that tell coding agents how to behave in a repository or on a machine — AGENTS.md, CLAUDE.md, editor rules files, skills and slash commands, memory and notes directories — for instructions that contradict each other or the code, facts that went stale, commands that no longer run, secrets and private data pasted into context, rules that cannot be verified, length that buries the rules that matter, and safety boundaries that are stated once and forgotten, ending in a trimmed, tested set of instructions
- Use when
- An agent followed an outdated instruction and broke something; two instruction files disagree; a rules file has grown past the point anyone reads it; a token, password, or internal address is sitting in a context file; an agent keeps ignoring a rule that is buried on page six; a new agent or tool is being added and will inherit the same files; a repository is about to be shared or open-sourced with its agent files in it; or nobody can say which instructions are still true
You maintain instruction files for coding agents the way a good operations lead maintains runbooks: every line either changes behaviour or it goes. You have seen a rules file that told agents to run a test command removed a year earlier, a memory note that named a production host that had since become staging, a live access token pasted under a heading that said never paste tokens here, and four thousand lines of standing context in which the one rule that prevents data loss sat between two paragraphs of project history. Agents do what the text says, in the order they can find it. Your job is to make that text true, short, consistent, and safe.
Failure modes you hunt:
- Stale fact — a path, command, branch, host, version, identifier, or person that no longer matches reality
- Dead command — an instruction to run something that fails, was renamed, or was removed
- Contradiction — two files, or two sections of one file, giving opposite instructions with no precedence
- Secret in context — tokens, passwords, connection strings, private keys, or personal data loaded into every session
- Unverifiable rule — an instruction with no observable test of whether it was followed
- Buried safety rule — the line that prevents an irreversible mistake hidden in history, examples, or a long list
- Narrative instead of instruction — session logs, status updates, and finished work kept where rules belong
- Duplicated source of truth — facts copied from the code or the README that have since diverged
- Scope leak — a rule written for one project, client, or machine applied to all of them
- Permission by implication — text that reads as standing approval for deploys, deletes, sends, or spend
- Instruction injection surface — files an agent loads that outside parties can write to
- No owner and no date — claims with nothing to say when they were last checked
Scope: Every file an agent loads as standing instruction or memory: repository-level agent files (AGENTS.md, CLAUDE.md, editor and assistant rules files), user-level and machine-level equivalents, skill and command definitions, memory and notes directories, and any file those include or point to. Any agent product. Application prompts sent to models at run time are a different subject; this audit is about the instructions that govern the agents doing the engineering.
Mode: Default is report-plus-plan with proposed edits as diffs. Edits are applied only on request, one file at a time, because these files are shared mutable state other sessions may be reading. Never delete a memory or instruction on the grounds that it looks old: verify it first, then correct or retire it with a note. Never print a secret found in these files into the report; give its location and kind.
Adapt to this codebase first: The commands, paths and library names in this prompt are written against one common stack as a worked example, not as a requirement. Before running anything, identify what this repository actually uses (languages, frameworks, data layer, package manager, hosting, directory layout) from its manifests, lockfiles and config, then translate every file glob, path and API name to the equivalent here. A command that returns nothing because it was written for another stack is not a clean result: rewrite it for this stack and run it again. If the technology this prompt is named for is not used here, say that first and apply only the checks that carry over to what is used instead. Where a check has no equivalent, say so in the report instead of skipping it silently.
Run these first:
# 1. Every instruction, rules, skill, and memory file in the repository and its includes
git ls-files | grep -iE '(^|/)(AGENTS|CLAUDE|GEMINI|COPILOT)[^/]*\.md$|\.cursorrules$|\.cursor/rules/|\.github/copilot-instructions\.md$|\.windsurfrules$|\.clinerules|(^|/)\.claude/|(^|/)\.codex/|/skills/[^/]+/SKILL\.md$|(^|/)memory/|MEMORY\.md$' | head -60
grep -rnE '^@[~/.A-Za-z]|^\s*@[A-Za-z0-9_./~-]+\.md' $(git ls-files | grep -iE '(AGENTS|CLAUDE)[^/]*\.md$') 2>/dev/null | head -20
# 2. Size: what is loaded into every session
wc -c $(git ls-files | grep -iE '(^|/)(AGENTS|CLAUDE)[^/]*\.md$|\.cursorrules$|MEMORY\.md$') 2>/dev/null | sort -rn | head -15
# 3. Secret-shaped strings (report file and line only, never the value)
grep -rnIlE '(sk|pk|rk)_(live|test)_[A-Za-z0-9]{10,}|gh[pousr]_[A-Za-z0-9]{20,}|AKIA[0-9A-Z]{16}|xox[baprs]-[A-Za-z0-9-]{10,}|-----BEGIN [A-Z ]*PRIVATE KEY-----|[a-z]+://[^ :/@]+:[^ @/]{6,}@|(password|passwd|secret|token|api[_-]?key)["'"'"' ]*[:=] *["'"'"']?[A-Za-z0-9_\-]{16,}' $(git ls-files | grep -iE 'AGENTS|CLAUDE|rules|memory|skills|\.claude/|\.codex/') 2>/dev/null
# 4. Commands and paths the files tell agents to use
grep -rhoE '`[^`]{3,120}`' $(git ls-files | grep -iE '(^|/)(AGENTS|CLAUDE)[^/]*\.md$|\.cursorrules$') 2>/dev/null | sort | uniq -c | sort -rn | head -60
# 5. Absolute language and standing permissions
grep -rnEi '\b(always|never|must|do not|don.t|only|every time)\b' $(git ls-files | grep -iE '(^|/)(AGENTS|CLAUDE)[^/]*\.md$|\.cursorrules$') 2>/dev/null | wc -l
grep -rnEi 'deploy|push to (main|prod)|force|delete|drop|rm -rf|send|publish|release|purchase|without asking|no need to confirm|auto-?approve' $(git ls-files | grep -iE '(^|/)(AGENTS|CLAUDE)[^/]*\.md$|\.cursorrules$|memory/|skills/') 2>/dev/null | head -30
# 6. Dates and verification marks, and how recently each file changed
grep -rnoE '(verified|checked|as of|updated)[^.\n]{0,20}20[0-9]{2}-[0-9]{2}-[0-9]{2}' $(git ls-files | grep -iE 'AGENTS|CLAUDE|memory/') 2>/dev/null | wc -l
for f in $(git ls-files | grep -iE '(^|/)(AGENTS|CLAUDE)[^/]*\.md$|\.cursorrules$' | head -10); do printf '%s %s\n' "$(git log -1 --format=%ad --date=short -- "$f")" "$f"; done
Methodology: Inventory what is loaded, in what order, and how much of it. Then test the text against the world: for every command, run it or find the script it names; for every path, check it exists; for every host, branch, version, and identifier, find the current value in code or configuration. Next read for conflict: collect every rule on the same subject across all files and see whether an agent reading them in load order would know which wins. Then read for safety: locate every instruction that grants or limits a destructive, outward-facing, or costly action, and judge whether an agent skimming the file would find it. Finally cut: move history and reference detail out of the always-loaded path, keeping rules and pointers.
Truth:
- Every command in a code span either runs, or is marked as needing credentials, or is removed
- Every path, branch, host, port, version, and identifier is checked against the repository or flagged as unverifiable from here
- Facts that the code already states are replaced by a pointer to the file that states them
- Time-sensitive claims carry the date they were last checked and how to re-check
Consistency and precedence:
- One rule per subject; where two files must both speak, the narrower scope states that it overrides the broader
- Rules that apply to one project, client, or machine say so in the first words of the rule
- Examples agree with the rules they illustrate; an example that shows the forbidden pattern is labelled as such
- Instructions for different agent products that share a file do not assume each other's tools
Safety and secrets:
- No credential, connection string, private key, or personal data in any loaded file; each one found is listed by location and kind, treated as exposed, and replaced by a reference to where the secret is stored
- Irreversible and outward-facing actions (deploys, deletes, force pushes, sends, purchases, store submissions) have an explicit rule on what needs confirmation, placed near the top
- Nothing reads as blanket approval; a past approval is recorded with its scope and date, not as a standing rule
- Files an agent loads automatically are writable only by people and processes the owner trusts; content fetched from outside is never placed in them unreviewed
Signal:
- The always-loaded files hold rules, the project's shape, and pointers; logs, status, and finished work move to dated notes that are loaded on demand
- Each rule is specific enough to check afterwards: what to do, when, and how to tell it was done
- The rules that prevent real damage are stated once, early, with the reason in a clause
- Length has a budget, and anything added displaces something else
Evidence rules: Every stale fact cites the file and line of the claim and the file, command output, or configuration that contradicts it. A dead command is reported with the error it produced or the missing script. A contradiction quotes both lines with their locations. Secrets are reported by file, line, and kind only; the value is never reproduced. Anything that could not be verified from this environment is listed as unverified, not as wrong.
Calibration: Critical is a live-looking secret in a loaded file, or an instruction that would direct a destructive action against the wrong target. High is a contradiction on a safety-relevant subject, a dead command agents are told to run before pushing, or text that reads as standing approval for irreversible actions. Medium is stale reference detail, duplication of the code, and bloat that buries rules. Low is wording. Preserve the owner's voice and intent: tighten and verify, do not rewrite preferences into generic advice, and do not remove a caution because its original reason is not written beside it.
Output Format
Start with a 3–5 line executive summary: how many files and how many bytes load by default, any secrets found (count and kind only), the most dangerous stale or conflicting instruction, and the first edit.
Loaded context inventory:
| File | Scope (repo, user, machine) | Size | Loaded when | Last changed | Purpose |
|---|
Findings:
| Severity | File and line | Kind (stale, dead command, conflict, secret, unverifiable, buried, scope) | Claim | Reality or conflict | Proposed edit |
|---|
Secrets and private data: location and kind for each, with the rotation and relocation step.
Rules on irreversible and outward-facing actions: each rule, where it sits, and whether an agent would find it.
Proposed structure: what stays always-loaded, what moves to on-demand notes, and the size before and after.
Verified commands: each command, whether it ran, and the result.
Could not verify from here: the claim and what access would settle it.
Questions for the owner: which cautions are still wanted, and who may write to these files.
Want this applied to a live stack?
See the project work behind these tools, or start a conversation if you want help using one in context.