Renfe trains
Run the CLI as sh <skill folder>/scripts/renfe <arguments>, where <skill folder> is the folder containing this SKILL.md and the arguments are those shown below after renfe. The launcher runs the binary bundled in bin/, or a matching renfe on PATH, or downloads this skill's release binary once from GitHub Releases and checks its SHA-256 before running it. JSON goes to stdout and progress to stderr. Errors exit 1 with Renfe's message.
Setup
- Supported on macOS and Linux. The CLI needs network access to renfe.com. Booking also starts a Chromium-based browser (Helium, Chrome or Chromium;
RENFE_BROWSERoverrides it) and writes to~/.config/renfe/. In a sandboxed agent, request those permissions forbook,payandticket. - Booking reads travellers from
~/.config/renfe/passengers.json. If it is missing, ask the user for each traveller's details and write the file in this format, with permissions 600. Never invent personal details.{"bizum_phone": "+34600000000", "passengers": [{"id": "me", "type": "adult", "name": "...", "surname1": "...", "surname2": "...", "document_type": "DNI", "document": "...", "email": "...", "phone": "+34600000000"}]}typeisadult,child(4 to 13) orinfant;document_typeisDNI,NIEorpassport; the buyer (first passenger) needsemailandphone.
Find trains
renfe stations "barcelona sants"
renfe search --from madrid --to barcelona --date 2026-10-15
renfe search --from valencia --to sevilla --date 2026-10-20 --return 2026-10-22 --adults 2
renfe search --from atocha --to "barcelona sants" --date 2026-10-15 --direct
- Stations take names (accents optional, word prefixes) or codes.
madridmeans all Madrid stations. stderr names the station picked when several match. - Each train has
departure,arrival,duration_minutes,legs(train numbers),sold_out,fares(code,name,price_eurper passenger,conditions) andnotices. Each journey has a ±3-dayprice_calendarfor cheapest-day questions.
Book
Travellers are referenced by id from the passengers file; the first --passenger is the buyer, an adult who receives the tickets by email. Never put personal details in command arguments.
- Search, pick the train and fare the user wants, and check it with
--dry-run. - Prepare the purchase.
--max-totalis the user's budget for the whole purchase:
Expectrenfe book --from madrid --to guadalajara --date 2026-10-08 --train 07:46 --fare basico --passenger me --max-total 10"status": "ready_to_pay"and Renfe'stotal_eur. - Tell the user the train, date, times, fare and
total_eur, and that a Bizum request is about to reach their bank app. Then pay, using exactly that total:
This waits up to 5 minutes (renfe pay --max-total 6.30--wait) for the approval and returns"status": "confirmed"with thelocatorandticket_pdf, the saved ticket (~/.config/renfe/tickets/<LOCATOR>.pdf).
--train takes the departure time or train numbers (05095+02140 for a connection). --fare takes a name, code or cheapest. For a round trip add --return, --return-train and --return-fare. book ... --pay bizum --max-total X does steps 2 and 3 in one run, when the user has already agreed to the train and price.
Rules
- Buy only when the user asked to book or buy. Searching and
--dry-runneed no approval. - Never raise
--max-totalabove the user's budget or the quoted total without asking. - Pay at most once per trip. After
payment_pending, a timeout, or any error oncepaystarted, do not runbookorpayagain for that trip. Ask the user whether they approved the Bizum request and check for Renfe's email first. - Run one
book/payat a time; they share one browser and fail if another is running. - Report the
locatorfrom a confirmed booking and give the userticket_pdf. Aticket_errormeans only the PDF failed; the purchase stands. Fix it withrenfe ticket LOCATOR, never by paying again. renfe ticket LOCATORre-downloads the PDF of a purchase made with this CLI;--tickets-dirchooses the folder. Tickets bought elsewhere are only in Renfe's email.- Payment is Bizum only. For card or PayPal, run
bookwithout--passenger, and the user finishes in the opened browser window.
