Aims. We consider a scenario for the longest duration gamma ray bursts, resulting from the collapse of a massive rotating star in a close binary system with a companion black hole (BH). Methods. The primary BH born during the core collapse is first being spun up and increases its mass during the fallback of the stellar envelope just after its birth. As the companion BH enters the outer envelope, it provides an additional angular momentum to the gas. After the infall and spiral-in toward the primary, the two BHs merge inside the circumbinary disk. Results. The second episode of mass accretion and high final spin of the postmerger BH prolongs the gamma ray burst central engine activity. The observed events should have two distinct peaks in the electromagnetic signal, separated by the gravitational wave emission. The gravitational recoil of the burst engine is also possible.