The Writ of Habeas Corpus protects prison inmates from false imprisonment to ensure people are not thrown into jail unlawfully. The inmate may file a petition for writ of habeas corpus.A habeas corpus petition cannot act as a second direct appeal. A writ of habeas corpus petition is a tool that individuals convicted of criminal offenses in California can use to challenge their imprisonment. Generally, a writ of habeas corpus is a civil remedy that challenges the legality of a person's detention or confinement. A petition for writ of habeas corpus is a legal action that allows individuals to challenge their unlawful imprisonment or restraint. A federal writ of habeas corpus is a legal remedy available to state and federal prisoners who object to their detention or imprisonment. This petition, called a writ of Habeas Corpus, is filed in Federal Court (US District Court ) whether you are serving time in a federal or state prison. The habeas petition is for situations when a legal error occurred, as we say, outside the "four corners" of the court file. Rules 8.380-8.388 govern habeas in the Court of Appeal and Supreme Court.