This week's feed treated Karpathy's LLM wiki gist like a finished product. Drop-in repos. "Paste this markdown file into Claude Code." A circulating count of more than a thousand GitHub repositories that name the idea, with dozens added this month alone.
One of the more useful posts, after actually running a popular Claude Code memory vault, said the quiet part: each new session starts without your notes unless you hand them over.
That is the whole problem. A gist, an AGENTS.md pointer, a "second brain" repo you clone in a minute — those are instructions. They are not memory. The model does not arrive with your weather-hold policy, or yesterday's decision, or the page you told it not to touch. The window is empty. If you do not pack the wiki into the session, the session will improvise.
So this post is a ~570-line, stdlib-only Python script called session_pack.py. You give it a Markdown wiki and a task. It scores pages with lexical overlap, a phrase bonus, and a light boost along [[wiki-links]]. It down-weights words that appear on almost every page, so a query about a "hold" does not drag in the galley menu. It respects a character budget. It refuses to pack pages marked restricted, draft, stale, or pack: false. It never modifies the wiki. Seventeen tests pin that down.
A pack is not a dump
The failure mode I keep seeing is "stuff the vault in the prompt." That works until the vault has a draft incident report and a passenger manifest in it, or until the context window is already doing real work.
A session pack is smaller and stricter.
- It is built for one query, not for the whole wiki.
- The character budget applies to the page excerpts the model will read. The audit list at the bottom is for you.
- Pages below a minimum score stay out. The default floor is 2.0.
- Restricted, draft, stale, and
pack: falsepages can still match the query. They are listed under "Excluded (not packed)" and their body never appears in the pack. - The packer will not write
SESSION.mdinside the wiki directory. The brief is an input to the session, not a new wiki page.
Core of session_pack.py (scoring, exclusions, and the budget)
RESTRICTED = frozenset({"restricted", "confidential", "secret", "private"})
DRAFT_STATUS = frozenset({"draft", "wip", "unpublished", "review"})
def exclusion_reasons(self) -> list[str]:
reasons = []
if self.meta.get("pack") in (False,) or str(self.meta.get("pack")).lower() in FALSEY:
reasons.append("pack: false")
if self.sensitivity in RESTRICTED:
reasons.append(f"sensitivity: {self.sensitivity}")
if self.status in DRAFT_STATUS:
reasons.append(f"status: {self.status}")
if self.meta.get("stale") is True:
reasons.append("stale: true")
return reasons
def term_weights(pages, query):
n = max(len(pages), 1)
weights = {}
for term in query:
df = sum(1 for page in pages if term in set(tokens(page.title + "\n" + page.body)))
# Common vault words such as "hold" keep a little weight;
# rare terms such as "southerly" keep most of theirs.
weights[term] = 0.25 + 0.75 * (1.0 - df / n)
return weights
# Page score = weighted overlap in title, headings, tags, and body,
# plus a bonus when a query bigram appears, plus 0.35 * source score
# for each [[wiki-link]] from a page that already scored.
# build_pack then takes pages at or above min_score, formats an excerpt
# from the best-matching paragraphs, and fills the character budget
# in score order. Leftovers are listed as "Dropped for budget."
The scoring is deliberately boring. It is the same idea as ranking a small wiki by links and words rather than standing up a vector database: enough to pick the right handful of pages, cheap enough to run in a hook when a session starts.
The sample vault
The fixture in this post is made up: a fictional passenger ferry operator I called Sable Ferry, running Gray's Point to Loon Island. These pages are not a real timetable or a real safety file.
The clean version has twelve Markdown pages under wiki/.
-
weather-hold-policy.md— when a sailing is held, who decides, and what 35-knot southerly gusts on the 19:10 actually mean -
crew-rest-rules.md— a late hold can force you to cancel the last return -
ticketing-refunds.md— refund or rebook once the hold is posted; no invented goodwill -
radio-channel-plan.mdandafter-hours-on-call.md— how the hold is announced, and who to call after 18:00 -
tidal-windows.md— a low tide at Gray's Point can stack with the weather - four low-signal pages: brand voice, the fall galley menu, docking lines, and a December refit of the Coriander
- two pages that must never enter a session:
passenger-manifest-handling.md(pack: false,sensitivity: restricted) andunpublished-incident-2026-10.md(status: draft, restricted). The draft is awkward on purpose. It is about a 19:10 sailing in 35-knot southerly gusts, so a naive search would put it at the top of the pack.
Running it on the evening-sailing question
The question I asked was the one a duty officer would actually type.
$ python3 session_pack.py pack fixture/wiki \
--query "Should we hold the 19:10 sailing if southerly gusts are 35 knots?" \
--out SESSION.md
The header and the first excerpt came back like this. The rest of the pack is the same shape.
# Session pack
- generated: 2026-11-26T06:21:37Z
- query: Should we hold the 19:10 sailing if southerly gusts are 35 knots?
- wiki: fixture/wiki
- budget: 3560 / 8000 chars
- pages: 6 included, 1 excluded, 0 dropped (budget)
## Weather hold policy
- path: weather-hold-policy.md
- score: 16.3
- tags: operations, safety, weather
- sustained wind 30 knots or more, or gusts 40 knots or more, on the exposed
southerly fetch
- significant wave height at the mid-channel buoy at or above 1.5 m
- visibility under half a mile in rain or spray
Southerly gusts in the mid-30s on the evening sailing sit in a narrower band:
the Loon Island approach is beam-on in a southerly, and the 19:10 departure
often meets a falling tide. Treat 35-knot southerly gusts as a captain's call
that should be made no later than 40 minutes before departure, and record the
decision on the ops channel.
Three things I care about in that report.
The excerpt does not start at the top of the policy. It starts at the band that matches the query: mid-30s southerlies, the 19:10, a captain's call no later than 40 minutes before departure. The hard 30 / 40 knot rule is still in the pack, immediately above it. That is the page the model should read first.
The other five included pages are consequences and caveats, not a second copy of the policy. Crew rest says you may also have to cancel the last return. Ticketing says what happens to the passengers. After-hours and the radio plan say who to tell, because 19:10 is after 18:00. Tidal windows, at a much lower score of 2.5, still clears the floor: a falling tide at Gray's Point can stack with the wind. The galley menu, the brand-voice note, and the Coriander refit all scored under 1.0 and stayed out.
And the page that would have been second — the unpublished October near-miss, which scores 14.1 against this exact query — is not in the pack. It is listed at the bottom:
## Excluded (not packed)
- unpublished-incident-2026-10.md (sensitivity: restricted, status: draft)
The body of that draft never appears. A session that "just greps the vault" would have handed the model an unreviewed near-miss and invited it to treat the draft as policy. The packer tells you the page exists and that it was held back. A human can open it. The agent, unless you explicitly say so, should not.
The budget is a knife, not a suggestion
Eight thousand characters was enough for all six relevant pages. Tightening it is how you see the dropped list.
$ python3 session_pack.py pack fixture/wiki \
--query "Should we hold the 19:10 sailing if southerly gusts are 35 knots?" \
--budget 1800 --out SESSION-tight.md
- budget: 1725 / 1800 chars
- pages: 3 included, 1 excluded, 3 dropped (budget)
## Dropped for budget
- after-hours-on-call.md (score 5.2; would need 427 more chars)
- radio-channel-plan.md (score 5.2; would need 441 more chars)
- tidal-windows.md (score 2.5; would need 493 more chars)
The policy, the refunds, and the rest rules still fit. The on-call roster, the radio plan, and the tidal caveat do not. That is the right failure: the pack stays inside the budget, and it tells you what it did not have room for. If the session needs the tide table, you widen the budget or pack a second time with a narrower query. You do not silently truncate the one page that would have changed the decision.
Restricted means not in the prompt
The draft incident is the dramatic case because it matches the weather query so well. The quieter case is a page whose job is the query, and which still must not be packed.
$ python3 session_pack.py pack fixture/wiki \
--query "export the passenger manifest after a weather hold"
- pages: 8 included, 2 excluded, 0 dropped (budget)
## Excluded (not packed)
- passenger-manifest-handling.md (pack: false, sensitivity: restricted)
- unpublished-incident-2026-10.md (sensitivity: restricted, status: draft)
passenger-manifest-handling.md is the page that explains how to export a manifest. It is also marked pack: false and restricted, because it describes where the CSV lives and says not to paste passenger names into chat or an agent session. A retrieval system that only optimizes for relevance would have put it first. The packer lists it as excluded and fills the brief with the hold policy and the refund rules instead — the part of the question an agent is allowed to help with.
That is the difference between "the model can find it" and "the model should see it in this session."
Put the pack in AGENTS.md, not in the harness's memory
A reply I liked in this week's thread said to add an LLM wiki to AGENTS.md, because current models follow that file better than they follow harness memory. I agree, as far as it goes. The file is a pointer. It is not the pack.
session_pack.py agents-snippet prints a paragraph you can paste:
# Wiki session pack
At the start of every session, read `SESSION.md` if it exists in the
working tree. Treat packed pages as the first source of answers and cite
them by path. If `SESSION.md` is missing, stale, or does not cover the
task, run:
python3 session_pack.py pack wiki/ --query "<the user task>" --out SESSION.md
Do not invent policy from memory. Do not read pages listed under
"Excluded (not packed)" unless a human explicitly asks you to. If the pack
omitted a page for budget, ask before widening the budget.
Hook the packer itself in whatever starts the session: a shell alias, a git hook, a small wrapper around your coding agent. status will tell you what an existing SESSION.md was built for, so you can notice when you are about to answer a new question with last hour's brief.
Where this belongs
A Markdown folder and a script are enough for one person's wiki. That is how most of the drop-in repos are shaped, and it is close to how people already do personal knowledge management: a vault of pages, a query, a handful of notes worth loading before you think. The packer is the missing step between "I have a vault" and "this session can see it."
On a team, "do not pack the manifest" should be a property of the page, not a convention in a script the intern forgot to run. You want knowledge base software that can keep operational pages searchable and keep restricted pages out of an agent context without anyone rewriting a frontmatter convention. The same need shows up when people compare an Obsidian alternative or a Notion AI alternative: the product is not the memory. The session is still empty until something selects, budgets, and withholds.
If you can run that workspace yourself — the thing people usually mean when they look for an open source Notion — the exclusion rules stay yours. That is the difference between a chat that was handed a zip of Markdown and AI knowledge base software that treats "what may enter the prompt" as part of the knowledge base.
What it does badly (on purpose)
Lexical scoring is not understanding. A page that talks about "cancelling the last boat" without saying "hold" or "19:10" will underscore. A page that repeats "weather hold" in a disclaimer can still sneak over a low floor. The IDF weighting is there to blunt the second case, not to eliminate it. If a miss matters, tighten the query or raise --min-score.
Excerpts can start mid-page. The packer prefers the paragraphs that match the query. That is why the weather policy opens on the knot thresholds and the 35-knot band, not on "the duty captain decides." Usually that is what you want. Sometimes the skipped preamble had a scope limit you needed. If you see that happen, raise --excerpt.
The audit list names excluded paths. I want a human to know that a matching draft was held back. On a vault where the path itself is sensitive, that list is already a leak. Do not run this in a log that leaves your machine if the filenames are the secret.
It will not refresh a stale pack for you. status reports what was generated. It does not watch the wiki or the clock. A session that keeps last night's SESSION.md will answer tonight's question with last night's pages.
It will not scale to a dump of everything you have ever written. Twelve pages is vault scale. Past a few thousand you still want a budget, a score floor, and an exclusion list — especially the exclusion list — but you may want a real index behind the scorer. The product is the brief, not the walker.
Try it: point session_pack.py at a Markdown export of your own wiki, ask it the question you were about to paste into an empty agent session, and read the excluded list before you hand the pack over. In the Sable Ferry fixture, the useful part was not that it found the weather policy. It was that the draft with the same numbers stayed out.



