We're using the Dungeons and Dragons 5th edition players handbook only. The Ranger's Companion section (PHB p. 93) seems, for the most part, to be pretty clear. The part about hit points states:
It's hit point maximum equals the hit point number in its stat block or four times your ranger level, whichever is higher. Like any other creature, it can spend Hit Dice during a short rest to regain hit points.
Since the PHB doesn't specifically say otherwise I assumed that you take the Hit Dice from the stat block along with everything else. This means a lvl 6 Ranger's companion has 24 hit poins but only 2d8 hit dice. As the Ranger gains levels the companion's Hit Dice become progressively less impactful. At lvl 20, when the companion has 80 hp, they have become almost meaningless. Since the class lacks any feature for having your companion regain HP (apart from wasting your precious spell slots in it) I wonder if this is intentional. Or was the intention to have the Ranger use the faithful companion they might have had for years as expendable cannon fodder?
To me this seems like yet another disappointing feature of an already underperforming subclass of a generally underwhelming class. Every player class gains Hit Dice as they gain levels so shouldn't it be the same for animal companions?