The spell's effects relate to "you or your companions", regardless of whether the target realizes they're your companions
The charm monster spell description says (emphasis mine):
You attempt to charm a creature you can see within range. It must make a Wisdom saving throw, and it does so with advantage if you or your companions are fighting it. If it fails the saving throw, it is charmed by you until the spell ends or until you or your companions do anything harmful to it. The charmed creature is friendly to you. When the spell ends, the creature knows it was charmed by you.
(The charm person spell has mostly identical wording, aside from only working on humanoids, and otherwise works the same way.)
The spell doesn't say these things depend on whether the charmed creature realizes they're your companions. As such, this means these effects - advantage on the save if companions are fighting it, and the charmed condition ending if your companions do anything harmful to it - apply simply based on whether they're actually your companions, regardless of whether the targeted creature knows they are.
The spell doesn't provide an in-universe explanation for how the spell determines that the creatures are your companions, so you may have to substitute your own reasoning to explain it in-game. However, out of game, that is simply how the spell works; it seems reasonable to interpret "your companions" as referring to the other player characters (and any possible allied NPCs) if the caster is a player character - assuming the PCs are all working together as a party, of course.