Top comments (11)
How do you detect when a packed decision has gone stale or conflicts with newer repository instructions?
Good question — this is where a packed decision quietly becomes a liability. The mechanism I'd use is provenance on every packed item: record the source file paths and the commit it was derived from, plus a hash of the source text. On load, re-hash: if the source changed, the decision is marked stale and surfaces for review instead of being silently trusted. For conflicts, never let last-writer-wins decide — when a newer instruction contradicts a packed decision, surface both with their timestamps and let the human pick, because the conflict itself is information. I run a similar rule in a bot-management app I built (BotRoster): anything high-stakes or stale requires explicit re-approval rather than auto-applying. The pack is a cache of decisions, and caches need invalidation — otherwise you're just trusting an old snapshot of the repo.
Thanks for the detail on tracking source file paths, commit hashes, and explicit human conflict resolution rather than letting stale packed decisions auto-apply, I'm building AI Lint as an in-repo pre-flight checklist and doctrine pack where architectural rules live directly in the repository and any conflict requires an explicit documented override with reason, risk, and mitigation: ai-lint.dosaygo.com/go/forum-20261...
That override record is the piece most doctrine packs skip — reason, risk and mitigation, all documented, makes the pack auditable later instead of just obeyed now. One check worth running early: pack a rule, change the source file it was derived from, and confirm the pack flags it stale before any decision from it applies. If a stale rule can still auto-apply once, the provenance is decoration. Happy to try the flow against a small repo of mine and tell you where it bites, if a second pair of eyes helps.
Thanks, Kamal. Changing the source after packing is a good test of whether stale decisions can slip through. We build AI Lint as a checklist, doctrine and rejects catalog for coding agents; I cannot claim it automatically detects stale packed rules. If you try it on a small repo, I would welcome what you find: ai-lint.dosaygo.com/go/forum-20261...
Thanks for the honest scope statement — saying plainly that AI Lint can't claim to auto-detect stale packed rules is exactly what makes a doctrine pack trustworthy: it tells the user where the automation ends and their judgment begins.
I'll take you up on the trial. I'll run it over a small repo of mine (pdf-slice, a Python CLI with a handful of real rules about extraction behaviour) and report back here what it flags — and, more usefully, what it misses. The sharpest test is the one you named: change a source file after packing and see whether the pack flags the rule stale before any decision applies. If it does, that's the falsifiable check the pack needs; if it doesn't, that's a concrete gap to work on.
One question while I'm at it: does the rejects catalog record why a rule was rejected, or just that it was? The reason is what stops the next agent from re-proposing it.
Thanks for testing the stale-source case, Kamal. Yes: the AI Lint rejects catalog describes the rejected pattern and why it causes problems; for example, the parallel-solutions reject explains how implementations can disagree on edge cases. I build AI Lint as a checklist, doctrine and rejects pack, and it does not automatically detect stale packed rules: ai-lint.dosaygo.com/go/forum-20261...
That answers it — and the 'why' is the load-bearing part. A reject that records only the pattern gets re-proposed by the next agent that hasn't seen the failure; a reject that records why the pattern breaks becomes a check the next session can actually run. The parallel-solutions example is a good one: 'implementations can disagree on edge cases' is a reason you can test against, not just a rule you obey. Noted on stale detection — since the pack states that limit plainly, the stale-source test is mine to run by hand: pack the pdf-slice rules, change a source file those rules describe, and see whether anything flags the mismatch before a decision applies. I'll report which of the two outcomes I get, with the rule that went stale as the example.
Thanks, Kamal. The specific stale rule and source change will make the result useful either way. I would be interested in where the mismatch first becomes visible during your run, including if it only comes up through manual review.
Will do — I'll pack the pdf-slice rules, change a source file one of them describes, and report back here where the mismatch first shows up: whether the pack flags it stale on its own, or only when I go looking for it by hand. That's the exact line I want to pin down — the test is only useful if it tells us which side of it we're on.
This is the right shape — a pack built for one query, with a floor and an audit list, is very different from stuffing the vault in the prompt. Two things I'd measure before trusting it. First, the "Excluded (not packed)" list leaks titles: a restricted page still tells the model the page exists, and for a passenger manifest or an incident report the title alone is the sensitive part. I'd redact excluded titles from the audit list, or drop them from it entirely — the audit is for you, but it travels in the same session.
Second, the 2.0 floor is a guess until you measure the pack's hit rate: over ~10 sessions, what fraction of packed pages actually get referenced? If half the pack is never read, the floor is too low; if a page you needed keeps missing, the scoring is wrong. Same with staleness — a policy from six months ago packs with the same weight as yesterday's decision, and there's no "last reviewed" decay. I run into the same tiering problem managing a team of AI bots (read-only auto-run, send/pay/delete approved): the question is never just "what goes in", it's "what can the packed content do once it's in".