*192OPINION OF THE COURT
Casey, J.In this habeas corpus proceeding, petitioner seeks the immediate release of William Lewis from jail, pursuant to CPL 30.30 (2) (a), upon the ground that the People were not ready for trial within 90 days of the underlying criminal action in which Lewis was accused of at least one felony. Supreme Court concluded that the appropriate remedy was by way of an appeal from the denial of the motion for Lewis’ immediate release made in the criminal action and that, in any event, Lewis was not entitled to immediate release regardless of the length of the prereadiness delay by the People.
Our analysis begins by recognizing that habeas corpus is an appropriate remedy in this case, as Lewis cannot appeal the denial of his motion unless and until he is convicted, when the issue of the propriety of his pretrial detention will be moot (see, People ex rel. Chakwin v Warden, 63 NY2d 120, 125). Supreme Court’s alternative conclusion that Lewis was not entitled to immediate release is based upon the fact that the indictment charged not only the crimes alleged in the felony complaint, but also several additional felonies. As to the additional felonies, the People announced their readiness within 90 days of the indictment. Thus, Supreme Court reasoned that Lewis could be held on the additional felonies on which the People timely announced their readiness, regardless of the length of the prereadiness delay on the charges contained in the felony complaint.
CPL 30.30 (3) (c) (ii) provides that the immediate release provisions of CPL 30.30 (2) shall not require the release of a defendant who is also being held in custody pending trial of another criminal charge as to which the applicable period for the People’s readiness has not yet elapsed. The 90-day time period for the People’s readiness began to run when Lewis was committed to the custody of respondent in the criminal action (see, CPL 30.30 [2] [a]). The criminal action commenced with the filing of the felony complaint (see, CPL 1.20 [16] [a]) and "includes the filing of all further accusatory instruments directly derived from the initial one” (CPL 1.20 [16] [b]). Thus, if the indictment herein was "directly derived” from the felony complaint, all of the charges contained in the indictment, including those not contained in the felony complaint, are part of the criminal action commenced by the filing of the felony complaint in which Lewis was committed to the custody of respondent more than 90 days before the People announced their readiness. The *193courts have applied a similar analysis in concluding that a subsequent accusatory instrument relates back to the original one for the purposes of determining the six-month readiness period imposed by CPL 30.30 (1) (a) (see, People v Osgood, 52 NY2d 37; People v Lomax, 50 NY2d 351) and for the purposes of computing excludable time under CPL 30.30 (4) (see, People v Sinistaj, 67 NY2d 236).
The relevant inquiry in determining whether the indictment was "directly derived” from the felony complaint focuses on the criminal transaction alleged in the two accusatory instruments. If the felony complaint and the subsequently filed indictment allege separate and distinct criminal transactions, the latter is not "directly derived” from the former for the purposes of assessing the People’s compliance with their speedy trial obligations (see, People v Schaffer, 200 AD2d 695, Iv denied 83 NY2d 810, 858; People v Murray, 127 AD2d 704, Iv denied 69 NY2d 884; cf., People v Sinistaj, supra). In this case, however, it is clear that the felony complaint and the indictment do not allege separate and distinct criminal transactions.
It is undisputed that the two sodomy counts contained in the indictment charge the same crimes as the two sodomy counts of the felony complaint. It is also clear from the wording of the indictment that all of the crimes charged in the indictment, including the two sodomy counts, are based upon conduct which is comprised of several groups of acts "so closely related and connected in point of time and circumstance of commission as to constitute a single criminal incident” (CPL 40.10 [2] [a]). As the crimes charged in the indictment are based on the same criminal transaction, they are joinable pursuant to CPL 200.20 (2) (a) and, therefore, defendant cannot be separately prosecuted for the crimes (see, CPL 40.40 [1]). In these circumstances, we are of the view that the indictment is "directly derived” from the felony complaint. The additional charges in the indictment are, therefore, included in the criminal action commenced by the filing of the criminal complaint (see, CPL 1.20 [16] [b]). Accordingly, the 90-day period specified in CPL 30.30 (2) (a) for the People to declare their readiness began to run for all charges contained in the indictment when Lewis was committed to the custody of respondent in the criminal action. That the People declared their readiness within 90 days of the filing of the indictment does not, therefore, provide a basis for the dismissal of this proceeding.
Respondent also argues that the proceeding should be dismissed as moot because the People have declared their readi*194ness for trial. The argument is meritless. The legality of a defendant’s pretrial detention is moot once the case is tried (see, People ex rel. Chakwin v Warden, 63 NY2d 120, 125, supra) or when a defendant pleads guilty (see, People ex rel. Ferguson v Campbell, 186 AD2d 319). The issue becomes moot because the defendant is no longer a pretrial detainee, having been either released upon acquittal, in which case habeas corpus relief is not necessary, or incarcerated upon conviction, in which case habeas corpus relief is not available. In this case, however, Lewis is a pretrial detainee and his detention is based solely upon his original commitment to respondent in the criminal action. Clearly, therefore, the legality of his pretrial detention is not moot.
A defendant’s right to release pursuant to CPL 30.30 (2) (a) is triggered by the lapse of the 90-day period specified therein. Nothing in the statutory scheme makes the right dependent upon the People’s continued unreadiness (see, e.g., People ex rel. Chakwin v Warden, supra). Nor does the statute require a defendant to assert the right before the People declare their readiness. Once the 90-day period lapses, a defendant is entitled to release in accordance with the provisions of CPL 30.30 (2), provided that the provisions of CPL 30.30 (3) are not applicable.
For the reasons previously set forth, Supreme Court erred in dismissing the petition without reaching the merits. It is undisputed that the prereadiness delay exceeded 90 days. The matter must be remitted, therefore, for a determination of whether any period of the delay is excludable pursuant to CPL 30.30 (4). If it is found that despite any excludable periods the delay nevertheless exceeded 90 days, Lewis must be released, either on bail at an amount which he is able to meet, or on his own recognizance (see, People ex rel. Chakwin v Warden, supra, at 125).
Mikoll, J. P., Crew III, Yesawich Jr. and Spain, JJ., concur.
Ordered that the judgment is reversed, on the law, without costs, and matter remitted to the Supreme Court for further proceedings not inconsistent with this Court’s decision.