We show local and global well-posedness results for the Hartree equationwhere γ is a bounded self-adjoint operator on L 2 (R d ), ρ γ (x) = γ (x, x) and w is a smooth short-range interaction potential. The initial datum γ (0) is assumed to be a perturbation of a translation-invariant state γ f = f (− ) which describes a quantum system with an infinite number of particles, such as the Fermi sea at zero temperature, or the Fermi-Dirac and Bose-Einstein gases at positive temperature. Global well-posedness follows from the conservation of the relative (free) energy of the state γ (t), counted relatively to the stationary state γ f . We indeed use a general notion of relative entropy, which allows us to treat a wide class of stationary states f (− ). Our results are based on a Lieb-Thirring inequality at positive density and on a recent Strichartz inequality for orthonormal functions, which are both due to Frank, Lieb, Seiringer and the first author of this article.