Skip to main content
Glama
README.md
# chitransit

Chicago transit data for AI agents and people. `chitransit` is a command-line tool and an MCP
server built on the official CTA and City of Chicago feeds:

- **'L' trains:** arrivals at any station, live positions of every train, follow one train by run number
- **The Loop:** trains on the elevated ring by line and track, downtown subway trains, line status and downtown alerts, in one call
- **Buses:** arrival predictions, live GPS positions, routes, directions and stops (Bus Tracker API v3)
- **Alerts:** delays, planned work, reroutes, station closures and elevator outages
- **Divvy:** live bikes, e-bikes, scooters and open docks near a place
- **Ridership:** daily and monthly 'L' station entries and bus route boardings (Chicago Data Portal)
- **History:** a small recorder that logs train positions to SQLite, then reports headways, gaps,
  bunching and delay rates. CTA only serves the present, so this is how you answer "how bad was
  the Brown Line this morning?"

It talks to CTA directly with your own free keys: no proxy, no account with anyone else.

## Install

Python 3.10 or newer. With [uv](https://docs.astral.sh/uv/):

```bash
uv tool install git+https://github.com/vayllon301/chitransit
chitransit doctor
```

Or run it without installing: `uvx --from git+https://github.com/vayllon301/chitransit chitransit loop`.

## API keys

| Feature | Key | Get it |
|---|---|---|
| 'L' arrivals, positions, follow, `loop` trains, `record` | `CTA_TRAIN_API_KEY` | [Train Tracker API](https://www.transitchicago.com/developers/traintrackerapply/) (free) |
| Bus arrivals, vehicles, routes, stops | `CTA_BUS_API_KEY` | [Bus Tracker API](https://www.transitchicago.com/developers/bustracker/) (free, sign in at ctabustracker.com) |
| Alerts, line status, stations, Divvy, ridership, GTFS bus stop search | none | |

Set them as environment variables (see `.env.example`). Each key allows 100,000 requests a day.
Keys travel in the query string, so chitransit never logs request URLs or puts them in errors.

## Command line

```bash
chitransit loop                                  # the Loop right now
chitransit arrivals "Clark/Lake"                 # next trains (names are fuzzy: "clark and lake" works)
chitransit arrivals western --line brown         # several stations share a name; pick by line
chitransit positions --line red --line blue      # every train on those lines
chitransit follow 412                            # one train's upcoming stops
chitransit status                                # CTA's status line for each 'L' line
chitransit alerts --station "Washington/Wabash"  # alerts for a station (or --line, --bus-route, --elevators)
chitransit stations library                      # search stations; --near LAT,LON; --loop
chitransit bus arrivals 1850 --route 22          # bus predictions at stop ids
chitransit bus vehicles 22 36                    # live buses on routes
chitransit bus stops 22 Northbound               # stop ids for a route and direction
chitransit sync --gtfs                           # once: download CTA GTFS (~50 MB) for bus stop search
chitransit bus find "Michigan & Washington"      # bus stops by name, or --near
chitransit divvy "Clark/Lake"                    # Divvy near a station or LAT,LON
chitransit nearby 41.8789,-87.6359               # 'L', Divvy and bus stops around a point
chitransit ridership station "Clark/Lake"        # latest 30 published days; --monthly, --from, --to
chitransit ridership bus 22
```

Every command takes `--json` for machine-readable output.

## MCP server

`chitransit mcp` runs an MCP server on stdio with 16 read-only tools:

| Tool | What it answers |
|---|---|
| `loop_status` | What is happening in the Loop right now? |
| `train_arrivals` | When is the next train at a station? |
| `train_positions` | Where is every train (optionally near a place, or on the Loop)? |
| `follow_train` | Where is run 412 going and when does it get there? |
| `find_station` | Which station is "the library"? Ids, lines, platforms, accessibility |
| `line_status`, `service_alerts` | Is the Blue Line OK? Is the elevator at Clark/Lake working? |
| `bus_arrivals`, `bus_vehicles`, `bus_route_info`, `find_bus_stops` | Buses |
| `nearby`, `divvy_near` | What is around this corner? Are there bikes? |
| `ridership_history` | How busy is a station or bus route, historically? |
| `history_summary`, `station_headways` | How did service actually run (needs the recorder) |

Claude Code:

```bash
claude mcp add chitransit \
  --env CTA_TRAIN_API_KEY=your-train-key --env CTA_BUS_API_KEY=your-bus-key \
  -- uvx --from git+https://github.com/vayllon301/chitransit chitransit mcp
```

Claude Desktop or any client with a JSON config:

```json
{
  "mcpServers": {
    "chitransit": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/vayllon301/chitransit", "chitransit", "mcp"],
      "env": { "CTA_TRAIN_API_KEY": "your-train-key", "CTA_BUS_API_KEY": "your-bus-key" }
    }
  }
}
```

Codex (`~/.codex/config.toml`):

```toml
[mcp_servers.chitransit]
command = "uvx"
args = ["--from", "git+https://github.com/vayllon301/chitransit", "chitransit", "mcp"]
env = { CTA_TRAIN_API_KEY = "your-train-key", CTA_BUS_API_KEY = "your-bus-key" }
```

## Reading the data correctly

- **Live vs scheduled.** Train Tracker mixes tracked trains with timetable entries. `live: false`
  means no train is being tracked yet for that slot; `schedule_fault: true` means its scheduled
  departure did not happen, so it may never run. Treat both as tentative.
- **Minutes** follow CTA's advice: arrival time minus the time the prediction was made.
- **Positions** come from track circuits, not GPS, so they snap to the track. Buses report GPS.
- **The Loop.** Brown, Green, Orange, Pink and Purple trains use the elevated ring; Red and Blue
  cross downtown in subways. The Inner Loop track runs clockwise and the Outer Loop
  counterclockwise (from the platform directions in CTA's stop list). Per that list, Brown trains
  use the Outer Loop; Orange, Pink and Purple the Inner Loop; Green runs both ways along Lake
  Street and Wabash Avenue only.
  `loop_status` counts a train as on the Loop when its next stop is a Loop station.
- **Times** are ISO 8601 in America/Chicago.
- **Ridership** counts station entries (tap-ins) and is published with a lag of about two months.
- **Not available from CTA:** train crowding, a trip planner, a history of past arrivals. Bus
  Tracker v3 has a passenger-load field; chitransit passes it on when CTA fills it in.

## History recorder

```bash
chitransit record                       # polls all lines every 60 s into the data directory
chitransit history summary --since 24h  # trains in service, distinct runs, delay share, outages
chitransit history headways "Clark/Lake" --line brown --since 7d
```

One request covers all eight lines, so 60-second polling uses about 1,440 of a key's 100,000
daily requests. Headways come from the moment a train's next stop changes, so they are accurate
to about half the poll interval; gaps that span a recording outage are skipped.

To keep it running on Linux, a systemd user service works:

```ini
# ~/.config/systemd/user/chitransit-record.service
[Unit]
Description=chitransit train position recorder

[Service]
EnvironmentFile=%h/.config/chitransit/env
ExecStart=%h/.local/bin/chitransit record --quiet
Restart=on-failure
RestartSec=30

[Install]
WantedBy=default.target
```

Data lives in `$CHITRANSIT_HOME`, else `$XDG_DATA_HOME/chitransit` or `~/.local/share/chitransit`
(`%LOCALAPPDATA%\chitransit` on Windows).

## Data sources

See [docs/DATA_SOURCES.md](docs/DATA_SOURCES.md) for every endpoint, its key, limits and quirks.
This project is not affiliated with the CTA, Divvy, Lyft or the City of Chicago. Use of CTA data
is subject to the [CTA developer terms](https://www.transitchicago.com/developers/terms/).

## Development

```bash
uv sync
uv run pytest
```

Tests run offline against recorded-format fixtures. MIT licensed.

TDQS

B3.2/5.0

Scored across 16 tools

Disambiguation4/5

Most tools map to a distinct resource+action (bus_arrivals vs bus_vehicles vs bus_route_info are cleanly separated, as are train_arrivals, train_positions and follow_train). Overlap remains around loop_status, which restates line status and alerts scoped to the Loop, and around nearby, which aggregates divvy_near, find_station and find_bus_stops results, so an agent may hesitate between the aggregate and the specific tool.

Naming Consistency3/5

There is a loose domain-prefix convention (bus_*, train_*, plus find_* and divvy_near), but the pattern mixes domain-first nouns (bus_arrivals, station_headways), verb_noun (find_station, follow_train, find_bus_stops) and one bare noun (nearby). It stays readable, but a tool like find_bus_stops breaks the bus_* grouping and divvy_near/divvy_* ordering is inconsistent.

Tool Count4/5

16 tools is at the upper edge of the comfortable band, but the surface spans four sub-domains (L trains, buses, Divvy, historical/recorded data), so each tool carries weight. A few, such as loop_status and history_summary, feel like conveniences layered on top of existing tools rather than new capabilities.

Completeness4/5

Coverage is strong: real-time arrivals and vehicle positions for both bus and rail, alerts, station/stop discovery, Divvy availability, and even historical ridership and headway analytics. The notable gap is any multi-modal trip/journey planning or route-itinerary tool, and there is no explicit station-detail/accessibility lookup beyond what find_station returns.

Maintenance

ActivityMaintained
ResponsivenessOutdated data