Honestly, you need to get some self confidence. You need to man up. Being a nice guy in this scenario doesn't help. If the CTO wants to play dirty and ruthless. You must play dirty and ruthless. How did a guy you hire get the guts to tell you he wants to fire you as a co-founder. This means your other co-founder is probably ganging up with him behind your back. You cannot trust both of them. I don't know who owns more percentage of the company betwen you and your co-founder but I want to believe that your CTO is minority stake holder at this point. Don't leave without a thorough fight. The good thing is that you can code no-matter how terrible, you can build a minimum viable product for any future idea you have. Your CEO cannot which is why it is convenient for him to try and co-operate wit the CTO.

Line of action:

1. Start speaking to a lawyer.
2. Transition out of code writing role into product visionary role, so the CTO doesn't see your as someone that reports to him. You played a part in not just formulating the initial idea but in coding a prototype, so in essence you can play the role of product visionary. That is Chief Product Officer.

3. Tell you co-founder you are transitioning into a product visionary role with the title of Chief Product Officer. Read up what this role does.

4. Call for a meeting with just you and your co-founder and test his allegiance. Tell him that if a guy you hired wants to fire you then he can also team up with future investors to fire the CEO, so he is not save in the future. So due to trust issues, you intend to fire your CTO after you get a replacement. Show him a list of possible top people in the open-source world using your technology that you intend to open up communication with as possible replacement for the CTO. Sink it into his head that the CTO is replace-able and that culture fit matters more thank skills as you can get a replacement for skillset easier than getting the person with the right skillset and cultural fit. http://www.bhorowitz.com/programming_your_culture

5. Call a meeting with your CTO and tell him you plan to stop writing code and then tell him you also plan to get a new CTO to replace him because you can't have a guy you hired steal your company. Let him know he is also replace-able as you won't have hired him because of poor culture fit even though he is skillful if you knew about the schemer he is.

6. Now that you have man up to both, call a meeting with the CEO and CTO to address any issues relating to what you discussed with them.

7. Watch the shares during any round of funding, so you are not squeezed out. See the company incorporation details and ensure your name is there and you are not deceived by your other co-founder.

8. CTO's are replace-able, don't don't let someone you hired ask you to leave, so that he can take your shares. He probably overstated his importance behind your back to the CEO and asked for more shares and your co-founder felt that if he gets you out of the way he will get the more shares.

If they were bold and ruthless, you must be bold and ruthless too.

sate your importance to founding the company, idea generation, writing enough code to make the CTO, join since he knew you people were not idea only guys.

Kick that CTO out and henceforth watch your co-founder closely.