
518 F.3d 1067 (2008)
Patricia D. SHAFER, Plaintiff-Appellant,
v.
Michael J. ASTRUE,[*] Commissioner of the Social Security Administration, Defendant-Appellee.
No. 05-16507.
United States Court of Appeals, Ninth Circuit.
Submitted August 17, 2007[**]
Filed March 10, 2008.
*1068 Mark Caldwell, Caldwell & Ober, P.L.L.C., Phoenix, AZ, for plaintiff-appellant.
Peter D. Keisler, Assistant Attorney General; Paul K. Charlton, United States Attorney; Lucille Gonzales Meis, Regional Chief Counsel, Region IX; Theophous H. Reagans, Assistant Regional Counsel, Social Security Administration, for defendant-appellee.
Before: HARRY PREGERSON, EUGENE E. SILER, JR.,[***] and CARLOS T. BEA, Circuit Judges.
BEA, Circuit Judge:
Patricia D. Shafer ("Shafer") appeals the district court's order denying her motion for attorneys' fees under the Equal Access to Justice Act ("EAJA"), 28 U.S.C. § 2412, in a social security disability action. We have jurisdiction pursuant to 28 U.S.C. § 1291. We hold the district court abused its discretion in denying Shafer's motion because the government's defense of the procedural errors in the administrative law judge's opinion was not substantially justified. Accordingly, we reverse the district court's order and remand for a determination of the amount of attorneys' fees.

I.
Shafer was employed as an audit clerk for Hallmark Cards for approximately 37 years. On February 14, 2000, Shafer filed an application for social security disability benefits with the Commissioner of the Social Security Administration ("Commissioner"). The Commissioner denied Shafer's application. Shafer then sought review of the Commissioner's decision by an administrative law judge ("ALJ").
After a hearing, the ALJ denied Shafer's application for disability benefits. The ALJ found Shafer suffers from asthma, migraine headaches, degenerative disc disease, and gastroesophageal reflux disease. The ALJ concluded, however, Shafer was not disabled within the meaning of the Social Security Act, 42 U.S.C. §§ 1381, et seq., because she retained the residual functional capacity for sedentary work and could perform her past relevant work as an audit clerk. The Social Security Administration's Appeals Council denied Shafer's request for review of the ALJ's *1069 decision, leaving the ALJ's decision to stand as the final decision of the Commissioner.
The district court affirmed the ALJ's decision, and Shafer appealed to this court. A panel of this court reversed the district court's decision and remanded the case to the Commissioner for further proceedings, holding the ALJ's decision was "infected" with procedural errors. See Shafer v. Barnhart, 120 Fed.Appx. 688, 692 (9th Cir. 2005) (unpublished memorandum disposition). Specifically, the court identified four procedural errors.
First, the court held the ALJ erred in rejecting Dr. Clifford J. Harris, Jr.'s diagnoses. See id. at 692-94. Dr. Harris, a non-examining medical expert, opined at the administrative hearing Shafer suffers from "anxiety and hyperventilation syndrome which, in turn, causes her to be `very fatigued.'" Id. at 692. Nevertheless, the ALJ disregarded, without explanation or further development of the record, "that portion of Dr. Harris'[s] opinion regarding anxiety induced hyperventilation syndrome resulting in fatigue." Id. at 693. In doing so, the ALJ contravened governing regulations requiring him to develop the record when there is evidence of a medically determinable mental impairment and evaluate every medical opinion received. Id. (citing 20 C.F.R. § 404.1529;[1] 20 C.F.R. § 404.1527(d)[2]).
Second, the court held the ALJ erred in rejecting, without providing clear and convincing evidence, treating physician Dr. Kirk Butler's opinion regarding Shafer's non-exertional limitations. Id. at 694-95. Dr. Butler opined Shafer "suffers from moderately severe impairments that frequently cause her to experience deficiencies of concentration, persistence, and pace which manifest themselves in failure to complete tasks in a timely manner." Id. at 694. Mr. Nathan Dean, a vocational expert, testified "all work activity would be precluded for an individual suffering from these impediments." Id. The ALJ rejected Dr. Butler's opinion because "according to Dr. Harris the limitations of Dr. Butler are not consistent with his treatment notes and with the objective evidence of record. . . ." Id. This court held the ALJ's rejection of Dr. Butler's opinion contravened governing law requiring the ALJ to provide clear and convincing reasons supported by substantial evidence to reject the uncontroverted opinion of a treating physician. Id. (citing Lester v. Chater, 81 F.3d 821, 830-31 (9th Cir.1996)).[3]
Third, the court held the ALJ erred in failing to provide clear and convincing reasons for discrediting Shafer's subjective complaints. Id. at 695-96. Shafer testified at the administrative hearing she was "forced to lie down two to three hours per day as a result of fatigue, and that she felt she could no longer function at her job because of numerous daily coughing spells, *1070 stress-induced incontinence, and back pain." Id. The court agreed with the ALJ that Shafer's statements regarding the impact of her impairments on her ability to work were "not entirely credible." Id. at 696. Nevertheless, the court held the ALJ committed legal error in failing to specify which parts of Shafer's testimony were not credible and what evidence in the record undermined such testimony. Id. (citing Reddick v. Chater, 157 F.3d 715, 722 (9th Cir.1998)).
Fourth, the court held the ALJ erred in assessing Shafer's residual functional capacity. Id. at 696-98. Specifically, the ALJ had erroneously assessed Shafer's "residual functional capacity for the exertional demands of work in categorical terms instead of providing a function-by-function assessment"; "failed to provide any assessment of her non-exertional residual functional capacity"; failed adequately to consider fatigue; and blindly adopted the residual functional capacity assessment of Dr. Harris, a non-treating, non-examining medical expert, even though Dr. Harris's assessment was contradicted by the evidence in the record. Id. at 697-98. Thus, the ALJ's residual functional capacity analysis fell "far short of what the Social Security Regulations and accompanying Rulings require[d]." Id. at 697.
The court noted the procedural errors "permeating the ALJ's opinion in this case cannot be ignored" and that it was not possible to discern the bases for the ALJ's conclusions. Id. at 698. The court, without expressing any opinion on the merits of Shafer's application for benefits, reversed the district court and remanded the case to the Commissioner for further proceedings. Id.
On remand, Shafer filed a motion for attorneys' fees in district court under the EAJA, contending the government's defense of the ALJ's procedurally flawed decision was not substantially justified. The district court denied Shafer's motion, holding "the parties in this matter were engaged in a `genuine dispute,' over an issue about which `reasonable people' could disagree." The district court reasoned this court, in reversing the district court's decision affirming the denial of benefits to Shafer, had not concluded "as a matter of law, that [Shafer] was disabled or that the ALJ had erred in determining that [Shafer] was not disabled; [this court had] focused on the sufficiency of the ALJ's explanation for his conclusion, not the evidentiary record."[4] Therefore, the district court held the government's position was substantially justified and Shafer was not entitled to an award of attorneys' fees under the EAJA. Shafer's timely appeal to this court followed.

