
    Mark Edwin COOK, Petitioner-Appellant, v. Norm MALENG, King County Prosecuting Attorney; Amos E. Reed, Secretary of the Washington State Department of Social & Health Services; Kenneth O. Eikenberry, Attorney General, Respondents-Appellees.
    No. 86-4151.
    United States Court of Appeals, Ninth Circuit.
    Argued and Submitted March 8, 1988.
    Decided June 2, 1988.
    
      John Midgley, Smith, Midgley & Pump-lin, Seattle, Wash., for petitioner-appellant.
    Charles S. Faddis, Asst. Atty. Gen., Olympia, Wash., for respondents-appellees.
    Before TANG and CANBY, Circuit Judges, and CURTIS, District Judge.
    
      
      The Honorable Jesse W. Curtis, Senior United States District Judge for the Central District of California, sitting by designation.
    
   PER CURIAM:

Mark Edwin Cook, a federal prisoner, appeals pro se the dismissal for lack of subject matter jurisdiction of his 28 U.S.C. § 2254 habeas petition. Cook alleges that the district court erred in finding that he was not sufficiently “in custody” to confer subject matter jurisdiction over his challenge to a 1958 state conviction. We agree.

BACKGROUND

Cook is currently serving a 30-year federal sentence for bank robbery and conspiracy. In 1958, a jury in Washington state court convicted Cook of three counts of armed robbery; the state sentenced Cook to three concurrent 20-year terms of imprisonment and paroled him in 1962.

While on parole in 1965, Cook was convicted in Washington state court of three counts of robbery, and sentenced to three concurrent 50-year terms; he was paroled from this sentence in 1973. In 1976, while on parole, Cook was convicted of the federal crimes leading to his current incarceration.

Cook also was convicted in Washington state court in 1976 of two counts of first-degree assault and one count of aiding a prisoner to escape. In 1978, the state sentenced Cook to two life terms and one ten-year term of imprisonment; Cook’s sentence was lengthened by two and one-half years because of his prior convictions. Because Cook could not serve that sentence until his release from federal incarceration, the Washington Department of Prisons placed a detainer on him, requesting the federal prison to notify the state when Cook’s federal term expires.

Cook filed this habeas petition in 1985, alleging that his 1958 conviction had been used illegally to enhance both the 1976 federal and 1978 state sentences. The district court granted the state’s motion to dismiss the petition. Cook timely filed a notice of appeal, and this court issued a certificate of probable cause.

ANALYSIS

This court reviews de novo the district court’s dismissal for lack of subject matter jurisdiction. See Bright v. Bechtel Petroleum, Inc., 780 F.2d 766, 768 (9th Cir.1986).

The district court has jurisdiction over habeas petitions under 28 U.S.C. § 2241, which provides, in part:

(c) The writ of habeas corpus shall not extend to a prisoner unless.... (3) He is in custody in violation of the Constitution or laws or treaties of the United States ...

28 U.S.C. § 2241(c) (emphasis added); see also 28 U.S.C. § 2254(c). Cook contends that the district court had jurisdiction to adjudicate his challenge to his 1958 conviction because that conviction was used to enhance the sentences for the 1976 federal and state convictions. The state argues that Cook was not “in custody” for the purpose of attacking the 1958 conviction when he filed his federal habeas petition in 1985 because the 20-year sentence for Cook’s 1958 conviction had expired in 1978.

When he filed this federal habeas petition in 1985, Cook was under a state detain-er to serve his 1978 state sentence. The district court clearly had subject matter jurisdiction over Cook’s attack on his 1978 sentence and the state concedes this point. Rose v. Morris, 619 F.2d 42, 43 (9th Cir.1980); Peyton v. Rowe, 391 U.S. 54, 67, 88 S.Ct. 1549, 1556, 20 L.Ed.2d 426 (1968) (“[A] prisoner serving consecutive sentences is ‘in custody’ under any one of them ...”).

This circuit has not previously decided whether satisfaction of the custody requirements to allow an attack on a current sentence necessarily satisfies the custody requirements to allow an attack on an earlier conviction used to enhance the sentence for the later conviction. We agree with the reasoning of those courts that have held that a prisoner “in custody” under one conviction is “in custody” to attack an earlier conviction used to enhance the sentence for the later conviction. See. e.g., Anderson v. Smith, 751 F.2d 96, 100 (2d Cir.1984) (where a prior conviction “may lengthen [the prisoner’s] time in prison, he is ‘in custody’ pursuant to that conviction for the purposes of habeas corpus jurisdiction”); Harrison v. Indiana, 597 F.2d 115, 116-17 (7th Cir.1979) (jurisdiction to hear attack on a conviction if its invalidation would shorten current incarceration); Lyons v. Brierly, 435 F.2d 1214, 1215-16 (3d Cir.1970) (habeas jurisdiction over attack on prior conviction); Capetta v. Wainwright, 406 F.2d 1238, 1239 (5th Cir.) (jurisdiction over attack on first conviction if current sentence reduced by invalidation), cert. denied, 396 U.S. 846, 90 S.Ct. 55, 24 L.Ed.2d 96 (1969); cf. Ward v. Knoblock, 738 F.2d 134, 139 (6th Cir.1984) (a prisoner is “in custody” to attack an illegally enhanced impending federal sentence in a 28 U.S.C. § 2255 proceeding), cert. denied, 469 U.S. 1193, 105 S.Ct. 970, 83 L.Ed.2d 974 (1985).

