My apologies for the length of this but I think it's important.
There is a misunderstanding as to what is meant by works in Paul's theology..
The Concise Oxford English Dictionary gives several definitions of work. The first and most general is:
“activity involving mental or physical effort done in order to achieve a result.”
By this definition “believing” and “confessing with the lips” is work.
Indeed Jesus says that believing is a work.
Jesus answered them, “This is the work of God, that you believe in him whom he has sent.”
(John 6:29)
St. Paul’s writes much about salvation (justification) and works in his letter to the Romans. A key text is Rom 3:19-28, and a key phrase that Paul uses in this is “works of the law”
20 For no human being will be justified in his sight by works of the law, since through the law comes knowledge of sin.
28 For we hold that a man is justified by faith apart from works of law.
(He also uses the phrase works of the law in Gal 2:1, 3:2, 5 & 10)
This implies that Paul recognises two classes of “works” – works of the law and works that are not works of the law. We’ll come to the latter later. But let us concentrate on what Paul means by works of the law.
In Romans 2 he writes
25 Circumcision indeed is of value if you obey the law; but if you break the law, your circumcision becomes uncircumcision.
And in Gal 3:10
For all who rely on works of the law are under a curse; for it is written, "Cursed be every one who does not abide by all things written in the book of the law, and do them."
Clearly by works of the law Paul is referring to the Jewish law.
The Concise Oxford English Dictionary helpfully gives a definition of this class of works -
“such activity as a means of earning income”.
It is in this sense of earning something that Paul uses the word in Rom 4:4 when he writes:
“Now to one who works, his wages are not reckoned as a gift but as his due.” (Rom 4:4)
Works done under the law are those done under some sort of legal contract that try to put an obligation on God – to make salvation our due. We try to earn our salvation
If we work, as for an employer, expecting wages as our due, then we will be judged under that Law and will always be found wanting and will be condemned.
That is why we can only receive salvation as a gift. It cannot be earned.
“For the wages of sin is death, but the gift of God is eternal life in Christ Jesus our Lord.”
There is another class of works – works that are not works of the law.
The third definition in Concise Oxford English Dictionary is helpful here –
“Theology, good or moral deeds”
Doing “good works” give us merit in the sight of God because they are done out of love and do not attempt to put God under any obligation to reward us.
One definition of merit from the Collins Concise English Dictionary is:
“ a deserving or commendable quality or act.”
When we do something out of love and not as a contract under Law we do a deserving or commendable act and God will graciously reward us.
“love your enemies, and do good, and lend, expecting nothing in return; and your reward will be great, and you will be sons of the Most High” (Lk 6:35)
“I the Lord search the mind and try the heart, to give to every man according to his ways, according to the fruit of his doings.” (Jer 17:10)
“Whoever does good has his reward, which each receives according to his deeds.”(Sir 16:14)
We could give examples of these three definitions of work as follows:
1. – Digging my garden (general definition).
2. – Digging someone else’s garden for a wage (work as earning income)
3. – Digging an elderly neighbour’s garden out of charity (work as a good deed and meritorious – a commendable act)
Paul writes: “For by grace you have been saved through faith, and this is not from you; it is the gift of God; it is not from works, so no one may boast”. (Eph 2:8-9)
Whereas James writes: “What good is it, my brothers, if someone says he has faith but does not have works? Can that faith save him?” (Jas 2:14)
These two are not contradictory if we understand that Paul is referring to works of the law and James is referring to good deeds, meritorious acts, just as in the examples he gives in the following verses:
“If a brother or sister is ill-clad and in lack of daily food, and one of you says to them, "Go in peace, be warmed and filled," without giving them the things needed for the body, what does it profit?”
These are the type of works Jesus refers to in Mt 25:31-45 and Mt 10:41-42
Further, from my examples of digging a garden we can see that it is not the act itself that is good or bad but the cause of the act, the motive. If the act is motivated by love then it is meritorious and God will reward us. If it is driven by other motives (e.g. to get admiration from others) then we may get no reward, at least from God.
“Beware of practicing your piety before men in order to be seen by them; for then you will have no reward from your Father who is in heaven…….” (Mt 6:1 & following verses)