كتاب الإيمان
1  
The Book of Faith
(59)
Chapter: If a person thinks of doing a good deed it will be recorded for him, and if he thinks of doing a bad deed it will not be recorded for him
(59)
باب إِذَا هَمَّ الْعَبْدُ بِحَسَنَةٍ كُتِبَتْ وَإِذَا هَمَّ بِسَيِّئَةٍ لَمْ تُكْتَبْ ‏‏
Sahih Muslim 131 b

This hadith has been narrated with another chain of transmitters with the addition of these words:

Allah would even wipe out (the evil committed by a man) and Allah does not put to destruction anyone except he who is doomed to destruction.
وَحَدَّثَنَا يَحْيَى بْنُ يَحْيَى، حَدَّثَنَا جَعْفَرُ بْنُ سُلَيْمَانَ، عَنِ الْجَعْدِ أَبِي عُثْمَانَ، فِي هَذَا الإِسْنَادِ بِمَعْنَى حَدِيثِ عَبْدِ الْوَارِثِ ‏.‏ وَزَادَ ‏ "‏ وَمَحَاهَا اللَّهُ وَلاَ يَهْلِكُ عَلَى اللَّهِ إِلاَّ هَالِكٌ ‏"‏ ‏.‏
Reference : Sahih Muslim 131b
In-book reference : Book 1, Hadith 246
USC-MSA web (English) reference : Book 1, Hadith 238
  (deprecated numbering scheme)