Hi all. After a thorough search online I can't seem to find a solution to my problem, which is why I'm now asking the experts

I'm doing a cox regression in 1175 subjects where I want to assess the effect of the dichotomous baseline variable X on the outcome Z. All subjects have variable X which is present since birth. In addition I have another dichotomous variable Y (which is more like an intervention effect) which is not present at baseline for any of the subjects, however some of the subjects get affected by (Y) event during the follow up at different dates, and this variable is known to be connected with outcome Z. I'm trying to know if variable Y increases the chance of occurrence of outcome Z in which (Z=1) among those who have the effect variable Y during their followup and those who don't.

So the "known" chain of events is X --> Y ---> Z . And I want to test X --> Z. But I still want to include the effect of Y in my model as some of the subjects will follow X-->Y-->Z.
So i thought - how can I include Y as a time-varying covariate so as not to underestimate the effect of Y but still assess if there is a direct correlation with X and Z.

Hope the question isn't to cryptic - I'll be happy to elaborate on the question.