I asked Catholic Answers about this. They gave me a good answer:
Are we saved by faith, works or both?
It depends on what stage of justification we’re talking about. If the initial stage of justification is in question, then our good works have no part to play. As the Catechism of the Catholic Church states:
Since the initiative belongs to God in the order of grace, no one can merit the initial grace of forgiveness and justification, at the beginning of conversion (2010; emphasis in original).
However, if the question refers to the ongoing (Rom. 3:23-24, 5:8-9) and final stages of justification (Rom. 6:16, Gal. 2:16), then works do play a part. This is how St. Paul understands the placement of works:
For by grace you have been saved through faith; and this is not your own doing, it is the gift of God—not because of works, lest any man should boast. For we are his workmanship, created in Christ Jesus for good works, which God prepared beforehand, that we should walk in them (Eph. 2:8-10).
Notice that Paul excludes works only with regard to that initial stage of salvation/justification. After we’re initially justified, then we must carry out the good works that God wills for us.
St. James teaches the same with regard to the corporal works of mercy:
You see that a man is justified by works and not by faith alone (James 2:24).
We also know that works pertain to our final justification, since Jesus teaches in Matthew 25:31-46 that the determining factor for those who go to heaven or hell are those who did and did not do the corporal works of mercy.