A theoretical description of the $g$ factor of a muon bound in a nuclear potential is presented. One-loop self-energy and multi-loop vacuum polarization corrections are calculated, taking into account the interaction with the binding potential exactly. Nuclear effects on the bound-muon $g$ factor are also evaluated. We put forward the measurement of the bound-muon $g$ factor via the continuous Stern-Gerlach effect as an independent means to determine the free muons magnetic moment anomaly and mass. The scheme presented enables to increase the accuracy of the mass by more than an order of magnitude.