All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
It is not permissible to kill ants during the prayer or outside it, because the Prophet, sallallaahu ‘alayhi wa sallam, forbade killing them unless they are harmful, as we stated in Fatwa 84945.
However, if the ants are of a harmful kind, then it is permissible to kill them even during the prayer. Jurists stated that it is permissible for the Muslim during the prayer to kill the snake, the scorpion and their likes, which are harmful.
Allaah Knows best.