Can an employer recover H-1B costs if I quit early?
Only as bona fide liquidated damages under state law, never as a penalty, and never including the ACWIA fee. Many "repayment" clauses fail those tests.
Only in a narrow way. Department of Labor rules forbid an employer from making you pay a penalty for leaving before an agreed date, but allow it to collect bona fide liquidated damages, and whether a clause is one or the other is decided under your state's law (20 CFR 655.731(c)(10)(i)). Even valid liquidated damages may never include any part of the ACWIA training fee. A clause that says "repay all immigration costs if you leave within two years" often fails one of those tests.
Penalty or liquidated damages
The rule describes the general state-law difference:
Liquidated damages are amounts fixed when the contract is made that are a reasonable estimate of the harm the employer would actually suffer if you left early.
A penalty is a fixed amount that is not a reasonable estimate of that harm, and works instead to punish leaving or keep you from leaving.
A flat $20,000 for leaving in month 23 of a 24-month commitment, with no relation to the employer's real loss, looks like a penalty. A sliding amount tied to actual, documented costs of hiring you looks more like liquidated damages.
What can never be included
The ACWIA fee. The employer may not receive any part of it from you, directly or indirectly, including as part of liquidated damages (20 CFR 655.731(c)(10)(ii)).
Recovery through your wages below the required wage, unless the strict conditions for voluntary deductions are met: your written authorization, a deduction principally for your benefit, and limits on the amount (20 CFR 655.731(c)(9)(iii)).
The petition costs themselves
Attorney fees and other costs of preparing and filing the LCA and the H-1B petition are the employer's business expenses (20 CFR 655.731(c)(9)). An agreement that turns them into a debt you owe on leaving starts from a weak position under the labor rules, and in some states under wage laws as well.
If you are the one being dismissed
If your employer ends your job before your authorized stay ends, it owes the reasonable cost of your return transportation abroad (8 CFR 214.2(h)(4)(iii)(E)). An employer that dismisses you cannot claim early-departure damages for a departure it caused.
A worked case
Your offer letter says you must pay $15,000 if you resign within 18 months, "to cover immigration expenses". You leave after 12 months for a new H-1B employer. The employer's actual filing costs included the $1,500 ACWIA fee, which can never be part of the claim. Whether the rest is enforceable turns on your state's law and whether $15,000 was a reasonable estimate of the employer's loss. You can raise the clause in a Department of Labor complaint, and an employment attorney can tell you how your state treats it.
What to do before signing
Ask for the clause in writing, ask what costs it covers, and check that it excludes the ACWIA fee and the petition and LCA costs. A clause that names a flat amount with no link to real costs is worth questioning before you accept.