The magistrate, whose recommendation forms the basis of the district court’s decision, relied on Harris v. Ingram, 683 F.2d 97, 98 (4th Cir.1982), a case distinguishable from the instant appeal. Harris involved an attack only on a federal sentence which was dismissed because it should have been brought in a 28 U.S.C. § 2255 proceeding. Moreover, the district court’s reliance on Ward v. Knoblock, 738 F.2d 134 (6th Cir.1984), cert. denied, 469 U.S. 1193, 105 S.Ct. 970, 83 L.Ed.2d 974, is also misplaced. In Ward, the court held that a prisoner is not “in custody” to attack a conviction where that conviction has been fully served and no longer places any “meaningful” restraint on the prisoner. Ward, 738 F.2d at 138. The court went on to conclude, however, that a prisoner is in custody to attack the legality of a sentence not yet served because a pending incarceration is a meaningful restraint. Ward, 738 F.2d at 139. Here, Cook is under a detainer because of a state conviction which was lengthened because of his 1958 conviction; Cook is thus meaningfully restrained by the 1958 conviction.

In this case the state used Cook’s 1958 conviction to enhance his 1978 sentence. See Wash.Rev. Code §§ 9.95.040 (1988), 9.41.025 (repealed 1984) (enhancement statutes); see also, Wash.Rev. Code § 10.01.040 (1980 & Supp.1988) (general criminal penalty “savings” statute). Cook is challenging the use of the 1958 conviction to enhance that sentence. If the 1958 conviction is invalid, it should not have been used to enhance the 1978 sentence. See State v. Gonzales, 103 Wash.2d 564, 567, 693 P.2d 119, 121 (1985) (state must prove validity of prison conviction used to enhance sentence); State v. Barnes, 42 Wash.App. 56, 57, 708 P.2d 414, 415 (1985). If the enhancement of the 1978 sentence is invalid, the length of Cook’s impending state imprisonment might be reduced by as much as seven and one-half years. See Wash.Rev.Code §§ 9.95.040(2), 9.41.025. Therefore, because Cook’s 1958 conviction lengthened his 1978 sentence, Cook is “in custody” for the purposes of a habeas corpus attack on the 1958 conviction, and the district court erred in dismissing Cook’s petition for want of subject matter jurisdiction. See 28 U.S.C. § 2241(c)(3), 2254(b); Anderson, 751 F.2d at 100.

We do not hold that jurisdiction afforded by section 2254(a) extends to all constitutional challenges to prior convictions upon a showing of some unfavorable collateral consequence flowing from the challenged conviction. The question presented for our decision is a narrow one, namely, whether the custody requirement for habeas corpus relief is satisfied where a prisoner’s prior conviction, although expired, is used to enhance the sentence on a current or future term. We conclude the custody requirement is satisfied in such a case. Where the state uses a prior conviction to enhance a present or future sentence, fairness requires that such restraints on individual liberty be justified. See Hensley v. Municipal Court, 411 U.S. 345, 350-51, 93 S.Ct. 1571, 1574, 36 L.Ed.2d 294 (1973).

The judgment is REVERSED and the case is REMANDED. 
      
      . Cook challenges the 1958 conviction on the ground that he was never given a competency hearing, even though the trial judge found that there was reasonable doubt as to Cook's competence to stand trial. The merits of that claim are not at issue in this appeal.
     
      
      . The state also argues that the enhancement argument goes to the issue of “mootness” rather than the "in custody” requirement. See Carafas v. LaVallee, 391 U.S. 234, 238, 88 S.Ct. 1556, 1560, 20 L.Ed.2d 554 (1968). Those cases which treat the problem of "collateral consequences” as a mootness issue do not involve sentence enhancement, but instead the civil or other ramifications of a conviction and sentence where the prisoner has been released from state custody. See e.g., Lane v. Williams, 455 U.S. 624, 630-31, 102 S.Ct. 1322, 1326, 71 L.Ed.2d 508 (1982); Aaron v. Pepperas, 790 F.2d .1360, 1361 (9th Cir.1986). The 1958 conviction was used to increase the length of a term of imprisonment Cook has yet to serve, such a “collateral consequence” establishes the district court’s subject matter jurisdiction over a challenge to the 1958 conviction.
      This proposition also finds support in this court’s recent decision in Myers v. Parole Commission, 813 F.2d 957 (9th Cir.1987). In Myers, this court noted, in dicta, that ”[w]e have also held that the collateral consequences of a conviction may in some cases be sufficient to satisfy the ‘in custody1 requirement even though the habeas petitioner is not in custody for the conviction he seeks to challenge when he files the habeas petition.” Myers, 813 F.2d at 959; see Braun v. Rhay, 416 F.2d 1055, 1059 (9th Cir.1969); Arketa v. Wilson, 373 F.2d 582, 584-85 (9th Cir.1967) The state in Myers made an argument almost identical to the state’s argument here. See Case file in No. 85-6264, Appel-lee’s Brief at 4-6.
     