¶1 Atlas Supply Inc. appeals the amount of attorney fees and costs the trial court awarded it. Atlas sued Realm Inc. and David L. Follett and Carrie L. Follett (collectively Realm) to recover payment for construction materials sold on credit. Realm asserted counterclaims for breach of contract, breach of warranty, and negligent misrepresentation. Based on an agreement that authorized “the costs of collection, including reasonable attorney fee,” the trial court awarded Atlas only those fees and costs related to its debt collection, not the fees it incurred defending against Realm’s counterclaims. Because the trial court construed the contract’s fee provisions too narrowly when it categorically denied Atlas any fees on the counterclaims, we remand for a recalculation of Atlas’s attorney fees consistent with this opinion.
*236FACTS
¶2 Atlas sells construction and industrial supplies manufactured by third parties. Realm purchased construction materials from Atlas on credit. When the products failed and had to be removed, Realm refused to pay Atlas for the materials. Atlas sued to recover the purchase price, and Realm counterclaimed for breach of contract, breach of warranty, and negligent misrepresentation. Atlas filed a third party complaint, and Realm filed a “fourth party” complaint against Atlas’s suppliers.
¶3 After extensive pretrial litigation, the parties mediated their disputes. The third parties agreed to pay Realm to settle its counterclaims against Atlas, and Atlas agreed to accept a reduced payment from Realm. But Atlas and Realm could not resolve Atlas’s substantial claim for attorney fees. Atlas claimed entitlement to attorney fees and costs under a credit application in which Realm agreed “to pay the costs of collection, including reasonable attorney fee in suit by Atlas Supply, Inc.... for the merchandise sold to applicant.”
¶4 The trial court granted Atlas summary judgment against Realm for the amount it agreed at mediation to pay Atlas. At the hearing on Atlas’s motion, the trial court held that Atlas was entitled only to its reasonable attorney fees and costs necessary to collect the delinquent account, not those incurred defending Realm’s counterclaims. Because Atlas had not segregated its request, the court allowed it an opportunity to resubmit it. Atlas resubmitted its fee request with pleadings arguing that it was entitled to recover all its fees. Because Atlas again had not segregated its request, the trial court denied it any fees. Atlas then filed a motion for reconsideration in which it segregated its request. The trial court granted reconsideration and awarded $56,247.14 in fees and costs. Atlas appeals.
*237ANALYSIS
¶5 Atlas appeals the denial of its attorney fees incurred defending against Realm’s counterclaims, arguing that the credit application entitles it to those fees because that defense was necessary to a successful collection. We review whether the credit application entitles Atlas to recover any attorney fees for defense of Realm’s counterclaims as an issue of law de novo.1
¶6 The attorney fee provision in the credit application submitted by Realm to Atlas provides,
In the event applicant becomes delinquent in his account, applicant agrees that Atlas Supply, Inc. shall have the right to bring suit against the applicant and if this occurs applicant agrees to pay the costs of collection, including reasonable attorney fee in suit by Atlas Supply Inc. or assigns for the merchandise sold to applicant on credit subsequent to the date hereof.
We must determine the scope of attorney fees authorized by this language.
¶7 Atlas argues that the provision entitles it to all fees and costs reasonably incurred to defend against Realm’s compulsory counterclaims because they were necessary for it to succeed on the collection of Realm’s unpaid debt. We agree. Atlas could not prevail on its collection action without defending against Realm’s compulsory counterclaims that, if successful, would have negated its liability on the contract.2
¶8 A compulsory counterclaim is one that “arises out of the transaction or occurrence that is the subject matter of *238the opposing party’s claim.”3 Under CR 13(a), a party must assert its compulsory counterclaims or those claims are forever barred.4 By contrast, a permissive counterclaim is “any claim against an opposing party not arising out of the transaction or occurrence that is the subject matter of the opposing party’s claim.”5 Permissive counterclaims “do not affect, nor are they affected by, the outcome” of the original claim.6
¶9 Atlas relies upon Moritzky v. Heberlein7 to support its position. There, Division Three considered who was the prevailing party in a lien foreclosure action.8 The answer to this question determined who was entitled to an award of fees.9 Moritzky sued to foreclose a mechanic’s lien on a house to collect unpaid labor costs.10 Heberlein counterclaimed for negligence, incomplete work, and building code violations.11 The trial court foreclosed Moritzky’s lien for the full amount requested but awarded Heberlein a greater amount on his counterclaim.12 This resulted in a net judgment in favor of Heberlein.13 The trial court then decided that Heberlein’s claim was an action independent of the lien foreclosure and awarded Moritzky fees as the prevailing party in the foreclosure action.14 Division Three *239reversed.15 Because Heberlein received a net affirmative judgment and his counterclaims were compulsory in the foreclosure action — required to be asserted in that action or lost forever — the court held Heberlein was entitled to an award of fees at trial and on appeal.16
¶10 By contrast, in C-C Bottlers, Ltd. v. J.M. Leasing, Inc.,17 Division Three held that a party was not entitled to attorney fees for successfully defending against the opponent’s permissive counterclaims. C-C Bottlers Ltd. (CCB) sued J.M. Leasing Inc. (JML) to collect two delinquent promissory notes. Both notes provided for recovery of costs and fees for collection.18 JML counterclaimed, alleging securities fraud.19 The trial court ruled in favor of CCB on summary judgment.20 It awarded CCB fees for the entire litigation after finding that JML’s counterclaims were “ ‘substantially interwoven and inseparable’ ” from CCB’s action on the notes.21
¶11 Division Three disagreed. It described JML’s securities fraud claims as “independent and unrelated claims asserted permissively”22 and noted that the fraud claims did not affect and would not affect the outcome of the promissory note claims.23 It then explained,
“[T]he prevailing party should be awarded attorney fees only for the legal work completed on the portion of the claim permitting such an award”, because while collateral claims may well be related to the contract claim and therefore conve*240niently tried together, they need not be resolved in order to decide the primary claim. Allowing recovery of fees for actions which do not authorize attorney fees would also give the prevailing party an unfair and unbargained for benefit.[24]
¶12 Here, as in Moritzky, Realm’s counterclaims were compulsory. They arose out of the same purchase transaction that led to Atlas’s original debt collection action. If successful, they would have defeated Atlas’s claim on the debt. Thus, they had to be resolved for Atlas to prevail on its collection action. In addition, Atlas could not have presented evidence supporting its claim without the evidence to defend against the counterclaims. The trial court erred by ruling the credit application did not entitle Atlas to fees relating to the compulsory counterclaims.25
¶13 Realm contends that Moritzky “is not on point” because it considered the compulsory nature of counterclaims in the context of a statute not applicable to this case. Realm offers no persuasive explanation why this distinction affects the precedential value of Moritzky on the issue before us, and we perceive none.
¶14 Realm also relies upon Seaborn Pile Driving Co. v. Glew26 and Hindquarter Corp. v. Property Development Corp 27 In Seaborn, the court addressed the effect of a CR 68 offer of judgment. Its decision turned upon the language of the parties’ contract and provides no guidance on the issue before us. In Hindquarter, the court reversed that portion of a trial court decision awarding attorney fees to a landlord incurred defending against a declaratory judg*241ment action initiated by the tenant to establish its right to exercise a lease renewal option. While the landlord also prevailed on a counterclaim for restitution, the court’s opinion does not indicate whether the landlord recovered fees for prosecuting that counterclaim. The opinion does not address the issue we decide in this case.
Attorney Fees on Appeal
¶15 Both parties request attorney fees on appeal. A contract that provides for attorney fees at trial also supports such an award on appeal.28 The credit application provides for attorney fees in a collection action. Because Atlas has prevailed on appeal, it is entitled to reasonable fees and costs.
CONCLUSION
¶16 We remand for calculation by the trial court of attorney fees to be awarded to Atlas, both at the trial court and on appeal, consistent with this opinion.
Becker and Dwyer, JJ., concur.Reconsideration granted and opinion modified August 20, 2012.
Ethridge v. Hwang, 105 Wn. App. 447, 460, 20 P.3d 958 (2001).
See Moritzky v. Heberlein, 40 Wn. App. 181, 183-84, 697 P.2d 1023 (1985) (considering the outcome of compulsory counterclaims in determining award of statutory attorney fees to prevailing party).
CR 13(a).
Krikava v. Webber, 43 Wn. App. 217, 219, 716 P.2d 916 (1986).
CR 13(b).
C-C Bottlers, Ltd. v. J.M. Leasing, Inc., 78 Wn. App. 384, 387, 896 P.2d 1309 (1995).
40 Wn. App. 181, 697 P.2d 1023 (1985).
Moritzky, 40 Wn. App. at 182-83.
Moritzky, 40 Wn. App. at 183.
Moritzky, 40 Wn. App. at 182.
Moritzky, 40 Wn. App. at 182.
Moritzky, 40 Wn. App. at 182.
Moritzky, 40 Wn. App. at 182.
Moritzky, 40 Wn. App. at 182.
Moritzky, 40 Wn. App. at 181.
Moritzky, 40 Wn. App. at 183-84.
78 Wn. App. 384, 390, 896 P.2d 1309 (1995).
C-C Bottlers, 78 Wn. App. at 386.
C-C Bottlers, 78 Wn. App. at 386.
C-C Bottlers, 78 Wn. App. at 386.
C-C Bottlers, 78 Wn. App. at 387.
C-C Bottlers, 78 Wn. App. at 388.
C-C Bottlers, 78 Wn. App. at 387.
C-C Bottlers, 78 Wn. App. at 389 (alteration in original) (citation omitted) (quoting King County v. Squire Inv. Co., 59 Wn. App. 888, 897, 801 P.2d 1022 (1990)).
Additionally, we note that the court correctly denied Atlas’s fee request for defending Realm’s claims that were brought on behalf of the State of Washington. Because the State was not a party to the original contract, its claims cannot be part of the action on which Atlas is entitled to fee recovery.
132 Wn. App. 261, 264, 131 P.3d 910 (2006).
95 Wn.2d 809, 810, 631 P.2d 923 (1981).
Reeves v. McClain, 56 Wn. App. 301, 311, 783 P.2d 606 (1989).