Variations in the grain size distribution are to be expected in the interstellar medium (ISM) due to grain growth and destruction. In this work, we present a dust collision model to be implemented inside a magnetohydrodynamical (MHD) code that takes into account grain growth and shattering of charged dust grains of a given composition (silicate or graphite). We integrate this model in the MHD code Athena, and builds on a previous implementation of the dynamics of charged dust grains in the same code. To demonstrate the performance of this coagulation model, we study the variations in the grain size distribution of a single-sized population of dust with radius 0.05 µm inside several dust filaments formed during a 2D MHD simulation. We also consider a realistic dust distribution with sizes ranging from 50 Å to 0.25 µm and analyze both the variations in the size distribution for graphite and silicates, as well as of the far ultraviolet extinction curve. From the obtained results, we conclude that the methodology here presented, based on the MHD evolution of the equation of motion for a charged particle, is optimal for studying the coagulation of charged dust grains in a diffuse regime such as a molecular cloud envelope. Observationally, these variations in the dust size distribution are translated into variations in the far ultraviolet extinction curve, and they are mainly caused by small graphite dust grains.