Inside the organism, the immune system can fight generically against any bacteria. However, the lumen of the gut is home to a very important microbiota, so the host has to find alternative ways to fight dangerous bacteria while sparing beneficial ones. While many studies have focused on the complex molecular and cellular pathways that trigger an immune response, little is known about how the produced antibodies act once secreted into the intestinal lumen. Our modeling work is along 3 axes. First, using stochastic models of bacterial population dynamics and branching processes, we infer relevant biological parameters of the dynamics of the bacterial population in the in vivo experiments of our collaborator, Emma Slack (ETH Zurich). We contributed to show that the main physical effect of these antibodies is to cross-link bacteria into clusters as they divide, preventing them from interacting with epithelial cells, thus protecting the host. We then developed a simple ordinary differential equations model of these bacterial clusters, and studied how the interplay of the time scales of bacterial growth and of link breaking could enable the immune system to target the most problematic bacteria. Last, we studied how such immune-mediated bacterial clustering could impact the evolution of drug resistance by using a hybrid cross-scale model (with deterministic within-host bacterial growth, and stochastic transmission).