Skip to content

Instantly share code, notes, and snippets.

@houshuang
Last active February 27, 2026 12:48
Show Gist options
  • Select an option

  • Save houshuang/39c0ae3a72f4c52c6c955c57a78b1d31 to your computer and use it in GitHub Desktop.

Select an option

Save houshuang/39c0ae3a72f4c52c6c955c57a78b1d31 to your computer and use it in GitHub Desktop.
Claude Code skill: Search and order books from Norwegian libraries (Hamar bibliotek + Biblioteksøk/bibsok.no interlibrary loans)
name description allowed-tools user-invocable
library-search
Search for books and order them from Norwegian libraries. Use when the user wants to find a book, check library availability, reserve/order a book, check loans, renew loans, or request interlibrary loans. Triggers on "find book", "search library", "order book", "reserve book", "check availability", "renew loan", "library", "bibsok", "hamar bibliotek", "interlibrary loan", "fjernlån".
Bash(agent-browser:*)
Bash(npx agent-browser:*)
Bash(curl *)
Bash(cat *)
Read
Write
WebFetch
true

Library Search & Order

Search for books in the Hamar public library and the national library catalog (Biblioteksøk), and order/reserve them for pickup at Hamar bibliotek.

Credentials

Read credentials from /Users/stian/src/research/.env:

  • HAMAR_BIB_EMAIL — email for hamar.bib.no login
  • HAMAR_BIB_PASSWORD — password for both systems
  • HAMAR_BIB_BORROWER_NUMBER — library card number (format: N + 9 digits), used for bibsok.no login

Always load credentials at the start:

source /Users/stian/src/research/.env

System Overview

There are two library systems:

System URL Use for Login with
Hamar Bibliotek https://hamar.bib.no/cgi-bin/m2 Local books at Hamar library Email + password
Biblioteksøk https://bibsok.no/ National catalog + interlibrary loans Borrower number + password

Always pick up at Hamar bibliotek (the default for both systems).

Workflow: Deciding Which System to Use

  1. Start with Hamar Bibliotek if the user wants a common/popular book — faster pickup if available locally
  2. Use Biblioteksøk if the book isn't found locally, or the user specifically wants an interlibrary loan
  3. Use the BIBSYS SRU API for quick bibliographic lookups (no auth, returns MARCXML) — useful when you just need to check if a book exists or get its ISBN

System 1: Hamar Bibliotek (Local Library)

Login

agent-browser open "https://hamar.bib.no/cgi-bin/m2?mode=login" && agent-browser wait --load networkidle && agent-browser snapshot -i
# Fill lnr field with email, passord field with password
agent-browser fill @LNR_REF "$HAMAR_BIB_EMAIL" && agent-browser fill @PASSORD_REF "$HAMAR_BIB_PASSWORD"
agent-browser click @LOGIN_BUTTON_REF && agent-browser wait --load networkidle

Search

After login, search from the homepage:

agent-browser open "https://hamar.bib.no/cgi-bin/m2" && agent-browser wait --load networkidle && agent-browser snapshot -i
# Fill the search field (pubsok_txt_0) and submit
agent-browser fill @SEARCH_REF "search terms" && agent-browser press Enter && agent-browser wait --load networkidle
agent-browser snapshot -i

Search results show for each book:

  • Title and author (linked)
  • Format: Bok/DVD/etc, Language, Year
  • Availability: green "X ledig" (available) or red "Ikke ledig" (unavailable)
  • "Bestill..." button to reserve
  • "Vis mer" button for details

Present results to user as a numbered list with title, author, year, and availability status.

Reserve a Book

# Click "Bestill..." on the desired result
agent-browser click @BESTILL_REF && agent-browser wait --load networkidle && agent-browser snapshot -i
# The form shows pickup location radio buttons — Hamar bibliotek should be default/selected
# Click "Bekreft bestilling" to confirm
agent-browser click @CONFIRM_REF && agent-browser wait --load networkidle
agent-browser snapshot -i  # Verify confirmation

Pickup locations: "Hamar bibliotek" (always use this) or "Hamar bibl.Vang".

Check Current Loans & Reservations

agent-browser open "https://hamar.bib.no/cgi-bin/m2?mode=mappami" && agent-browser wait --load networkidle && agent-browser snapshot -i

Shows:

  • Mine reserveringer — ordered/reserved books with "Endre"/"Avbestill" buttons
  • Mine lån — currently borrowed books with due dates and "Forleng lånet" (renew) buttons
  • "Forleng alle lån" button to renew everything at once

