Praise be to Allah.
In cases like this, the divorce is not valid, for two reasons:
It is only in your mind, and has never been expressed either verbally or in writing.
The divorce of a person who is afflicted with waswaas (insinuating thoughts from Shaytaan) is not valid because this is something that he has no control over, and it carries no weight in sharee’ah.
And Allaah is the Source of Strength.