I'm really confused about a hadith
إِنَّمَا الأَعْمَالُ بِالنِّيَّةِ
which means
Actions are (only) dependent upon their intentions.
Does it mean if we have a clean intention, we can do anything, even if it's a sin?
what hadith is referring is that when we do a good deed we need the intention for doing that deed. For example, if someone didn't eat from dawn to dusk without intention to fast but due to some other reason like not availability of food, he does not get reward for fasting. Just like that if a person gives money to poor without intention of paying zakath, it would not be considered as zakath. The hadith was revealed in connection with hijra (emigration).
(The value of) an action depends on the intention behind it. A man will be rewarded only for what he intended. The emigration of one who emigrates for the sake of Allah and His Messenger (ﷺ) is for the sake of Allah and His Messenger (ﷺ) ; and the emigration of one who emigrates for gaining a worldly advantage or for marrying a woman is for what he has emigrated. http://sunnah.com/muslim/33/222
you kind of have the right idea, but not entirely. this hadith doesn't mean you can do whatever you want and tell yourself you had a good intention. What it means is if you had a pure intention to do an act, even though the physical action you did could be counted as a sin, your intention made that sin something good (and vice versa). For example, you two people pay a large sum of sadaqa (say $5000 each). this is a good deed yes? well physically it may seem so, but the truth is only known by Allah SWT. Person A could have payed that $5000 because he saw an ad about deprived orphans, and did so out of the goodness of their heart. Person B however could have payed that $5000 because they want to show to people they have payed so much money. Both did a good deed physically, but their intentions were different, so person A would have gotten the reward for paying $5000 to help the poor, but person B's deed would have been rejected and have no value whatsoever. If anything, they have put themselves in the negative as this is a kind of shirk.
A really good example that relates to this, in the battle of Khandaq, the muslims had dug a huge ditch/trench around themselves for defence so the enemies couldn't get across. A man from the enemy call Amr bin AbuDawud was known for his courage and strength, and he managed to get across. The only muslim not scared to fight him was Ali RA. They fought and after a fierce battle, Ali RA pinned Amr to the ground. He was about to kill him, then Amr spat in his face, Whilst Amr knew he was going to die, Ali instead stood up and walked away. Some people say Ali killed him after Amr got up and tried attacking him again, and some say the Amr reverted to islam after he found out why Ali RA had walked away in the middle of battle. When asked why Ali RA had walked away, he replied that had he killed Amr after he spat in his face, it would have been purely out of anger and not for the sake of Allah SWT. The lesson that is generally learnt from this is the amazing self control that Ali RA had, but we can also relate this to the theme of intentions. Had Ali RA killed Amr after he spat in his face, his intentions would have been revenge, and any other person would say "i did it for the sake of Allah", even though we know this is not true. Ali RA however knew that if he had killed Amr at that point, his intention would have been for revenge, and that would have accounted for that person's unjust death.
Do you see how intention playes a huge role on the deed of a person now? Its not about telling yourself that this deed is good or not, rather what is in your heart and what you know.
In Islam for an action to be accepted, according to scholars there are 2 conditions that need to be meet:
1- The action has be be allowed or permissible act and not considered a sin or mischief. (عمل صالج
2- The action has to be taken with the proper intentions. And that were the Hadith that you have mentioned comes into play.
To understand this more, if you read the Quran, you always see, "الذين امنوا و عملوا صالحا" which is translated as "Those who belief and do good deeds". If you go through the entire Quran, you always see that belief is conjectured with doing good deeds. Same applies for actions that a person does.
And the verse:
وَالَّذِينَ يُؤْتُونَ مَا آتَوا وَّقُلُوبُهُمْ وَجِلَةٌ أَنَّهُمْ إِلَىٰ رَبِّهِمْ رَاجِعُونَ (60)
And the literal translation for it:
And those who commit these actions and their hearts are trembling that they will go back to their Lord.
Aisha (RA) asked the prophet about this verse in the following hadith:
حَدَّثَنَا ابْنُ أَبِي عُمَرَ، حَدَّثَنَا سُفْيَانُ، حَدَّثَنَا مَالِكُ بْنُ مِغْوَلٍ، عَنْ عَبْدِ الرَّحْمَنِ بْنِ سَعِيدِ بْنِ وَهْبٍ الْهَمْدَانِيِّ، أَنَّ عَائِشَةَ، زَوْجَ النَّبِيِّ صلى الله عليه وسلم قَالَتْ سَأَلْتُ رَسُولَ اللَّهِ صلى الله عليه وسلم عَنْ هَذِهِ الآيَةِ : ( والَّذِينَ يُؤْتُونَ مَا آتَوْا وَقُلُوبُهُمْ وَجِلَةٌ ) قَالَتْ عَائِشَةُ أَهُمُ الَّذِينَ يَشْرَبُونَ الْخَمْرَ وَيَسْرِقُونَ قَالَ " لاَ يَا بِنْتَ الصِّدِّيقِ وَلَكِنَّهُمُ الَّذِينَ يَصُومُونَ وَيُصَلُّونَ وَيَتَصَدَّقُونَ وَهُمْ يَخَافُونَ أَنْ لاَ يُقْبَلَ مِنْهُمْ أُولَئِكَ الَّذِينَ يُسَارِعُونَ فِي الْخَيْرَاتِ وَهُمْ لَهَا سَابِقُونَ " . قَالَ وَقَدْ رُوِيَ هَذَا الْحَدِيثُ عَنْ عَبْدِ الرَّحْمَنِ بْنِ سَعِيدٍ عَنْ أَبِي حَازِمٍ عَنْ أَبِي هُرَيْرَةَ عَنِ النَّبِيِّ صلى الله عليه وسلم نَحْوَ هَذَا .
that 'Aishah the wife of the Prophet (ﷺ) said: "I asked about the Messenger of Allah (ﷺ) about this Ayah: And those who give that which they give with their hearts full of fear... (23:60)" 'Aishah said: "Are they those who drink Khamr (Alcohol) and steal (Rob people)?" He said: "No, O daughter of As-Siddiq. They are those who fast, perform Salat, give charity while they fear that their Lord will not accept it from them: It is these who hasten to do good deeds, and they are the foremost of them (23:61)."
This Hadith enforces the idea that only good actions are accepted with good intentions as well.
References:
http://quran.ksu.edu.sa/tafseer/qortobi/sura23-aya60.html
http://qurancomplex.gov.sa/Quran/Targama/Targama.asp?nSora=23&l=arb&nAya=60#23_60