Placing comma before ambiguous prepositional phrase

But when I'm not writing code, I'll be spending time with friends and family, in the pursuit of happiness.

Is the comma placement before "in the pursuit of happiness" correct? Most of the time, I place commas before prepositional phrases when they appear as nonrestrictive clauses in the middle of sentences.

Here, however, I want to clarify that I--not my friends and family--am in the pursuit of happiness. As such, the comma before the prepositional phrase at the end feels logical.

Am I correct to place it there?


I don’t think there are any issues with it. According to the Purdue Owl, this seems to be a free modifier:

  1. Use commas to set off phrases at the end of the sentence that refer to the beginning or middle of the sentence. Such phrases are free modifiers that can be placed anywhere in the sentence without causing confusion. (If the placement of the modifier causes confusion, then it is not "free" and must remain "bound" to the word it modifies.) Nancy waved enthusiastically at the docking ship, laughing joyously. (correct) INCORRECT: Lisa waved at Nancy, laughing joyously. (Who is laughing, Lisa or Nancy?) Laughing joyously, Lisa waved at Nancy. (correct) Lisa waved at Nancy, who was laughing joyously. (correct)

https://owl.purdue.edu/owl/general_writing/punctuation/commas/extended_rules_for_commas.html

As long as it isn’t causing confusion, then I think it should be ok.