The hippocampus encodes both spatial and non-spatial features of an environment thought to be critical to guide navigational trajectories and associative learning, respectively. These seemingly dichotomous roles have been reconciled in a proposed cognitive map - a representation of environment structure abstracted away from specific behavioral demands. However, the extent to which a cognitive map is independent of behavioral demands remains unclear because direct comparisons across environments with common structure but different spatial/behavioral context is lacking. Here we compare behaviors in mice trained to navigate to a hidden target in a physical arena and manipulate a joystick to a virtual target to collect a delayed reward. Comparison of behaviors with an artificial agent revealed a common algorithmic basis for learned foraging trajectories in both contexts. Imaging CA1 neural activity revealed a similar map-like encoding of active foraging; however, detailed analysis of ensemble activity, optogenetic inactivation, and modeling revealed a context-specific functional dissociation. In a navigational context, CA1 was critical for retrospective evaluation of spatial trajectories, but dispensable for initiation. In a non-navigational context, CA1 activity was critical for initiation and planning foraging trajectories. This work highlights how construction of a cognitive map to facilitate idiosyncratic behavioral demands7 is critical for foraging in diverse spatial contexts.