/zotero-librarian:zotero-librarianfrom zotero-librarian
Import PDFs, papers, books and lecture notes into Zotero with metadata verified against the file itself rather than trusted from a catalogue, and keep the library on a flat collections-for-context, tags-for-topic model. Also handles lookups ("what does my library have on X"), retagging, and reorganising. Use whenever the user wants to add something to Zotero, search or ask about their Zotero library, or organise items in it.
Ships in zotero-librarian. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Zotero is the single library. There is no second destination to route to — everything with a PDF goes here, and the only questions are what is this exactly and where does it belong.
This skill exists because the obvious way to answer the first question is wrong. Looking an ISBN up in a catalogue and writing down what comes back produces a library that is confidently incorrect: wrong books, wrong years, wrong authors, and — worst — no signal that anything is wrong. The method here was derived by migrating 115 books and measuring every step; the numbers quoted throughout are from that run, not estimates.
The one rule everything else follows from: the tools gather evidence, the model decides, and the PDF is the final authority.
Just start; no need to re-confirm the plan first. Report progress as you go.
Zotero desktop must be running. The MCP server talks to it locally
(ZOTERO_LOCAL=true) and reads ~/Zotero/zotero.sqlite directly.
zotero_write_capabilities at
the start of any run that will write; if it reports writes unauthorized, call
zotero_authorize_local_writes, which pops a dialog for the user to approve. Don't
attempt writes before it succeeds.GB_KEY in the
environment. Never hardcode it or commit it.If the server doesn't appear, check /plugin (is this plugin enabled?) and /mcp.
Where lib/ is. Every lib/*.py named below lives at ${CLAUDE_PLUGIN_ROOT}/lib,
which is set for you. It is stdlib-only — import it by putting that directory on the
path, and run it with uv:
uv run --no-project python -c "
import sys; sys.path.insert(0, '$CLAUDE_PLUGIN_ROOT/lib')
import sources, resolve
print(sources.gb('9780262048644'))
"
Inbox/ and nowhere else. Only the user knows what context an item
belongs to.zotero_write_capabilities. If writes aren't authorized, zotero_authorize_local_writes
and wait. Confirm mutool is on PATH (it is the only PDF tool needed — see
Reading the file).
mutool info <pdf> page count — the only trustworthy source
mutool draw -F txt -o - <pdf> 1-10 front matter text layer, if any
mutool draw -F png -r 150 -o p%d.png <pdf> 1-10 render when there is no text layer
You are the OCR. No tesseract/ocrmypdf is needed: render the pages and look at
them. It is effectively free — page 3 of a 216 MB scan renders in 0.03 s.
Render rather than extract when: the text layer is empty or garbled; the cover is image-only; or extracted author order contradicts the surrounding evidence (extraction returns text in layout order, which can invert an author list).
lib/frontmatter.py gives you page_text, render, page_geometry,
cover_suspicion and needs_visual_read.
Book signals: ISBN on a copyright page, table of contents, "Nth edition", a
dedication/preface, >150 pages. Paper signals: DOI, abstract, references section, a
journal or conference name, <60 pages. Genuinely ambiguous (thesis, book chapter, tech
report) → import anyway, tag needs-review, and say so.
ISBN /\b97[89][\d -]{10,}\b|\b\d{9}[\dXx]\b/ → validate the checksum
DOI /\b10\.\d{4,9}\/[-._;()\/:a-z0-9]+\b/i
arXiv /arXiv:\s*\d{4}\.\d{4,5}/
zotero_add_item(source=<doi|url>). CrossRef metadata,
authoritative; always prefer this when you have one.lib/sources.py, then lib/resolve.py.Do not use zotero_add_item(source_type='isbn') as a source of truth — see
references/mcp-notes.md.
Read the front matter and settle every field against it, for every item, no matter how clean the candidates look. Order of authority:
1. the PDF's typeset title page and its verso (copyright page) ← decisive
2. the rest of the front matter: series page, preface, TOC
3. external sources — for what the PDF omits, and to corroborate
4. any prior local record — a previous judgement, not a fact
5. page 1 / the cover image ← lowest
Resolution: PDF states it → PDF wins, and the override goes in extra so the
decision stays auditable. PDF silent and sources agree → write it. PDF silent and sources
conflict → leave empty, tag needs-review, surface both values. Never pick silently.
The judgements that are yours and cannot be delegated to a rule are listed in references/metadata.md.
Run both checks on every PDF, at import and whenever you open an item's PDF for other work. Report the result even when nothing is wrong:
mutool show <pdf> outline; empty output
means none) and does the front matter have a printed table of contents? A clear
printed Contents but no outline means Zotero's reader sidebar is empty when it
needn't be. Propose generating the outline.uv run lib/outline.py folios <pdf> compares every page's label
with the number typeset on it. Any disagreement, including a PDF with no labels at
all, means Zotero shows and cites PDF page 34 for printed p. 19. Propose fixing the
labels. This check stands on its own: a PDF can have a good outline and wrong labels.
For labels only, uv run lib/outline.py labels <pdf> <out.pdf> --labels <ranges>
writes a copy and re-runs the check on it.Don't fix either one unasked, since the attached file will then differ from the original. At import, do it before step 6 so the file that gets attached already has the fix.
The outline is a true representation of the printed Contents. Hand-curated, not script output, and faithful:
Schr¨odinger → Schrödinger, lost spaces, ligatures), checked
against the rendered page.Steps:
level<TAB>page<TAB>title per line,
with the page number as printed. Read it from mutool draw -F txt, and render the
page to confirm accents, quotes and numbering. Use =N (absolute PDF page) for the
front/back matter entries. Find those with uv run lib/outline.py headings <pdf>,
which lists every bold line with its page, y and size.uv run lib/outline.py check <pdf> toc.tsv. It finds the printed→PDF
offset by voting across every entry (--offset N overrides it), then compares each
title with the heading typeset on its target page: ok, ~ (shows what the page
says), text (no heading found, so the bookmark falls back to page top) or MISS.
Look at every non-ok line. A ~ where the body heading differs from the Contents
keeps the Contents wording. Fix transcription errors in the spec. A MISS can
also be the printed Contents itself being wrong (Goodfellow's lists the Index one page
early): point that entry at the real page with =N, keep its title, and note it in
extra. --force only after looking at each MISS page.uv run lib/outline.py write <pdf> toc.tsv <scratch>/<Author> - <Title>.pdf --labels 1:r,<first arabic page>:D --title "<title>" --author "<author>".
Work out the label ranges from the printed folios (roman front matter, where arabic 1
falls, any restart). Roman i often starts on PDF page 2 because the title page has no
number, so 1:r is a guess to check, not a default. The script refuses an existing
outline without --replace and checks the entry count on read-back. Then run
folios on the copy; it must report 0 disagreements.uv run lib/outline.py verify <out.pdf> <scratch>/sheet.png,
then Read the PNG. It shows one strip per bookmark, cut from where the bookmark lands,
labelled with the title and page label. Every strip must open on its heading. The
labels' curly quotes render as ·, which is a font limitation of the sheet only.
For one entry, confirm the raw destination independently
(mutool show -b <pdf> trailer/Root/Outlines/First/...): /XYZ y is measured from
the page bottom.extra: PDF outline added at import from the printed Contents, titles verbatim (original had none); page labels <ranges> set to match the printed numbering. For a labels-only fix, record just the second half.Already imported? Replace the file inside the existing attachment
(~/Zotero/storage/<attachment key>/), after checking its MD5 is still the file you
attached. That keeps the attachment key and the user's annotations.
zotero_add_item(source=<absolute path>, collections=['Inbox'], tags=[...], if_exists='file')
→ zotero_update_item(...) for anything extraction got wrong
Then strip the junk citation key (see mcp-notes) and verify: zotero_get_item_children
for the attachment, and an MD5 check against the source file if the original is still on
disk.
Full model and the controlled vocabulary: references/structure.md.
Inbox/ everything new; should trend to empty
Courses/<inst>/<course>
Projects/<name>
Archive/
That is the whole collection tree. Items live at the library root unless a course or project actually uses them. Classification is tags:
topic: tags from the controlled vocabulary. A term that isn't in the list is a
vocabulary change to propose, not a tag to invent silently.kind: tag.needs-review whenever a field failed the gate.No runbook. Use zotero_search_items, zotero_advanced_search, zotero_search_by_tag,
zotero_get_item_fulltext, zotero_get_annotations, zotero_get_notes,
zotero_get_collections / zotero_get_collection_items, zotero_get_tags, and
zotero_semantic_search if keyword search comes up empty. Quote what the source actually
says; don't paraphrase from the title.
Pick the attachment before you read. Given a parent key, the PDF tools open its
first attachment, which for lecture notes re-uploaded every few weeks is the oldest
version. When an item has more than one file attachment, resolve which one to read and
pass that attachment key explicitly. The default is the one the user marked in
Weavero, which stores the choice as the tag ▶️ wv-defatt on the attachment.
zotero_get_item_children doesn't show attachment tags, so read them from the database
(read-only, safe while Zotero runs):
sqlite3 "file:$HOME/Zotero/zotero.sqlite?immutable=1" "
SELECT a.key, a.dateAdded, ia.path,
EXISTS(SELECT 1 FROM itemTags it JOIN tags t USING(tagID)
WHERE it.itemID = a.itemID AND t.name = '▶️ wv-defatt') AS wv_default
FROM items p JOIN itemAttachments ia ON ia.parentItemID = p.itemID
JOIN items a ON a.itemID = ia.itemID
WHERE p.key = '<parent key>' AND a.itemID NOT IN (SELECT itemID FROM deletedItems)
ORDER BY a.dateAdded;"
wv_default = 1 → read that one.Say which version you read when you quote from it.
Whenever you open an item's PDF, also run the outline and page-numbering checks from step 5½ and propose any fix they call for.
No fixed script — use the read/write tools directly, keeping the two standing rules: content over filenames, and never delete or merge without confirming. Watch the tag-replacement trap when retagging.
For runs over ~10 files, keep an append-only JSONL ledger — one line per state
transition (intent, created, attached, tagged, verified) — so an interrupted run
resumes cleanly. Write the intent line before the create.
The durable safety net is not the ledger but the library itself: put
imported: <date> (and any source id) in extra, and tag the run. Even with the ledger
deleted, the run can be reconstructed by listing that tag. Always search for an existing
item by that key before creating — if_exists only dedupes on DOI/ISBN/URL, which
self-published material doesn't have.
topic:/kind:
vocabulary, saved searches, item types and field conventions.${CLAUDE_PLUGIN_ROOT}/lib/ — tested code. Don't reimplement it.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub fiocchidavide/zotero-librarian --plugin zotero-librarian