context-paging
Skill7 starsChanged 4 days agoMITView on GitHub
Context paging, page out, page in, offload context, rolling context window, recover compacted history. Keep exact context recoverable in a per-project SQLite database instead of losing it to compaction or session end; per-project harness hooks capture the full conversation. Nothing is summarized.
In this repository22 other files it gives its agents.
- AGENTS.mdAGENTS.md
- audit-and-resolveSkill
- coordinate-workSkill
- design-skillSkill
- design-time-triggered-skillSkill
- design-validationSkill
- diagnose-and-repairSkill
- indefinite-loopSkill
- install-dev-skillsSkill
- operate-workflowSkill
- polish-docsSkill
- run-experimentSkill
- contract-disciplineSkill
- documentation-styleSkill
- evidence-disciplineSkill
- git-disciplineSkill
- scratch-spaceSkill
- testing-doctrineSkill
- context-compaction-procedureSkill
- maintain-scratchSkill
- refine-skillSkill
- security-hygiene-checkSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 52
Add /agents/context-paging/ to the project .gitignore.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Context paging
Opt-in rolling context, modeled on the Pi context-paging extension: the full record lives on disk, the working window stays small, and recovery returns exact text. Page exact content out to the project database before compaction or session end removes it; page it back in by search when a detail from earlier work is needed. Never store paraphrases — recovery must return exact content.
Store
SQLite at <project>/agents/context-paging/context.db (CP_DB overrides); keep /agents/context-paging/ gitignored next to /agents/tmp/. Any script auto-creates the schema. Tables: sessions; messages (captured conversation, foreign key to session; role is the entry type — user, thinking, assistant, tool_call, tool, system for harness reminders, triggered inputs, and task notifications); topics and tags (session-scoped); pages (curated context units, foreign keys to session and topic); page_tags. The subscription registry ${XDG_CONFIG_HOME:-~/.config}/context-paging/projects.json maps project roots to database and script paths; it is the only thing harness hooks check.
Scripts (scripts/, one operation each; env supplies defaults)
| Script | Operation | Arguments |
cp_session_start.py | get-or-create session, mark active | [session_key] |
cp_session_end.py | mark session ended | [session_key] |
cp_session_list.py | sessions with counts | — |
cp_session_delete.py | delete session; rows cascade | SESSION_KEY |
cp_topic.py | get-or-create topic | [name] (CP_TOPIC) |
cp_topic_list.py | topics with page counts | — |
cp_page_out.py | store a page of exact context | content|- [topic] [tag ...], --kind note|decision|summary|reference|error |
cp_page_in.py | reload pages: recent, matching, or by id (--id never time-filtered) | [query] --id N --all --full --limit N --since DUR |
cp_page_update.py | replace page content, id stable | id content|- |
cp_page_delete.py | delete page | id |
cp_tag.py | attach tag to page | page_id tag |
cp_message_add.py | capture a message row | role content|- |
cp_message_list.py | list or filter messages chronologically | [query] [limit] --since DUR --role R,R |
cp_search.py | chronological project-wide recovery search; compact references with per-role counts | query --since DUR --offset N --role R,R |
cp_around.py | browse messages around an id, in order | message_id [count] --full |
cp_cleanup.py | prune ended/stale sessions when due (>24h) | --days N --stale-days N --force |
cp_init.py | create the schema only | — |
cp_subscribe.py | subscribe a project to harness capture | [project_dir] |
cp_unsubscribe.py | unsubscribe; database kept | [project_dir] |
cp_subscribed.py | gate: exit 0 iff subscribed | [project_dir] |
CP_SESSION names the current session (else manual); CP_TOPIC and CP_TAGS (comma-separated) supply defaults, so cp_page_out.py "<exact content>" is a complete call. A - content argument reads stdin. Read lookups (cp_search.py, cp_message_list.py, cp_page_in.py listings) default to the past hour, order oldest-first, and open with a compact [filters: …] line stating what was applied; widen with --since 30m|24h|7d|any. Every result line names its role, cp_search.py adds a [matches: …] line counting hits per role (and per page kind), and --role R,R retargets messages to specific roles — search broad first, read the counts, then narrow to the type that matters. Empty windowed results name how many matches lie beyond the window; exact loads (--id N, cp_around.py) are never time-filtered.
Working discipline
- Page out exact, durable material as it is produced: decisions with rationale, file paths from long investigations, error text, large tool outputs worth keeping. One page per unit; the topic and tags name it for later retrieval.
- Search returns compact references — ids and excerpts, never full contents — windowed to the past hour by default, with
--sincewidening and--offsetpaging through further matches. Follow a hit withcp_around.py <message_id>to read it with its neighbors in order (--fullfor whole contents) orcp_page_in.py --id Nfor a full page, so minimal data enters the context until detail is needed. Page in when resuming (cp_page_in.py --all) or when a previously known detail is missing after compaction. When you author a compaction statement, follow context-compaction-procedure instead of the harness template. - Messages are capture, pages are curation: hooks record the conversation verbatim — user prompts, agent thinking, replies, tool calls and results; record your own summaries and decisions as pages.
Install into a project
- The skill folder installs with the library (install-dev-skills);
scripts/stays inside it. - Add
/agents/context-paging/to the project.gitignore. - Insert the harness opt-in section below into the project
AGENTS.md. - Execute that section now rather than deferring: skip on an existing subscription or recorded decline; otherwise ask whether to install the harness plugin, and on yes complete the harness wiring for your host — references/kimi-hooks.md or references/codex-hooks.md — code the hook dispatcher, register the hook rules, then run
cp_subscribe.pylast, so subscribed means installed and verified. A no writes the decline variable; any other answer defers to the section's next-session check. - Manual use needs no harness wiring; the scripts run directly.
Harness opt-in section (insert verbatim)
Context paging harness opt-in
The context-paging skill keeps this project's exact context recoverable in
agents/context-paging/context.db(gitignored). Harness capture is per-project opt-in and only runs for subscribed projects. Once per session, before substantive work, check in order and stop at the first that holds:
- Already installed and activated:
scripts/cp_subscribed.pyfrom the context-paging skill exits 0 for this project. Skip silently.- Declined:
agents/tmp/context-paging.jsoncontains{"harness_install": "declined"}. Skip silently.- Otherwise ask the user: "Install context paging in your harness for this project? It captures the full conversation automatically and keeps paged context recoverable." On yes, install per the skill's harness wiring this session. On no, write
{"harness_install": "declined"}toagents/tmp/context-paging.json. Any other answer defers to the next session; ask at most once per session.
Harness wiring
The capture plugin is not shipped; code it at install time so it matches the host's current hook API — references/kimi-hooks.md (kimi code CLI) and references/codex-hooks.md (Codex) are the worked examples. Requirements for any host:
- Gate every invocation on the subscription registry entry for the event's project directory and exit immediately when absent; hooks are user-level in most harnesses, and this gate is what makes them per-project.
- Session start registers the session and runs the due-checked cleanup (this is the periodic cleanup check at the first message of a new session); user messages and tool calls/results insert
messagesrows live where the host provides event payloads, and after-tool/turn-end events sweep the harness transcript past a stored cursor for agent thinking, replies, and anything the events cannot carry (the cursor makes sweeps idempotent; each row has exactly one source, so nothing duplicates); session end sweeps once more and marks the session ended. - Capture is fail-open: hook errors log and allow, never block the harness.
- The session-start hook prints a short paging notice (database path,
cp_search.py,cp_page_out.py) so fresh sessions know older context is recoverable.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

