what happens to the grant I wrote with my PI if I switch institutions I am an international master's student at a top US institution and I am graduating from my program in September. I do not have a PhD lined up yet, I am planning on applying in this fall. Towards the end of my master's studies, I came up with an idea for a project and already did the ground work (separate from the project that my PI was funding me for). However, because I am an international student, I cannot write a grant / fellowship for this project idea myself. I've pitched this idea to my PI and she is interested in applying for a grant for this project together, provided I do all the work to write the grant. I am OK with writing the grant and submitting it under my PI's name but my question is: what happens if we get the funding for this project from a federal agency (e.g., NSF) and I end up starting my PhD in a different institution next year? Does the grant money stay with the PI? If so, can that money still be used towards funding my research on the same project in a different university (in a lab where I can do similar research)?

More info upon questions below:
I am worried that I will get the grant with my PI, but won't be accepted for a PhD position in my current institution (I will be applying to a different department -BE- than the department I'm completing my master's in -EE-). The reason for this assumption is that I already applied to BE and was rejected. My PI did write me a recommendation letter but she is not in the admissions committee and she told me that she has no leverage in who is admitted to BE. I'll still apply again this year, but I may be rejected again. So, I'm just trying to see whether it is worth putting the effort in writing the grant if the only way to benefit from that grant is to be a PhD student in my current institution. I'm wondering whether some sort of agreement may be made between my current PI and the future PI in wherever I'll be admitted (still in the US) such that I can still use that grant to work towards my project? There are many labs in other US institutions with overlapping interests as my current lab, so finding a relevant place won't be hard. I'm just curious if anyone had / heard of a similar experience?
If your name does not explicitly appear in the proposal as an investigator, then the funding, if the grant is awarded, is not committed to you in any way, shape, or form. The PI could in principle take your ideas and use it to fund another student to work on your project!

Unfortunately, most universities will not let grad students serve as PI’s, with the exception of some programs that are specifically aimed at graduate students, such as the Kirschstein Fellowship at the NIH. So you are definitely running the risk of writing your idea up as a proposal and ending up with absolutely nothing to show for it.