What to do when asked to do something that seems unethical by a co-advisor which might result in losing credit for my work I am doing a course project, and my co-advisor contributed to my design with tips and comments - nothing major. When the system started working he told me no to reveal all the details while presenting my work in the class. 

That didn't feel right. I believe that the course instructor has the right to know all details about my design, and naturally, his name should go on any publication that comes out of this. 

I heard my co-advisor telling another professor that my work is "his vision". I hate being in a such weird situation. I feel like my co-advisor is willing to unethical things for his own benefit (As an example, he refused to write me a recommendation letter to prevent me from leaving the university).

Also, because designs have to go through a fabrication step which takes along time, I feel that if he put his hands on my design I will lose credit for my work. He already told me that he will have one of his other students complete the other step. I am afraid that he will say that the other student did more work so he should be the first author of any publication coming out this or even remove me from the whole picture. Given his history, I cannot trust him now.

Moreover, I intend to leave the university for PhD somewhere else in about six months (he doesn't know that), so I won't be there when the work finishes. 

How to handle this issue ? Should I reveal everything to the course instructor and start a fight with my co-advisor ? or accept this which is byound my tolerance?
You shouldn't start a fight with your coadvisor, but you shouldn't let them push you into an ethical compromise, either. (Or perhaps into a deeper ethical compromise — most instructors expect course projects to be the work of the students, not the students and their advisors.)

If you're not comfortable hiding details from your class/instructor, say so. Directly and professionally, without accusing him of shady behavior. Exactly as if your coadvisor were a responsible, ethical, adult human being.


  he refused to write me a recommendation letter to prevent me from leaving the university


This is where I would normally write "Walk away". Your coadvisor is using you. Fortunately, it looks like you've already figured that out.


  Moreover, I intend to leave the university for PhD somewhere else


Good.


  (he doesn't know that yet)


Not so good. Why are you keeping this a secret?