Does the shaytan (devil) know what crosses our minds of ideas which no one knows except Allah and thus whisper to us what is in accordance with our thoughts, or what?
The sound evidence indicates that the shaytan is close to man, and indeed he flows through him like blood, so he whispers to him at moments of heedlessness and withdraws from him when he remembers Allah. Through this constant closeness he knows what whims and desires occur to man, so he makes them appear attractive to him and he whispers to him regarding them.
Al-Bukhari and Muslim narrated from Safiyyah bint Huyayy (may Allah be pleased with her) that the Prophet (peace and blessings of Allah be upon him) said: “The shaytan flows through man like blood.”
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said: They smell a good smell or a bad smell [meaning the angels, who smell a good smell when a person is thinking of a good deed, as was narrated from Sufyan ibn ‘Uyaynah]. But the devils do not need that [smell] in order to know; rather they even know what is in the heart of the son of Adam, and they see and hear what he says to himself. Moreover, the devil has full control over man’s heart, then when man remembers Allah he withdraws, and when he neglects to remember Him, he whispers to him. He knows whether he is remembering Allah or is neglecting to remember Him, and he knows the whims and desires of his heart and makes them appear attractive to him.
It is proven in al-Saheeh, in the hadeeth (narration) mentioned by Safiyyah (may Allah be pleased with her) that the Prophet (peace and blessings of Allah be upon him) said: “The shaytan flows through the sons of Adam like blood.”
The closeness of the angels and the shaytan to the heart of the son of Adam is something that is confirmed in many reports, whether the person is a believer or a disbeliever. End quote from Majmoo’ al-Fatawa.
The shaytan is aware of what a person is thinking to himself, and he knows his inclinations and his whims and desires, both good and bad, so he whispers to him accordingly.
Shaykh Ibn Baz (may Allah have mercy upon him) was asked -- in a lengthy question --: If I intend in my heart to do something good, does the shaytan know and try to divert me from it?
He replied: Every person has a devil and an angel with him, as the Prophet (peace and blessings of Allah be upon him) said: “There is no one who does not have a companion from among the jinn and a companion from among the angels.” They said: Even you, O Messenger of Allah? He said: “Even me, but Allah helped me with him and he became Muslim (or: and I am safe from him), so he only enjoins me to do that which is good.” And he (peace and blessing of Allah be upon him) told us that the shaytan dictates evils to man and calls him to evil, and he has some control over his heart. And he can see, by Allah's will, what a person wants and intends to do of both good and bad deeds. The angel also has some control over his heart that makes him inclined towards good and calls him to good. This control is something that Allah has enabled them to have, i.e., He has given some power to the companions from among the jinn and from among the angels; even the Prophet (peace and blessings of Allah be upon him) had a shaytan with him who was the companion from among the jinn as mentioned in the hadeeth quoted above.
The point here is that every person has with him a companion from among the angels and a companion from among the devils. The believer suppresses his shaytan by obeying Allah and adhering to His religion, and he humiliates his shaytan until he becomes weak and is unable to prevent the believer from doing good or to make him fall into evil except that which Allah wills. But the sinner, through his sins and bad deeds helps his shaytan until he becomes strong enough to help him to follow falsehood and he encourages him to do so and he becomes strong enough to keep him from doing good.
The believer has to fear Allah and strive to resist his shaytan by obeying Allah and His Messenger (peace and blessings of Allah be upon him), and seeking refuge with Allah from the shaytan. And he should be keen to support his angel to obey Allah and His Messenger (peace and blessings of Allah be upon him) and to follow the commands of Allah. End quote from Fatawa al-Shaykh Ibn Baz.
And Allah knows best.