The Prophet Muhammad ﷺ said:

Actions are but by intentions, and everyone will have what he intended. So whoever migrated to Allah and His Messenger, he migrated to Allah and His Messenger. But whoever migrated for some worldly benefit, or to take a woman in marriage, then his migration was only to what he migrated to.

Al-Bukhāri, Muslim and others.

Traditionally, Muslim scholars chose to begin their works by quoting this ḥadīth, or report, from the Messenger of Allah ﷺ. Here is a brief commentary taken from Ibn Rajab’s Jāmiʿ Al-ʿUlūm wa Al-Ḥikam, in which he explains the entire Forty Ḥadīth collection of Al-Nawawi:

Imām Al-Bukhārī (as Al-Nawawi later did in his Forty Ḥadīth) begins his Ṣahīh collection with this ḥadīth, reminding us that any deed through which Allāh’s pleasure is not sought is futile; it will bear no fruits in this life or the hereafter.

ʿAbd Al-Raḥmān b. Mahdī, the great scholar of ḥadīth, said:

If I were to compile a work in chapters, I would place this ḥadīth at the beginning of each one.

He also said:

Whoever wishes to author a book, he should begin with the ḥadīth about intentions.

This ḥadīth forms a fundamental principle of Islām and an axis around which it revolves.

It is reported that Imām Al-Shāfiʿī said:

This ḥadīth constitutes a third of all knowledge, and it relates to seventy areas of fiqh (correct understanding of the religion).

It is reported from Imām Aḥmad that he said:

The foundations of Islām are upon three ḥadīth: the one reported by ʿUmar – ‘Actions are but by intentions’, the one reported by ʿĀʾishah – ‘Whoever does a deed that does not conform to our commands will have it rejected’ and the one reported by Al-Nuʿmān b. Bashīr – ‘The ḥalāl and ḥarām are clear…’

This ḥadīth teaches us the principle that acceptance of our deeds and whether or not they are regarded as righteous depends primarily on what the intention behind them is. If the intention is good and pure – to receive Allāh’s pleasure and reward, the deed is righteous. Otherwise the deed is futile and false. This is the first thing that needs to be dealt with.

The second condition which needs to be met for our deeds to be accepted by Allāh is that they should be in conformity with Islām’s true teachings as taught to us by the Prophet ﷺ and as understood and applied by the Righteous Predecessors (The Salaf). Hence, the Prophet stated:

Whoever does a deed that does not conform to our commands will have it rejected.

Al-Bukhārī and Muslim.