In some clinical trials, the repeated occurrence of the same type of event is of primary interest and the Andersen–Gill model has been proposed to analyze recurrent event data. Existing methods to determine the required sample size for an Andersen–Gill analysis rely on the strong assumption that all heterogeneity in the individuals' risk to experience events can be explained by known covariates. In practice, however, this assumption might be violated due to unknown or unmeasured covariates affecting the time to events. In these situations, the use of a robust variance estimate in calculating the test statistic is highly recommended to assure the type I error rate, but this will in turn decrease the actual power of the trial. In this article, we derive a new sample-size formula to reach the desired power even in the presence of unexplained heterogeneity. The formula is based on an inflation factor that considers the degree of heterogeneity and characteristics of the robust variance estimate. Nevertheless, in the planning phase of a trial there will usually be some uncertainty about the size of the inflation factor. Therefore, we propose an internal pilot study design to reestimate the inflation factor during the study and adjust the sample size accordingly. In a simulation study, the performance and validity of this design with respect to type I error rate and power are proven. Our method is applied to the HepaTel trial evaluating a new intervention for patients with cirrhosis of the liver.