The procedure for filing a petition for a writ of habeas corpus is spelled out in the CPLR Article 70. Petition for a Writ of Habeas Corpus under 28 USC 2241.Category Representing Yourself (Pro Se). First, a U.S.C. § 2254 allows us to file a petition for Habeas Corpus when the client is in custody under sentence of a state court and is in a state prison. This article addresses a defendant's right to file a federal petition for a writ of habeas corpus from a conviction in a state court. Filing may proceed on a consensual basis in contested matrimonial and Article 78 matters. A writ of habeas corpus may be served on any day. A Writ of Habeas Corpus is a civil proceeding that is available in both State and Federal Court to challenge the legality of imprisonment. Any defendant who has been convicted of a New York state crime in a proceeding should be aware of their right to file a petition for a Writ of Habeas Corpus. Such petitions can be filed if a defendant has been convicted in a New York state court as well as for defendants convicted in a federal court.