Renew Loans

# To renew all loans at once:
agent-browser click @RENEW_ALL_REF && agent-browser wait --load networkidle
# Or click individual "Forleng lånet" buttons

Other Useful Pages

Page URL
Profile ?mode=lninfo
History ?mode=historikk
Wishlist ?mode=lister-vis
Messages ?mode=saker-vissaker

System 2: Biblioteksøk (National Interlibrary Loans)

Login

agent-browser open "https://bibsok.no/?mode=logginn" && agent-browser wait --load networkidle && agent-browser snapshot -i
# Fill lnr with borrower number, passord with password
agent-browser fill @LNR_REF "$HAMAR_BIB_BORROWER_NUMBER" && agent-browser fill @PASSORD_REF "$HAMAR_BIB_PASSWORD"
agent-browser click @LOGIN_BUTTON_REF && agent-browser wait --load networkidle

Search

Search URL pattern — can be opened directly:

https://bibsok.no/?mode=vt&pubsok_txt_0={QUERY}

With field-specific search:

https://bibsok.no/?mode=vt&pubsok_txt_0={QUERY}&pubsok_kval_0={FIELD}

Field codes for pubsok_kval_0:

Code Field
(empty) All fields
/HT Exact title
/TI Words in title
/PE Author
/EO Subject
/IS ISBN
/KL Dewey number

Filters:

Parameter Example values
avgr_medier ff=l (books), ff=di (audiobooks), lf=t (comics)
avgr_spraak sp=nor, sp=eng, sp=swe, sp=ger, sp=fre
avgr_bn bn=a (adults), bn=j eller bn=d (children/youth)
aarfra / aartil Year range (4-digit years)
sortering relevans, aar, tittel, ordord

Example searches:

# Simple search
agent-browser open "https://bibsok.no/?mode=vt&pubsok_txt_0=Kierkegaard" && agent-browser wait --load networkidle && agent-browser snapshot -i

# ISBN search
agent-browser open "https://bibsok.no/?mode=vt&pubsok_txt_0=9788249511129&pubsok_kval_0=/IS" && agent-browser wait --load networkidle && agent-browser snapshot -i

# Books by author in Norwegian
agent-browser open "https://bibsok.no/?mode=vt&pubsok_txt_0=Ibsen&pubsok_kval_0=/PE&avgr_medier=ff%3Dl&avgr_spraak=sp%3Dnor" && agent-browser wait --load networkidle && agent-browser snapshot -i

Present results to user as a numbered list.

Order Interlibrary Loan

After finding a book, extract its TNR from the detail page link:

# Navigate to book detail
agent-browser open "https://bibsok.no/?tnr={TNR}" && agent-browser wait --load networkidle && agent-browser snapshot -i

# Must be logged in. Click "Bestill" button
agent-browser click @BESTILL_REF && agent-browser wait --load networkidle && agent-browser snapshot -i

# The order page defaults to Hamar bibliotek as pickup. Confirm with "Reserver"
agent-browser click @RESERVER_REF && agent-browser wait --load networkidle
agent-browser snapshot -i  # Verify confirmation

Hamar bibliotek code is 2040300 — it should be the default pickup library.

System 3: BIBSYS SRU API (Quick Bibliographic Search)

For quick lookups without browser automation. No auth required:

curl -s 'https://bibsys-network.alma.exlibrisgroup.com/view/sru/47BIBSYS_NETWORK?version=1.2&operation=searchRetrieve&recordSchema=marcxml&query=alma.all_for_ui=SEARCH_TERM&maximumRecords=10'

CQL query fields:

  • alma.all_for_ui=TERM — search all fields
  • alma.title="PHRASE" — by title
  • alma.creator=NAME — by author
  • alma.isbn=NUMBER — by ISBN

Combine with AND: alma.creator=Ibsen AND alma.title=Hedda

Returns MARCXML. Key MARC fields:

  • 020 = ISBN
  • 100 = Author
  • 245 = Title
  • 260/264 = Publisher/year
  • 300 = Pages

Use this for quick existence checks or to find ISBNs before searching in the other systems.

Interaction Guidelines

  1. Always present results clearly — numbered list with title, author, year, availability
  2. Ask before ordering — confirm with the user which book to reserve
  3. Try local first — check Hamar bib before suggesting interlibrary loan
  4. Report availability — tell the user if a book is available now or must be waited for
  5. After ordering, confirm — read back the confirmation to the user
  6. Close browser when done — run agent-browser close after completing all operations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment