                     FOR PUBLICATION
  UNITED STATES COURT OF APPEALS
       FOR THE NINTH CIRCUIT

PATRICIA D. SHAFER,                        
               Plaintiff-Appellant,
                                                  No. 05-16507
                v.
MICHAEL J. ASTRUE,*                                D.C. No.
                                                CV-02-00774-MEA
Commissioner of the Social
                                                     OPINION
Security Administration,
              Defendant-Appellee.
                                           
         Appeal from the United States District Court
                  for the District of Arizona
         Mark E. Aspey, Magistrate Judge, Presiding

                  Submitted August 17, 2007**
                    San Francisco, California

                       Filed March 10, 2008

    Before: Harry Pregerson, Eugene E. Siler, Jr.,*** and
               Carlos T. Bea, Circuit Judges.

                      Opinion by Judge Bea




  *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.

                                 2241
                     SHAFER v. ASTRUE                  2243


                        COUNSEL

Mark Caldwell, Caldwell & Ober, P.L.L.C., Phoenix, Ari-
zona, for the plaintiff-appellant.

Peter D. Keisler, Assistant Attorney General; Paul K. Charl-
ton, United States Attorney; Lucille Gonzales Meis, Regional
2244                   SHAFER v. ASTRUE
Chief Counsel, Region IX; Theophous H. Reagans, Assistant
Regional Counsel, Social Security Administration, for the
defendant-appellee.


                          OPINION

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 determina-
tion 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 appli-
cation. 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, how-
ever, 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
                          SHAFER v. ASTRUE                         2245
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 decision, leaving the
ALJ’s decision to stand as the final decision of the Commis-
sioner.

   The district court affirmed the ALJ’s decision, and Shafer
appealed to this court. A panel of this court reversed the dis-
trict court’s decision and remanded the case to the Commis-
sioner for further proceedings, holding the ALJ’s decision
was “infected” with procedural errors. See Shafer v. Barnhart,
120 F. App’x 688, 692 (9th Cir. 2005) (unpublished memo-
randum 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 hear-
ing Shafer suffers from “anxiety and hyperventilation syn-
drome which, in turn, causes her to be ‘very fatigued.’ ” Id.
at 692. Nevertheless, the ALJ disregarded, without explana-
tion 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
  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).
2246                       SHAFER v. ASTRUE
Dr. Kirk Butler’s opinion regarding Shafer’s nonexertional
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 voca-
tional 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 pro-
vide 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 subjec-
tive complaints. Id. at 695-96. Shafer testified at the adminis-
trative 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 cough-
ing spells, 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
  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 F. App’x at 694. The court held, however, this treat-
ment 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 man-
ner. Id. at 695. Further, the ALJ failed to describe “how or why Dr. But-
ler’s treatment notes do not support his uncontroverted opinion.” Id.
                       SHAFER v. ASTRUE                    2247
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 assess-
ment”; “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 assess-
ment 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 mer-
its 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 dis-
trict 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 peo-
ple’ 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 determin-
ing that [Shafer] was not disabled; [this court had] focused on
2248                        SHAFER v. ASTRUE
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 attor-
neys’ 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 (1990).

                                    III.

   [1] The EAJA states, in relevant part:

      [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 juris-
      diction of that action, unless the court finds that the
      position of the United States was substantially justi-
      fied or that special circumstances make an award
      unjust.
  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 dis-
abled because the ALJ committed procedural errors in reaching that deter-
mination. See Shafer, 120 F. App’x at 692.
                           SHAFER v. ASTRUE                          2249
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 ben-
efits was “substantially justified.”

   [2] “ ‘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 posi-
tion must be substantially justified at each stage of the pro-
ceedings.” 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 govern-
ment’s position as to the merits of Shafer’s disability claim
was substantially justified. See id. at 1052-53. Rather, the rel-
evant 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 pro-
ceedings because the ALJ committed two errors. Id. Specifi-
cally, 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
  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 gov-
ernment was substantially justified in contending Shafer was not disabled.
See Cooter & Gell, 496 U.S. at 405.
2250                    SHAFER v. ASTRUE
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 “sub-
stantially 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 justi-
fied. Id. at 1053. Rather, the district court should have deter-
mined 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 discred-
ited 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 as the ones in
the present case” lacked substantial justification. Id.

   [3] In this case, the ALJ committed the same fundamental
procedural errors as the ALJ in Corbin. The ALJ failed to pro-
vide clear and convincing reasons for discrediting Shafer’s
subjective complaints and failed to make any findings regard-
ing 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 con-
vincing 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.

  [4] Accordingly, we reverse the district court’s order deny-
ing Shafer’s motion for attorneys’ fees under the EAJA, and
                     SHAFER v. ASTRUE                  2251
remand for a determination of the amount of attorneys’ fees.
See id. at 1053.

  REVERSED AND REMANDED.
