The Prophet Muhammad – Allah’s peace and blessings be upon him – 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 hadīth, or report, from the Messenger of Allah, Muhammad – Allah’s peace and blessings be upon him. Here is a brief commentary taken from Ibn Rajab’s Jāmi’ Al-‘Ulūm wa Al-Hikam, in which he explains the entire Forty Hadīth collection of Al-Nawawi:
Imām Al-Bukhārī (as Al-Nawawi later did in his Forty Hadīth) begins his Sahīh collection with this hadīth, reminding us that any deed through which Allah’s pleasure is not sought is futile; it will bear no fruits in this life or the hereafter.
ʿAbd Al-Rahmān b. Mahdī, the great scholar of hadīth, said, “If I were to compile a work in chapters, I would place this hadīth at the beginning of each one.” He also said, “Whoever wishes to author a book, he should begin with the hadīth about intentions.”
This hadīth forms a fundamental principle of Islām and an axis around which this way of life revolves.
It is reported that Imām Al-Shāfi’ī said, “This hadī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 Ahmad that he said, “The foundations of Islām are upon three hadī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 halāl and harām are clear…’”
This hadī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 Allah’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 Allah is that they should be in conformity with Islām’s true teachings as taught to us by the Prophet – peace and blessing be upon him – and as understood and applied by the Righteous Predecessors. Hence, the Prophet stated:
Whoever does a deed that does not conform to our commands will have it rejected.
Al-Bukhārī and Muslim.