AJAN AÇIKLAMASI Audit agent memory, context files, and skills.
Agent context & memory layers
When to Use
- The user asks whether MD files, skills, or a notes vault hurt performance or cost.
- Memory,
AGENTS.md/CLAUDE.md, or a skill set needs slimming or an audit.
- A memory/context file is at or near its char limit.
- The user wants knowledge kept tool-agnostic so swapping model or CLI does not change
behavior, or questions why a shared context file is named for one vendor.
- A cloned ajan profile behaves oddly or repeats stale facts.
Procedure: optimize one profile without mixing identities
- Establish the authorized profile and read its SOUL.md, USER.md, MEMORY.md, existing workspace guides and only the relevant skills. Inspect each file independently; identical cloned MEMORY.md files do not imply identical USER.md files. Save a scoped rollback copy before editing.
- Assign each item to one owner: SOUL.md = agent identity, behavior, boundaries and the short workspace-entry instruction; USER.md = durable user identity and general preferences; MEMORY.md = verified lasting learnings; AGENTS.md = workspace navigation and rules; skills = task procedures/preferences; vault notes = detailed decisions, sources and project knowledge. Do not put the same role sentence in SOUL.md and MEMORY.md or create a per-agent AGENTS.md merely because the profile exists. Leave MEMORY.md empty if there are no qualifying learnings.
- Move useful details to their destination before trimming. Deduplicate in place; label unverified connection state as last-known rather than current, remove stale executable versions from standing context, and keep historical records intact. A backup preserves history, but is not an active replacement for a necessary working rule.
- Build a thin branch map from existing notes: short agent roles, the owner's vault location and rough contents, and authorized project locations. Read only the relevant branch. Put the entry-reading instruction in SOUL.md when its revision is authorized, not in MEMORY.md as a learned fact. Preserve hard safety boundaries in a reliably loaded layer before removing duplicates.
- Reconcile contradictory directions across the profile and relevant skills: local note saving is not push permission; command examples are not authorization; code belongs outside the notes vault, but README and architecture documentation may live with code. Do not make navigation pointers grant new access rights.
- Verify file contents, memory budgets, destination references and skill frontmatter; compare untouched config and repository state when in scope. Report a concise changed/verified/remaining summary. A fresh-session loading test is separate from file verification; do not claim live adoption from a successful write or a manually read guide.
Procedure: recurring multi-profile context audits
When a user asks for a scheduled audit across agents, make a scoped inventory before creating the job:
- Enumerate only authorized profile roots and named agent-role documents. Exclude secrets, personal backups, transcripts, and any profile/vault belonging to another person before traversal; a request to audit "all agents" does not authorize reading someone else's user memory.
- Verify actual loading behavior for each tool/profile and launch directory. Classify files as auto-loaded, on-demand, or merely stored; do not call every Markdown file "always loaded" or scan every skill body. Inspect a skill only when an identified standing instruction duplicates or conflicts with it.
- Measure standing files separately per profile (characters, with token estimates explicitly approximate) and assign each fact to its correct layer. Do not merge profiles just because their files look alike.
- List existing scheduled jobs before creating a recurring one; keep a context audit distinct from a whole-vault librarian sweep. Make the prompt self-contained, include its scope/exclusions and report path, and read the created job back to verify schedule, delivery, workdir, skills, enabled state, and next run.
- In a scheduled run, apply only reversible, evidence-backed, non-behavior-changing edits to authorized non-protected notes after making a scoped backup. Never delete or move notes. Do not automatically edit protected or always-loaded instruction files, user identity/memory, safety boundaries, permissions, model/provider choices, or role behavior; prepare the exact diff and reason for user approval instead. A cron run cannot ask the user, so leave approval-gated edits pending in its report.
- Report inspected paths, exclusions, measured counts, actual edits and backup paths, proposed diffs, unresolved decisions, and the next run. If scope or authority is unclear, stop that edit and report the boundary rather than widening the scan.
Example job shape: one cron job every few days, workdir = the vault root, delivery origin, skills agent-context-memory-layers + a vault-librarian skill + agent-router, report under a dated audits folder in the vault, backups under ~/.hermes/cache/agent-context-audit-backups/<YYYYMMDD-HHMM>/. Update the existing job rather than creating a second one.
Name the forbidden files, not only the allowed ones. An allow-list prompt still leaks scope: the first run opened a profile's config.yaml "to check the char limit" and had to report it as a scope accident. Spell out that config.yaml and other non-instruction config files are out of scope - and that a profile's char limits cannot be verified from inside such an audit at all.
First: separate the four layers before measuring anything
Most "too many MD files" worries collapse once the layers are split. Only layer A is a
standing cost.
- A. Auto-loaded every session -
SOUL.md, MEMORY.md, USER.md, the skill
name+description listing, and ONE project context file.
- B. On-demand - skill bodies via
skill_view, subdirectory context files injected
into a tool result when the agent touches that directory.
- C. On disk, never auto-loaded - skill bodies, vault notes. A 700k-character vault
and 700k of skill bodies cost nothing at session start.
- D. Conversation history - the layer that actually grows. It is not just chat text:
replayed reasoning blocks, the agent's own tool arguments (whole written files, patches)
and tool outputs all stay in it and are resent on every later call until compression.
Procedure: token spend / context growth / "all chats crashed"
- Triage first:
hermes gateway status, then hermes auth list. Every Anthropic credential
in a 429 countdown means quota exhaustion, not a crash; report the countdown, do not
restart the gateway.
- Measure spend from logs and the fixed prompt:
scripts/token_usage_from_logs.py.
- With the user's permission, find what fills history (read-only, own profiles only), weighting each message by the calls that follow
it:
scripts/context_growth_from_statedb.py. It records sizes and categories only, never message text.
- Propose levers in this order: split oversized skills (proposal to the owner), offload
auxiliary.compression to Sonnet 5/Gemini with a fallback chain instead of running Opus,
lower reasoning_effort on routine profiles, end finished sessions, trim agent output habits.
Watch for server-side cache eviction at 400k+ context (eviction causes 95% redundant reprocessing).
Diagnose the growth source before suggesting threshold/model knobs; this user rejected
lowering the compression threshold as the answer and wanted the cause.
- Write the report to the vault (e.g.
Token Analysis <date>.md) plus one line in the open-tasks note;
change no config without approval.
Details, measured shares and pitfalls: references/token-and-context-growth.md.
Measure layer A in characters and divide by ~4 for a token estimate. Never report a
character count as a token count.
Loading semantics differ per tool - do not generalize
- ajan project context: first match wins, one type per session:
.hermes.md → AGENTS.override.md → AGENTS.md → CLAUDE.md → .cursorrules.
SOUL.md loads separately from HERMES_HOME only. Inside a git repo, AGENTS.md
loads as a merged git-root→cwd chain; outside a repo, cwd only.
- A nested git repo severs the parent chain. When a repo sits under a plain (non-repo)
parent directory, the chain starts at that repo's own root, so a guide in the parent
folder is never loaded from inside the repo. Each repo therefore needs its own root
guide; a workspace-level guide covers only work done at the workspace level. Verify by
resolving the git root from the intended working directory, not by assuming nesting
implies inheritance.
- Test loading and protected-write approval independently. Their filename sets are not identical; do not infer that every auto-loaded file is gated or every ungated file is ignored. Inspect the installed startup loader, subdirectory-hint loader and write guard separately, including configured extra patterns. Never choose an alternative filename to evade a denied write. An ordinary architecture document is not a replacement for an approved agent guide.
- ajan memory does NOT auto-compact. A write past
memory.memory_char_limit /
user_char_limit returns an error, so a full file means the agent can no longer learn
until it frees room itself. A file at 100% is a defect, not a full tank.
- Claude Code reads
AGENTS.md directly (v2.1.277+) ONLY when no CLAUDE.md,
.claude/CLAUDE.md or CLAUDE.local.md exists at or above the cwd; with both present it
reads CLAUDE.md only. So renaming a lone CLAUDE.md to AGENTS.md makes one file serve
ajan, Claude and Codex when their loading conditions are met - verify the installed version and actual session loading. Update live pointers, but preserve historical reports that accurately name the former path.
@path imports in CLAUDE.md do not reduce context cost - imported files load at
launch too. Path-scoped .claude/rules/ is the mechanism that actually saves context.
- Memory is NOT shared between tools. ajan reads
~/.hermes/memories/, Claude reads
~/.claude/projects/<proj>/memory/ plus its CLAUDE.md chain, Codex reads
~/.codex/AGENTS.md. Never tell a user that putting a fact in ajan memory makes other
CLIs know it. The only genuinely shared layer is files on disk: a vault, and a
project-root AGENTS.md. Prefer AGENTS.md over a tool-branded filename so no single
vendor owns the shared contract.
What the evidence says about context files
Two 2026 studies disagree, and the disagreement is the useful part:
- arXiv 2602.11988 - context files did not generally improve task success and raised
inference cost by over 20%; instructions were followed well, repository overviews were
not helpful.
- arXiv 2601.20404 - median runtime −28.64% and median output tokens −16.58% with a root
AGENTS.md, but it evaluated no semantic correctness (sanity check on a sample only).
So "faster" is not "more correct." The operative rule: write instructions and
non-standard conventions; avoid verbose repository tours or restating what the agent can derive. For a branching map, retain one-line project briefs and explicit pointers so the agent can choose a branch without reading every repository. Anthropic's context-engineering guidance points the same way - attention budget
is finite, prefer just-in-time retrieval over upfront loading. RAG is not a prerequisite;
structured notes plus search handle a personal vault fine.
Example: a branching context architecture
- Keep a thin, tool-neutral root at
~/AGENTS.md: short agent-role directory, the notes vault location and rough contents, and GitHub workspace location. Keep full role cards and project details out of this layer.
- Keep connection setup, authentication incidents, installed-model facts, image-worker readiness, and system follow-ups in a vault system-status note (dated evidence) and an open-tasks note (next action / acceptance gate). Load these only for system work; do not carry their changing status in persistent memory. Preserve old evidence as history, and separate CLI login, ajan-native provider, quota, and genuine artifact tests.
- Make the root a need-based signpost, not a reading chain: each line is "if you need X → this one file" (product status → its vault hub note, handing work to another agent → that agent's row in the role table, anything else in the vault → the vault's own read map, media location → media map line). Agents open only the branch the task needs; no file other than SOUL.md and the root is "read first every time". Build the tree like a modular codebase: no hop limit and no note-length limit (a note may be long, like a skill); the test is that a reader reaches what it needs without wading through what it does not, so long notes open with a short summary and headings and push detail down or into child notes. Inner nodes hold pointers with a "when to come here" clause, facts live only in leaf notes, because facts copied into router files are what went stale. Keep ONE map per audience: when a human index (e.g. a start-page note) duplicates the agent map, fold its useful links into the map and retire it to
_to_delete/ rather than maintaining both. <proje-klasoru>/AGENTS.md serves agents that do not own the project; an owner agent carries its own repo path and hub-note path in its SOUL.md. The vault is the main read source; its read map says what lives where and which folders are off-limits, not a repeat of root bans. Each agent's vault write area lives only in its own SOUL.md; the few shared write rules sit in root AGENTS.md. Full principle list: the role-based-agent-orchestration skill's references/flow-and-knowledge-tree.md.
- Treat empty project notes and absent architecture as normal for an unstarted project, not as maintenance defects. Verify project maturity before proposing documentation work; do not invent a stack, force a brief, or populate placeholders merely to make an inventory look complete. When architecture documentation is requested, keep a short repo-local map with the verified the notes vault project path and a concise description of its notes rather than duplicating their content.
- If the user wants it, keep the notes vault entry guide above the vault's Git repository, outside it. Do not introduce push/sync work for context maintenance.
- Make sure every profile actually has the root map in front of it (auto-loaded or pointed to from SOUL.md). A home-level guide is not automatically loaded from every ajan launch directory; file existence or manual reading does not prove automatic ingestion. Test loading per tool and launch environment before claiming universal sharing.
- Revise specialist memories conservatively: preserve unique learned facts, not duplicate identity or startup procedures. Keep role definitions and authorized startup routing in SOUL.md; keep unique user facts in USER.md. Preserve model settings unless explicitly asked to change them.
- Skill ownership: one owner per skill, the master copy lives with the owner. A specialist's craft skill (video, TTS, Android build, web mockup) is owned by that specialist; it edits it, and copies elsewhere (including default's) are refreshed FROM it, never the reverse. If default finds an improvement it sends it to the owner as a proposal instead of writing into the owner's skill. Shared infrastructure skills (
agent-router, incident-escalation, ...) are owned by default. Record it as a sahip: line at the top of the skill; a skill used by two specialists still has one owner, the other proposes. Why: syncing specialists back to a central copy erases what they learned doing the work.
- Ownership metadata on notes: guide, hub and rule notes carry a
sahip: frontmatter line (the agent responsible for keeping it current); dated notes (lessons, reports) do not need it, and an update date is optional. Do not rely on file mtime (touched by sync/usage counters without content change) or git author (every agent commits under the user's identity) for ownership.
- Multi-profile rollout (SOUL/skill/config changes across many profiles): have one child build a no-apply package first (per-profile full SOUL drafts plus
diff -u, a skill operation table with owner/copy/disable/remove, a backup-first apply script, acceptance checks, at most five questions), then get ONE batch approval. Present the protected AGENTS.md rewrites as separate full-file drafts sent to the user, and do the unprotected vault work (role table, system-status block) meanwhile so the gate does not stall the step. Before applying: copy the package out of the pruned scratch dir to a permanent folder, run the script's dry-run, and put the backup outside the cache. If a set -e apply script stops midway (a mid-script check that returns non-zero for a still-incomplete state is a common cause), do NOT rerun it from the top: its backup step would refuse or capture already-changed files. Build a resume script from the header (variables, helpers) plus the remaining steps only, run it, then the acceptance checks. Afterwards ask two changed profiles "who are you, who do you work with, where do you write in the vault" with a one-shot chat; correct answers prove the new SOUL loads.
- Agents know only the agents they work with. Each SOUL.md carries a short "Birlikte çalıştıklarım" list (the agents it routinely hands work to or receives from); the full role table is an on-demand lookup used through
agent-router, not auto-loaded; the root AGENTS.md points to it in one line instead of listing every agent.
- If another person is authorized to use the same agents, keep their notes and entry guide separate from the main user's tree, do not strip their paths or skills during cleanups, and do not route them through the main user's root. Agent-role awareness does not grant another agent access to private notes.
- Distinguish profile separation from security isolation: separate memory, config and bot channels do not sandbox a local terminal. Never describe an access prohibition in Markdown as an OS-enforced boundary.
- Treat
claude auth status as evidence about the invoking process environment only, not proof that another open terminal or desktop session is logged out. Do not open login screens or alter credentials on the user's behalf.
Routing test for any line of knowledge
Ask: is this needed in EVERY session?
- Yes, regardless of task → classify by ownership first: identity/behavior in SOUL.md, user facts in USER.md, learned facts in MEMORY.md, workspace instructions in AGENTS.md. Keep each short; not every always-needed item is memory.
- Only for one kind of work → a skill (loads only when relevant).
- Only when searched → the notes vault.
- Derivable from the code or files → write nothing.
When slimming memory, move first, delete second: write the fact into its destination
skill, prove it landed, and only then shorten the memory entry.
Pitfalls
Only these basenames are auto-loaded as per-directory context, in priority order (first match per dir wins): AGENTS.override.md, AGENTS.md, agents.md, CLAUDE.md, claude.md, .cursorrules (agent/subdirectory_hints.py:_HINT_FILENAMES). A file named ARCHITECTURE.md, README.md or PLAN.md is NEVER auto-loaded - an agent reads it only when told to. So repo-level architecture notes need either a protected-name file or an explicit pointer from a parent AGENTS.md. Verify with list_context_file_sources() from the target cwd before claiming a file loads.
Writes to agents.md, claude.md, soul.md, .cursorrules are approval-gated (tools/file_tools_write_guards.py:_PROTECTED_INSTRUCTION_BASENAMES). The gate fails closed: a config read error keeps it ON. When the approval prompt cannot reach the user, hand them the exact diff or command instead of renaming the file to dodge the gate - a dodged gate also dodges auto-loading, so the write silently loses its purpose.
An AGENTS.md write is an approval-gated protected write. Editing any AGENTS.md prompts the user; a timed-out prompt means NO consent - never retry it through terminal, execute_code or another path. Plan guide edits as single small diffs the user can approve quickly, and apply profile files (SOUL/USER/MEMORY) separately so one pending approval does not block the rest.
Never rename a context file to route around the approval gate. Writing the same
content as ARCHITECTURE.md or any other unprotected name succeeds, but the file then
sits outside the hint-filename list and is never auto-injected - the agent only sees it
if something explicitly reads it. That is a legitimate move for durable documentation,
and a silent failure if presented as equivalent to a guide. When you take it, say in the
same breath that the content is on disk but NOT auto-loading, and name the gated write
still required to make it load. Prove the distinction by resolving context sources from
the target directory instead of assuming the write implies ingestion.
A blocked gated write is a handoff, not a dead end. Produce the exact intended diff
or full file text for the user to apply themselves, and keep the content available in an
unprotected file when that helps - but never let the fallback quietly become the
reported outcome.
Scope a principle the user states mid-project to that project unless they say it is general. A design rule voiced while discussing one product (e.g. "this feature should be plain code, not an agent") belongs in that project's note; promoting it to USER.md or a SOUL draft makes it bind unrelated work, and the user has to walk it back. When the scope is ambiguous, write it to the project note and ask before widening.
Standing context is not the place for project-specific or one-off detail. A specialist only needs project X's rules while doing X; put project facts in that project's note and procedures in a skill, then have the identity point at them. A sentence like "project X keeps a single active timer" loaded on every turn is pure overhead for unrelated visual or content work.
Clearing cloned memories does not shrink standing context by itself. The duplicated role/navigation/safety text usually has to live somewhere that actually loads (SOUL.md), so expect the per-profile total to drop only by the genuine duplication. Measure SOUL+USER+MEMORY together, before and after.
A copied memory file rots silently. hermes profile create --clone copies
memories/MEMORY.md and USER.md on purpose (_CLONE_SUBDIR_FILES in
hermes_cli/profiles.py, verified 2026-10-05) because they are treated as curated
identity. The copy is a frozen snapshot: it keeps naming retired tooling, can contradict
itself across entries, and inherits a full char budget so the clone cannot learn. Audit a
per-profile memory before trusting it, and never treat a clone's content as current.
ajan is itself inconsistent here - profile_distribution.py excludes memories as user
data while clone includes it.
Duplicating a rule across layers is the same rot at smaller scale. Prefer one source
plus pointers ("read <path> before writing") over copying the rule into every file; when
you update one copy the others become wrong. Exception: hard safety prohibitions stay
restated at each layer, because a skill that was never loaded cannot forbid anything.
A changed hard-safety rule (new exception, corrected fact) must be re-propagated to every duplicate, not just the canonical source. Each ajan profile's SOUL.md is a static baked snapshot taken from the root AGENTS.md's identity/security text at profile-creation time - it is NOT a live read, so editing root AGENTS.md alone leaves every already-created profile enforcing the stale rule (a profile will correctly refuse an action the user just explicitly permitted, citing "my fixed security rule," because its own copy never changed). When a hard-safety rule changes: (1) grep every profile's SOUL.md for the exact shared boilerplate sentence to confirm which profiles actually carry the standard template text (grep -rl "<distinctive phrase>" ~/.hermes/profiles/*/SOUL.md); (2) patch that exact sentence in each matching file, plus the root AGENTS.md and any detailed binding doc (e.g. a vault "red lines" file) it points to; (3) explicitly EXCLUDE profiles whose SOUL.md has custom, non-template security text - these are out-of-scope profiles that deliberately do not inherit the shared exception, not an oversight to fix. Verify completion with a post-patch grep across all profiles for the new clause, not by trusting a per-file edit count.
Also fix stale facts you encounter while editing a binding doc, but don't silently drop an unrelated warning in the same edit. A multi-line replacement in a safety/reference file can delete a neighboring sentence that happened to sit in the replaced span (e.g. a "this is the only backup of X" warning next to a correction of a disk partition name) - diff the patch result against the pre-edit content for anything load-bearing that disappeared, not just for the intended change landing.
Check Git scope separately from loading scope. A guide above the repo can intentionally avoid sync conflicts, but that placement neither guarantees automatic loading nor a backup. Verify both separately; do not relocate it into Git against the user's preference.
Do not claim a skill count or vault size hurts performance without measuring layer A -
bodies on disk are free.
Routine curator sweeps cost nothing; the aux-model consolidation pass is opt-in
(curator.consolidate). Do not describe curation as a token expense when it is off.
Keep every skill description under 60 chars; it sits in the system prompt on every call,
unlike the body. Longer descriptions are rejected at creation.
Verification
Before reporting a cleanup as done:
- Re-read each edited file and report before/after character counts against the real limit.
- For every fact removed from memory, grep the skill it moved to and confirm the string is
present. A move is not done until the destination is proven.
- Confirm frontmatter still parses on every touched skill.
- State plainly which files were NOT touched (other profiles, other tools' context files),
so the user is not left guessing the blast radius.
- Distinguish your own edits from changes made by other agents or cron jobs - compare
timestamps before claiming authorship of a dirty working tree.