A robotic medical system with a flexible guide tube such as a lung catheter can record the shape of the guide tube in a target configuration. If the shape includes a bend that is sharper than a sharpest permitted bend for insertion or removal of a tool such as a biopsy needle, a control system can find any locations of sharp bends and automatically retract the guide tube to a location associated with a sharp bend. With the tip backed up to that location, the needle can be inserted into or removed from the catheter. The control system can automatically move the catheter between the target configuration and the retracted configuration of the guide tube.