ctx-memory AGENTS.md

Repository instructions for ctx-memory, a local memory system for coding agents. It stores project history in SQLite with vector search and writes project memory to AGENTS.md so agents can use it in later sessions.

In plain words
What is it for?
Use it when working on ctx-memory or changing its architecture, hooks, wrappers, memory pipeline, or agent integrations. It also records known issues and project-specific conventions.
Why use it?
It reduces the need to repeat past work, decisions, errors, and conventions when starting a new coding session. It also documents how memory is collected and injected for different agents.

Instructions file for CodexOpenCode

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add instructions/ghadisaab/ctx-memory/agents-md
Clone the repo
git clone --depth 1 https://github.com/GhadiSaab/ctx-memory

Made for: Codex, OpenCode.

Per session 2,237 This file is loaded in full into every session.
When invoked 2,237 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.02237 $0.02237
Opus 5 $0.01118 $0.01118
Sonnet 5 $0.00447 $0.00447
Haiku 4.5 $0.00224 $0.00224

Measured 2d ago against content hash 19c3ba7d76b0, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

ctx-memory AGENTS.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

AGENTS.md · 89 lines

How it starts

The opening of the file, as written. The whole thing — 89 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Project Memory (from previous sessions)

Project Memory

Architecture

  • Persistent memory layer for LLM coding agents (Claude Code, Codex, Gemini, OpenCode) backed by SQLite + sqlite-vec, exposed via MCP
  • Three-layer pipeline: Layer 1 (pure message/event processing) → Layer 2 (digest ≤500 tokens) → Layer 3 (project memory markdown merge)
  • Shell wrapper intercepts tool binaries, spawns MCP sidecar (Claude/OpenCode only), runs pipeline on session end
  • Claude: hooks fire live (PostToolUse) + JSONL reader seeds messages post-session
  • Codex: post-hoc only — reads ~/.codex/state_5.sqlite + rollout JSONL after session ends
  • OpenCode: MCP sidecar + AGENTS.md injection at startup
  • AGENTS.md used for context injection for Codex and OpenCode (written before spawning tool)
  • Non-interactive subcommands (update, mcp, login, etc.) bypass wrapper entirely via execFileSync
  • You want OpenClaw (from Discord) to be able to act directly on your local files instead of only replying with paste-ready output. I’m checking your local OpenClaw/GSD setup to see exactly which permission boundary is blocking that and what to change safely.
  • I successfully applied the config-side changes, but openclaw approvals set failed because its CLI syntax is different than expected. I’m switching to directly updating ~/.openclaw/exec-approvals.json, then I’ll verify and restart gateway.
  • Now I have the full picture. Here are all the problems:

  • Problems Found

  • 1. Project12 sessions go to wrong project ("ghadi")

  • Root cause: /home/ghadi is a git repo (has .git/). When you run claude from /home/ghadi/perso/Project12, git rev-parse --show-toplevel walks up and returns /home/ghadi — so the wrapper resolves it to the ghadi project instead of creating a Project12 project.
  • Fix needed in src/wrapper/project.ts: If gitRoot is a parent of cwd (not the same or a direct project root), fall back to using cwd itself.
  • 2. Architecture/decisions never saved in digests

  • Root cause: decisions in Layer 1 only come from:
    • "confirmation" pattern matches with extractedDecision
    • Messages typed as "decision"
  • When Claude announces architecture, it's just an assistant message — Layer 1 never classifies it as a "decision". So decisions: [] always, nothing reaches Layer 3's architecture section.
  • Fix needed: Layer 1 needs to extract decisions from assistant messages that match architecture/decision patterns (e.g. "I'll use...", "The architecture is...", "decided to...").
  • 3. llm-memory projects list didn't show Project12

  • Root cause: Same as #1 — Project12 was never registered. Its sessions went to the ghadi project.
  • 4. No messages captured (0 messages_raw despite JSONL existing)

  • Root cause: The JSONL reader runs at session end and finds the file by mtime >= sessionStartMs. But the current session's JSONL file is still open/being written, so the mtime check may race. Also, 0 messages in DB means seedBuffers with messages never ran (no messages seeded from JSONL).

  • Want me to fix these now? The priority order I'd suggest:
    1. Fix #1 (git root leaking to parent) — affects project isolation completely
    1. Fix #2 (decisions extraction) — affects architecture/memory quality
    1. Fix #4 (messages not seeded) — investigate why JSONL reader returns nothing for recent sessions
  • Now fix tryConfirmation in patterns.ts to extract a meaningful decision sentence instead of dumping the whole assistan…
  • "I'm using" still matches "using " in ARCH_SIGNALS. And "React 19 instead of 18" matches "react". Both are still appeari…
  • Clean! But "I'm using Subagent-Driven Development to build KubeQuest task by task" is in Architecture because it matches…
  • The real fix is to change the entrypoint guard to use import.meta.url instead of VITEST, but actually looking at th…
  • The fix: check if argv[1] ends with wrapper/index.js (the only valid case to run main()), rather than checking fo…

Read the full file on GitHub · 89 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 89 lines · 2,237 tokens per session scan A 19c3ba7d76b0

Subscribe to this mod's changes

ctx-memory AGENTS.md is an instructions file published in the GitHub repository GhadiSaab/ctx-memory (0 stars, last pushed 2mo ago), licensed MIT. It adds 2,237 tokens to every session, about $0.0112 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other instructions, from other repositories

vscode buildNext.instructions.md

Working notes and architecture documentation for the new esbuild-based build system in build/next. Use when making changes to the new build pipeline (transpile/bundle commands, NLS plugin, source-map handling, resource copying, or self-hosting watch tasks).

microsoft/vscode · 6,785 tokens

spec-kit AGENTS.md

AGENTS.md instructions for github/spec-kit, covering agents.md, about spec kit and specify, quickstart — add a new integration in 5 steps, integration architecture and integrationmanifest — file tracking.

github/spec-kit · 7,104 tokens

codex AGENTS.md

AGENTS.md instructions for openai/codex, covering rust/codex-rs, the codex-core crate, code review rules, crate api surface and model visible context.

openai/codex · 5,182 tokens

langchain AGENTS.md

AGENTS.md instructions for langchain-ai/langchain, covering global development guidelines for the langchain monorepo, corridor security analysis, project architecture and context, monorepo structure and development tools & commands.

langchain-ai/langchain · 4,345 tokens

vscode oss-third-party-notices.instructions.md

Instructions for microsoft/vscode, covering vs code oss third-party-notices pipeline, architecture, pipeline flow in ci, applying the notice (cutover) and fallback chain (never fail the build).

microsoft/vscode · 5,001 tokens

next.js AGENTS.md

Instructions for vercel/next.js, covering next.js development guide, codebase structure, monorepo overview, core package: packages/next and other important packages.

vercel/next.js · 7,296 tokens