Maintain a per-repository operational memory file. This skill is mandatory every session.
Activation note: always active, no trigger required. Run Startup (Do First) once at the start of each session before doing any work, then re-read notebook.md immediately before any file edit.
Startup (Do First)
Do not start task work until this checklist is complete:
- •Resolve repository root.
- •Resolve repository name with
basename -s .git $(git remote get-url origin)(fallback to repo directory name if origin is missing). - •If
.agents/notebook.mdexists, run the one-time migration scriptpython3 home/programs/codex/skills/notebook/migrate_notebook.py. - •Set notebook path to
~/.cache/agents/{repository_name}/notebook.md. - •If missing, create it from
Starter Template. - •Read context:
- •Always read
Top Rules,User Preferences, andSession Index. - •Read all
## Logentries before starting task work. - •Read the entire notebook when any
Full-Read Triggerapplies.
- •Always read
- •Run
Session Trackingand updateSession Index. - •While working, log only qualifying events under
## LogusingEntry Format. - •Run
Consolidationwhen thresholds are hit.
Migration script behavior: merges .agents/notebook.md into the cache notebook and removes the repo notebook only after a successful write. Run it only when .agents/notebook.md is present.
Starter Template
Use this exact template when creating ~/.cache/agents/{repository_name}/notebook.md:
# Notebook ## Purpose Track mistakes, failed attempts, user corrections, and what actually worked in this repository. ## Working Agreements - Read this file before starting work. - Add entries continuously while working. - Insert each new log entry under `## Log` so newest entries stay first. - Log your own mistakes, not only user corrections. - Keep entries factual and short. - Consolidate regularly to keep only high-signal guidance. ## Top Rules - <high-signal rule> ## User Preferences - <repeated user preference> ## Session Index - session_count: 1 - session_ids (newest first): - <SESSION_ID> ## Log
Session Tracking
Session contract:
- •
current_session_idis the stable identifier for the active chat/thread session. - •In Codex, use
CODEX_THREAD_ID. - •In non-Codex agents, use that runtime's equivalent conversation/thread/session id variable.
- •The value must stay the same within one session and change when a new session starts.
Session Index is mandatory and stores:
- •
session_count - •
session_ids(newest first), onecurrent_session_idper agent session since last consolidation
At startup:
- •Resolve
current_session_idfrom the runtime session identifier variable (Codex:CODEX_THREAD_ID; others: equivalent variable). - •If
Session Indexis missing, initialize:- •
session_count: 1andsession_ids: [current_session_id]when id exists. - •
session_count: 0and emptysession_idswhen id is unavailable.
- •
- •If id exists and first
session_idsentry differs, prepend id. - •If id is unavailable, do not append anything.
- •Set
session_counttolen(session_ids). - •Do not emit a
session-startlog entry for this bookkeeping.
What to Log
Allowed event types: mistake, failed-attempt, user-correction, working-pattern, consolidation.
- •
mistake: your assumption, implementation, or command was wrong. - •
failed-attempt: approach failed or only partially worked. - •
user-correction: anything the user told you to do differently. - •
working-pattern: non-obvious, high-signal pattern that should be reused. - •
consolidation: notebook cleanup was executed.
Before writing any entry, all three must be true:
- •Novel: not already captured in
Top Rules,User Preferences, or a newer log entry. - •Concrete: tied to a specific command, diff, failure, or decision in this repository.
- •Actionable: changes what you will do differently next time.
If any check fails, skip the entry.
- •Keep
## Login strict descending chronological order. - •Do not log
session-start. - •Log only events that would change future behavior or save time on similar tasks.
- •For
working-pattern, skip obvious wins. If a competent engineer would expect it, do not log it. - •If no qualifying event occurred, do not force an entry.
- •Do not log duplicates already captured in
Top Rules,User Preferences, or a newer log entry. - •Do not log generic writing/process advice unless tied to a concrete failure in this repo.
- •Do not log user corrections that only restate an existing rule without new constraints.
- •Do not delete failures to hide them. Remove old entries only during consolidation after promoting the lesson.
Entry Format
Use this format for every log entry:
### <ISO-8601 timestamp> | <event-type> - Context: <what you were trying to do> - Observation: <what happened> - Action: <what you changed next> - Outcome: <worked, failed, partial> - Follow-up: <how to avoid or repeat this>
Consolidation
Trigger consolidation when either condition is true:
- •Notebook has 400 lines or more.
- •
session_count >= 5.
During consolidation:
- •Merge repeated lessons into
Top Rules. - •Promote repeated user guidance into
User Preferences. - •Remove redundant, low-signal, or superseded entries already captured above.
- •Keep
## Lognewest first. - •Keep notebook under 200 lines after consolidation.
- •Reset
Session Indexto current session only (session_idshas one current id when available) and setsession_countaccordingly.
Practical Defaults
- •Do notebook create/read steps sequentially, not in parallel.
- •Start every session by running
Startup (Do First)and reading the required notebook sections before doing repository work. - •Multiple agents may write the notebook at the same time. Re-read
notebook.mdimmediately before editing and keep writes minimal so concurrent changes are less likely to be clobbered. - •Quote multi-word shell search patterns.
- •Check for duplicate lessons before adding a new log entry.