I know that one is not allowed to pass gas while wearing tefillin. What are the parameters of this din? If one is wearing tefillin and senses the urge to pass gas for the first time, must he remove his tefillin right away? Or does must he only remove them if he notices himself repeatedly passing gas?
A person wearing tefillin may not pass gas even once. See sources. When a person wears tefillin he is strapping the name of H-shem to his body, (similar to the kohen gadol wearing the Tzitz) and he may not defile it even once. If you feel that you have to pass gas, if you can hold it in and control it fine, if not remove your teffilin right away. There are poskim that say that passing gas while wearing tefillin is assur min hatorah, and others that say that passing gas while wearing tefillin is worse than it falling on the floor!.
Shulchan Aruch O:CH 37-2, Sha’agas Aryeh 40, see Eshel Avrohom Butchatch 38-2 that suggest that the same way one fasts when his teffilin fall on the floor, that this is not less severe! Also see Teshuvos Vhanhagos 3-14, Halacha L’moshe (on Kitzur Shulchan Aruch) 175, Nishmas Avrohom O:CH 80-3, Halichos Shlomo 4 ftnt 101. There are opinions that if the gas was such that it doesn’t have any bed smell, as sometimes occurs to sick people that that is not the gas referred to here. See Halichos Shlomo ibid in the name of Od Yosef Chai Chayei Sara 4.