A multi-messenger, space-based cosmic ray detector for gamma rays and charged particles poses several design challenges due to the different instrumental requirements for the two kind of particles. Gamma-ray detection requires layers of high Z materials for photon conversion and a tracking device with a long lever arm to achieve the necessary angular resolution to separate point sources; on the contrary, charge measurements for atomic nuclei requires a thin detector in order to avoid unwanted fragmentation, and a shallow instrument so to maximize the geometric factor. In this paper, a novel tracking approach for gamma rays which tries to reconcile these two conflicting requirements is presented. The proposal is based on the Tracker-In-Calorimeter (TIC) design that relies on a highly-segmented calorimeter to track the incident gamma ray by sampling the lateral development of the electromagnetic shower at different depths. The effectiveness of this approach has been studied with Monte Carlo simulations and has been validated with test beam data of a detector prototype.