II.
We review the district court's denial of a motion for attorneys' fees under the EAJA for abuse of discretion. Corbin v. Apfel, 149 F.3d 1051, 1052 (9th Cir. 1998). A district court abuses its discretion if it "base[s] its ruling on an erroneous view of the law or on a clearly erroneous assessment of the evidence." Cooter & Gell v. Hartmarx Corp., 496 U.S. 384, 405, 110 S.Ct. 2447, 110 L.Ed.2d 359 (1990).

III.
The EAJA states, in relevant part:

*1071 [A] court shall award to a prevailing party other than the United States fees and other expenses . . . incurred by that party in any civil action (other than cases sounding in tort), including proceedings for judicial review of agency action, brought by or against the United States in any court having jurisdiction of that action, unless the court finds that the position of the United States was substantially justified or that special circumstances make an award unjust.
28 U.S.C. § 2412(d)(1)(A) (emphases added).[5] "Fees and other expenses" include "reasonable attorney fees." Id. § 2412(d)(2)(A). It is undisputed Shafer was the "prevailing party" in the first appeal to this court. Therefore, the only question is whether the government's position in Shafer's appeal from the ALJ's denial of social security disability benefits was "substantially justified."
"`Substantial justification' under the EAJA means that the government's position must have a reasonable basis in law and fact." Corbin, 149 F.3d at 1052. "The government's position must be substantially justified at each stage of the proceedings." Id. (citation and internal quotation marks omitted). Where, as here, the ALJ's decision was reversed on the basis of procedural errors, the question is not whether the government's position as to the merits of Shafer's disability claim was substantially justified. See id. at 1052-53. Rather, the relevant question is whether the government's decision to defend on appeal the procedural errors committed by the ALJ was substantially justified.[6]See id. at 1053.
Our decision in Corbin is instructive. The district court affirmed an ALJ's denial of Corbin's claim for social security disability benefits. Id. at 1052. On appeal, this court reversed and remanded the case to the Commissioner for further proceedings because the ALJ committed two errors. Id. Specifically, the ALJ failed to determine: (1) whether Corbin's testimony regarding "excess pain" she suffered as a result of her impairments was credible; and (2) whether a doctor, who had ordered Corbin not to lift more than 5 pounds, intended the lifting restriction to be temporary or permanent. Id. On remand, Corbin filed a motion for attorneys' fees under the EAJA, which the district court denied. Id. The district court held because there was "some evidence" to support the ALJ's denial of benefits, and the ALJ had merely failed properly to evaluate that evidence, the government's position was "substantially justified." Id.
On appeal, this court reversed, holding the district court erred in considering whether the government's position on the ultimate issue of Corbin's disability was substantially justified. Id. at 1053. Rather, the district court should have determined whether the government was substantially justified in defending the ALJ's procedural errors. Id. The court held the procedural errors committed by the ALJ "a failure to make findings and weigh evidence"were "serious." Id. at 1053. Corbin's testimony regarding excessive pain could be discredited only by specific findings, which were lacking. Id. While the government's defense on appeal of a procedural error did not automatically justify an award of attorneys' fees, "the defense of basic and fundamental errors such *1072 as the ones in the present case" lacked substantial justification. Id.
In this case, the ALJ committed the same fundamental procedural errors as the ALJ in Corbin. The ALJ failed to provide clear and convincing reasons for discrediting Shafer's subjective complaints and failed to make any findings regarding Dr. Harris's diagnosis of anxiety induced hyperventilation syndrome resulting in fatigue. Further, the ALJ in this case committed procedural errors that were absent in Corbin. The ALJ rejected a treating physician's opinion in favor of a non-treating physician's opinion without providing clear and convincing reasons, and committed several errors in assessing Shafer's residual functional capacity. It follows a fortiori the government's defense of the ALJ's procedural errors was not substantially justified, and Shafer is entitled to attorneys' fees under the EAJA.
Accordingly, we reverse the district court's order denying Shafer's motion for attorneys' fees under the EAJA, and remand for a determination of the amount of attorneys' fees. See id. at 1053.
REVERSED AND REMANDED.
NOTES
[*]  Michael J. Astrue is substituted for his predecessor Jo Anne Barnhart as Commissioner of the Social Security Administration. Fed. R.App. P. 43(c)(2).
[**]  The panel unanimously finds this case suitable for decision without oral argument. See Fed. R.App. P. 34(a)(2).
[***]  The Honorable Eugene E. Siler, Jr., Senior United States Circuit Judge for the Sixth Circuit, sitting by designation.
[1]  "We will develop evidence regarding the possibility of a medically determinable mental impairment when we have information to suggest that such an impairment exists. . . ." 20 C.F.R. § 404.1529(b).
[2]  "Regardless of its source, we will evaluate every medical opinion we receive." 20 C.F.R. § 404.1527(d).
[3]  The court noted the ALJ "appears to have treated Dr. Butler's opinion as controverted by the testimony of Dr. Harris, the non-examining medical expert." Shafer, 120 Fed. Appx.at 694. The court held, however, this treatment was factually incorrect because Dr. Harris "did not comment upon, let alone contradict," Dr. Butler's assessment that Shafer's impairments resulted in an inability to concentrate and complete tasks in a timely manner. Id. at 695. Further, the ALJ failed to describe "how or why Dr. Butler's treatment notes do not support his uncontroverted opinion." Id.
[4]  The district court was incorrect in stating this court in the first appeal did not hold the ALJ erred in finding Shafer was not disabled. Although this court did not address the merits of Shafer's application for benefits, it held the ALJ erred, as a matter of law, in finding Shafer was not disabled because the ALJ committed procedural errors in reaching that determination. See Shafer, 120 Fed.Appx.at 692.
[5]  The government does not contend there are "special circumstances [that] make an award unjust" in this case. See 28 U.S.C. § 2412(d)(1)(A).
[6]  Accordingly, the district court committed an error of law, and thus abused its discretion, in viewing the relevant question as whether the government was substantially justified in contending Shafer was not disabled. See Cooter & Gell, 496 U.S. at 405, 110 S.Ct. 2447.
