12306-skill
A 12306 Train Schedule and Ticket Availability Query Tool Without API Keys
Install & Use
Copy this prompt and send it to your AI assistant (Claude / Cursor / TRAE / Codex / WorkBuddy etc.) to auto-install:
Help me install this AI Skill: 12306-skill. It is used for: A 12306 Train Schedule and Ticket Availability Query Tool Without API Keys Full Skill content: https://321skill.com/skills/12306-skill/raw/index.md Read that page and install it.
The prompt includes a link to the full Skill content. You can also view the full content.
This Skill addresses the cumbersome process of applying for API keys when querying China Railway 12306 train schedules and ticket availability. In practical travel planning, users often need to quickly obtain train numbers, departure times, arrival times, and seat availability for a specific route. However, official channels or third-party APIs typically require registration, authentication, or even payment, making the process lengthy.
Usage is straightforward: simply run a command in the terminal with the departure station, destination, and optional parameters. For example, to query all trains from Beijing to Shanghai for today, execute node {baseDir}/scripts/query.mjs Beijing Shanghai. This generates an HTML file displaying the results. To output a Markdown table for easy sharing in chats, add the -f md flag. It also supports flexible filtering by train type (G/D/Z/T/K), departure time range, arrival time range, maximum travel duration, and showing only trains with available tickets.
It is ideal for individuals or teams who frequently need to query train ticket information, especially those who have integrated AI coding assistants (like Claude or Cursor) into their workflows. University students, job seekers, and frequent business travelers can use natural language instructions to have an AI agent directly invoke this tool, eliminating the need to manually open a browser or app. For data analysts, the JSON output mode enables batch data retrieval for further analysis.
Before querying, it is recommended to use the stations.mjs script to confirm the full station name, as a single city may have multiple stations (e.g., Wuhan Station, Hankou Station, Wuchang Station). Entering just the city name may lead to inaccurate results. Please note that this tool relies on a Node.js environment, and query results are based on 12306's public data, which may be affected by network restrictions or anti-crawling mechanisms. It is advisable to control query frequency appropriately.
Key Features
Unlike the official 12306 website or third-party APIs (e.g., 12306-api), it requires no API key application, works out-of-the-box, and runs entirely locally in the command line. This makes it suitable for integration into AI coding assistant workflows, where queries can be triggered via natural language instructions.
Limitations
Requires a Node.js environment (node must be pre-installed). Query results are based on 12306's public data, and high-frequency requests may trigger anti-crawling restrictions. It is recommended to maintain an interval of at least 1 second between queries.
FAQ
How do I query for transfer (connecting) options?
This tool currently only supports direct, single-leg queries and does not support automatic transfer planning. If a transfer is needed, it is recommended to first use the JSON output mode (--json) to obtain train information for each leg and then manually combine them, ensuring the transfer station is the same for both segments.
How do I specify the query date?
Use the -d or --date parameter with the format YYYY-MM-DD, for example, -d 2025-06-15. If not specified, it defaults to today.
Installation guide for AI assistants
If your AI coding assistant (Claude Code, Cursor, TRAE etc.) can see this page, send it this message to auto-install:
Visit https://321skill.com/skills/12306-skill/raw/index.md to read the original Skill definition (Markdown format) for 12306-skill, and install it according to the instructions.
Raw Markdown URL for AI: /skills/12306-skill/raw/index.md