
12306
This is a wrapper around China Railway's official 12306 API for querying train schedules and ticket availability. You can filter by train type (G/D/Z/T/K), departure windows, travel duration, and seat class, with output in HTML, markdown tables, or JSON. The station lookup is essential because city names are ambiguous (武汉 has four stations, 上海 has four, and querying by city returns trains from any of them). If you're building travel tools for China or need to help users plan high-speed rail trips with transfers, this handles the tedious parts. No API key needed since it hits the public endpoint directly, and station data caches locally for a week.
- skills.sh installs
- 642
- GitHub stars
- 12
- last updated
- Jul 14, 2026
Install
$ npx -y skills add kirorab/12306-skill --skill 12306 --agent claude-codeInstalls into .claude/skills of the current project.
Files
12306 Train Query
Query train schedules and remaining tickets from China Railway 12306.
Query Tickets
node {baseDir}/scripts/query.mjs <from> <to> [options]
- HTML mode (default): writes file, prints path to stdout
- Markdown mode (
-f md): prints table to stdout
Examples
# All trains from Beijing to Shanghai (defaults to today)
node {baseDir}/scripts/query.mjs 北京 上海
# Markdown table output (to stdout, good for chat)
node {baseDir}/scripts/query.mjs 北京 上海 -t G -f md
# Morning departures, 2h max, with second class available
node {baseDir}/scripts/query.mjs 上海 杭州 -t G --depart 06:00-12:00 --max-duration 1h --seat ze
# Only bookable trains arriving before 6pm
node {baseDir}/scripts/query.mjs 深圳 长沙 --available --arrive -18:00
# Custom output path
node {baseDir}/scripts/query.mjs 广州 武汉 -o /tmp/tickets.html
# JSON output (to stdout)
node {baseDir}/scripts/query.mjs 广州 武汉 --json
Options
Sponsors
Details
- Repository
- github.com/kirorab/12306-skill
- First seen
- Jun 3, 2026