God is Omniscient which means he knows everything including your thoughts. The Psalmist David clearly tells us that God knows our thoughts and He can purify our thoughts if we allow Him.
You have searched me, Lord,
and you know me.
You know when I sit and when I rise;
you perceive my thoughts from afar.
You discern my going out and my lying down;
you are familiar with all my ways.
Before a word is on my tongue
you, Lord, know it completely.
Search me, God, and know my heart;
test me and know my anxious thoughts.
See if there is any offensive way in me,
and lead me in the way everlasting.
Bad thoughts are difficult to control and can truly lead to sin if we ponder on them and allow them room to grow in our mind and actions. God has given every person a conscience from birth. It is the mind’s and soul’s warning system which enables a person to know what is right and wrong and discern between good and evil. So when a “bad” though enters your mind, dismiss it at once and it is not then a sin.
Do not conform to the pattern of this world, but be transformed by the renewing of your mind. Then you will be able to test and approve what God’s will is—his good, pleasing and perfect will.