A thought is not necessarily a sin, the devil tempts is with thoughts all the time. It is what we do with the thoughts that is sin. So when we engage our thoughts and desire to entertain them that bevomes sinful (obviously talking of immoral thoughts like sexual immorality).
2846 This petition goes to the root of the preceding one, for our sins result from our consenting to temptation; we therefore ask our Father not to “lead” us into temptation. It is difficult to translate the Greek verb used by a single English word: the Greek means both “do not allow us to enter into temptation” and "do not let us yield to temptation."150 “God cannot be tempted by evil and he himself tempts no one”;151 on the contrary, he wants to set us free from evil. We ask him not to allow us to take the way that leads to sin. We are engaged in the battle “between flesh and spirit”; this petition implores the Spirit of discernment and strength.
2847 The Holy Spirit makes us discern between trials, which are necessary for the growth of the inner man,152 and temptation, which leads to sin and death.153 We must also discern between being tempted and consenting to temptation. Finally, discernment unmasks the lie of temptation, whose object appears to be good, a “delight to the eyes” and desirable,154 when in reality its fruit is death.
God does not want to impose the good, but wants free beings. . . . There is a certain usefulness to temptation. No one but God knows what our soul has received from him, not even we ourselves. But temptation reveals it in order to teach us to know ourselves, and in this way we discover our evil inclinations and are obliged to give thanks for the goods that temptation has revealed to us.155
2848 “Lead us not into temptation” implies a decision of the heart: "For where your treasure is, there will your heart be also. . . . No one can serve two masters."156 "If we live by the Spirit, let us also walk by the Spirit."157 In this assent to the Holy Spirit the Father gives us strength. "No testing has overtaken you that is not common to man. God is faithful, and he will not let you be tempted beyond your strength, but with the temptation will also provide the way of escape, so that you may be able to endure it."158
2849 Such a battle and such a victory become possible only through prayer. It is by his prayer that Jesus vanquishes the tempter, both at the outset of his public mission and in the ultimate struggle of his agony.159 In this petition to our heavenly Father, Christ unites us to his battle and his agony. He urges us to vigilance of the heart in communion with his own. Vigilance is “custody of the heart,” and Jesus prayed for us to the Father: "Keep them in your name."160 The Holy Spirit constantly seeks to awaken us to keep watch.161 Finally, this petition takes on all its dramatic meaning in relation to the last temptation of our earthly battle; it asks for final perseverance. "Lo, I am coming like a thief! Blessed is he who is awake."162