Where does someone file a petition for a writ of habeas corpus?

Habeas Petitions Based on a Texas State Conviction

A person wanting to challenge a criminal conviction that was handed down by a state court in Texas must file his petition with the court that handed down the conviction.

Habeas Petitions Based on a Federal Conviction

A person wanting to challenge a criminal conviction that was handed down by a federal court must file his petition with the court that handed down the conviction.

Federal Habeas Petitions Challenging a Texas State Conviction

A person who was convicted by a state court and who has lost his state petition for habeas corpus has two options for where he files his petition. He can either file it

(1) in the federal district court with jurisdiction over his county of incarceration or

(2) in the federal court with jurisdiction over the county out of which his conviction is based. Usually, however, the case will be ultimately transferred to the federal court with jurisdiction over the county out of which the conviction is based.

Title 28, Section 124 dictates which federal district courts have jurisdiction over the various Texas counties. Here is a link to that statute.