zad
Make clearing your coding agent's context window safe.
Quick start · How it works · Any agent · Case study (العربية) · Portfolio write-up
Coding agents are stateless. Every turn resends the entire conversation, so cost grows quadratically and answers get worse as the window fills. The fix is to clear the context — but clearing destroys everything the agent learned.
zad makes clearing safe. It keeps one plain Markdown file in your repository
holding the four things a /clear would otherwise delete forever: the plan, the
decisions, the approaches that already failed, and the constraints you stated out
loud but never wrote down.
It stores nothing else. Not the architecture, not the file layout, not what your functions do — the agent re-reads all of that from the repository for free.
pipx install zad-cli
بالعربية: دراسة الحالة التقنية — القرارات المعمارية والأخطاء والأرقام المقيسة · رحلة البناء — سرد المشروع من المشكلة إلى النشر.
Before
The ritual, every time the context filled up:
- Notice the agent is repeating itself and the replies are getting worse
- Scroll back and try to remember which decisions actually mattered
- Type a summary into the chat and hope it covers the dead ends
/clear- Paste the summary back and spend three turns re-explaining what it left out
Step 3 is where the loss happens. You remember what you built. You do not remember, at 1 a.m., the thing you tried at 11 p.m. that did not work.
After
zad handoff # prompt is on your clipboard — paste it, then /clear
The agent updates .ctx/handoff.md itself and you clear with nothing lost. The
file is committed, so it survives the session, the machine, and you.
Quick start
pipx install zad-cli
cd your-project
zad init
The distribution is zad-cli because zad was already taken on PyPI by an
unrelated DNS tool. The command you run is zad.
zad init finds your agent instruction files (CLAUDE.md, AGENTS.md,
.cursorrules, .cursor/rules/, .github/copilot-instructions.md), appends one
marker-delimited block telling the agent to read the handoff first, and creates
.ctx/handoff.md. It never touches a byte outside its own markers, and running
it twice changes nothing.
Then, whenever the window is filling up:
zad status # how full is it, and what is filling it
zad handoff # copy the prompt, paste it, /clear
That is the whole tool. Four commands, one of which you will never run:
| command | what it does |
|---|---|
zad init |
wire zad into this repo's agent instruction files |
zad status |
measure the current session — read-only, changes nothing |
zad handoff |
put the update prompt on your clipboard |
zad uninstall |
remove the marker block; leaves .ctx/ alone |
zad adapters |
what zad can read on this machine, and how to teach it more |
The file
.ctx/handoff.md, committed to your repository, hand-editable:
# zad handoff
<!-- generated by zad — safe to edit by hand -->
## Plan
- [x] 1. Authentication
- [ ] 2. Authorization <- current
- [ ] 3. Audit log
## Decisions
- JWT over server sessions — frontend is decoupled
Rejected: server sessions (complicates deployment)
## Never again
- Pre-indexing on boot — added 12s to startup
- Roles inside the token — grows unbounded
## Constraints
- Do not change the folder structure
- Node 18, no upgrade
Four sections and no schema beyond that. Add your own sections, prose or notes; zad carries anything it does not understand through untouched. Full details and the format guarantee are in docs/schema.md.
How it works
The code describes itself. That single idea is why zad is a few thousand lines instead of a platform.
After a context clear, the agent re-reads your repository. It recovers the architecture, the module layout, the function signatures, the test names, the dependency list — every "what exists" fact — at no cost to you, because it was going to read those files anyway. Writing any of that into a handoff file means paying tokens to duplicate something already available for free, and then paying again to keep the duplicate current.
So zad refuses to store it. What is left is exactly the set of things the repository cannot tell you:
- the plan — done and next. Git history shows what changed, not what is next.
- the decisions — and the alternatives that were rejected. The code shows JWT; it does not show that server sessions were considered and why they lost.
- the dead ends — the expensive one, see below.
- the constraints — "Node 18, no upgrade" lives in your head and in one message from three weeks ago.
The append-only rule
Negative knowledge — we tried X and it failed — exists in no file anywhere. The failed attempt was deleted. The branch was thrown away. The code that remains describes only what worked.
That is why an agent, an hour after a clear, proposes with total confidence the exact approach that failed at lunchtime, and why you pay for that discovery twice.
So the ## Never again section is append-only. Nothing in zad removes,
edits, reorders, deduplicates or summarises an entry there. Not merge(), not
init, not any other code path. merge() verifies the invariant on its own
output and refuses to write if it was ever violated. There is a test named after
it. The generated prompt tells your agent the same thing in capital letters.
Only you, editing the file by hand, can take a line out. That is your call to make, not the tool's.
zad status
Read-only measurement of the session you are in right now.
zad status — claude-code
session ad1fd7d2-49a1-4221-8031-4667b6f2a98e
project /Users/macbook/Desktop/زاد-حل ازمة نافذة السياق
Context 309,273 tokens ████████████████████ 155% of 200,000
exact — reported by the API for the last turn
over the assumed window — pass --window to match your model
Growth +1,595 tokens per turn over 163 turns
Breakdown estimate (tiktoken o200k_base)
conversation 102,698 76.0%
thinking 11,464 8.5%
tool output 20,991 15.5%
total 135,153
this covers the message text in the transcript only. The system prompt, tool
definitions and anything the transcript does not record are not in it, which is
why this total is smaller than the context figure above.
Arabic 3,965 Arabic characters (measured on the first 400k characters)
tiers are cumulative in order; zad changes nothing
tier 1 safe invisible and legacy characters 87 found ~70 tokens
tier 2 judgment call letter unification 322 found ~0 tokens
tier 3 risky diacritic removal 211 found ~226 tokens
→ '4. `zad status` and the session adapter layer' is done and context is about
155% full — this might be a good place to run 'zad handoff' and /clear before
starting '5. `zad handoff` and release readiness'
Real output, from zad measuring the session that built zad. The per-tier caveat lines are elided here for width; the tool always prints them.
It also reports files read more than once with no change in between (content
hash comparison, so an edit makes a re-read legitimate), and --json for
scripting.
status is the only command that reads anything outside your repository, and it
never writes. If no supported agent is installed it says so and exits 0.
It will not guess
Transcript formats are undocumented and change without notice, so zad scores how much of one it actually recognised and shows the evidence. It prints token numbers only when a verified field mapping recognised the file — a mapping a person checked against a real installation on a date recorded in the descriptor.
Otherwise it tells you what it found, says plainly that it is unverified, and
stops. No numbers, in the text output or in --json, where the measured keys are
absent rather than null so a script cannot read a zero and believe it.
A wrong context size is worse than no context size, because you act on it.
Any agent
What zad knows about a format is a JSON descriptor, not code. Adding an agent
is a JSON file dropped in ~/.config/zad/adapters/ — no Python, no fork, no
release. Claude Code ships verified; a shape-inference fallback reads transcripts
nobody has described yet, well enough to tell you they are there.
zad adapters list # what zad knows, and when each mapping was verified
zad adapters detect # where zad looked, and what was actually there
zad adapters report # anonymized structure to paste into an issue
zad adapters report describes the shape of your transcripts — key paths,
types, counts, string lengths — and never their contents. No messages, no file
paths, no code, no value strings at all. That is what makes it safe to paste into
a public issue, and it is checked by a test that fills a fixture with sentinel
values and asserts none of them survive.
Full schema and a worked example: docs/adapters.md.
Arabic
Arabic costs about 2.5 characters per token where English costs about 4.0
(measured over 1.4 MB of real transcripts against o200k_base; on cl100k_base
Arabic is 1.55). So the usual len(text) / 4 estimate is accurate to within a
percent for English and underestimates Arabic by 36% — worse than useless for
the people whose windows fill fastest. zad estimates per script instead; on
held-out data its worst-case error is 3.4%. Method and numbers:
docs/session-formats.md.
Invisible junk is correspondingly expensive, so status reports it — in three
tiers that are never merged into one number:
| tier | what | safety |
|---|---|---|
| 1 | tatweel, presentation forms, zero-width marks, non-standard spaces | safe — renders identically |
| 2 | أ إ آ ٱ → ا, ى → ي, ة → ه |
judgment call — changes spelling, wrong for proper nouns |
| 3 | diacritics | risky — meaningful in poetry, religious and ambiguous text |
There is deliberately no "optimize" button. A single figure across all three
tiers would be a button that quietly corrupts Quranic text to save tokens.
status reports; nothing in zad rewrites your text.
Guarantees
- Zero runtime dependencies. Standard library only.
tiktokenis the single optional extra (pipx install "zad-cli[tokenizer]") and onlystatususes it. - No network. Ever. No API keys, no model calls, no telemetry, no analytics.
zad handoffcalls no model — the agent in front of you is the model, and it already has the whole session in its context. - Python 3.9+, macOS, Linux and Windows, tested on all nine combinations.
- Never a traceback. Failures print one line and exit non-zero.
Each of these is enforced by a test, not by good intentions:
tests/test_constraints.py walks the AST of every module to check the version
floor, the dependency list, and that no networking module is imported anywhere.
Non-goals
zad is deliberately small. It is:
- not a prompt compressor — it does not rewrite, shorten or re-encode your prompts
- not a memory database — no index, no embeddings, no store; one Markdown file in your repo
- not a RAG system — it retrieves nothing and ranks nothing
- not a proxy — it sits nowhere in the request path and makes no network calls
- not a project planner — it records the plan you already have; it does not produce one
The value is in what it refuses to do. Every feature it does not have is context it does not spend.
Contributing
The most useful thing you can add is an adapter for another agent — Cursor,
Codex, Aider, Zed. zad status supports Claude Code today because that is the
only transcript format anyone has sat down and observed. See
CONTRIBUTING.md.
MIT licensed. zad is Arabic for the provisions you pack for a journey.
Metadata
Release files for zad-cli 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zad_cli-0.1.0.tar.gz | 107.7 kB | With provenance | Details for zad_cli-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zad_cli-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for zad_cli-0.1.0-py3-none-any.whl |
Total release size: 175.2 kB
Release files / zad_cli-0.1.0.tar.gz
| Download URL | zad_cli-0.1.0.tar.gz |
|---|---|
| Size | 107.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba98be0034693a54985ee006baa5d06dc7a6ce7762ce9a24c79040d7a9980578
|
|
BLAKE2b-256 checksum How to use checksums |
f1484561170ee318e6225921327ef4d3a11ee30a280502695f980f4438ea8edb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / zad_cli-0.1.0-py3-none-any.whl
| Download URL | zad_cli-0.1.0-py3-none-any.whl |
|---|---|
| Size | 67.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c36ab364e176fbdce8f44f96aa63321a4ea919ed3f90e85778e95c143c9828cb
|
|
BLAKE2b-256 checksum How to use checksums |
397ba5db7095b1bdada375395db8fb9e3b422e4be0ee4e40ae41996db4a40b6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logSecurity for zad-cli 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for zad_cli-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.