When the defendant is charged with the commission of a felony by a written complaint subscribed under oath and on file in a court within the county in which the felony is triable, he or she shall, without unnecessary delay, be taken before a magistrate of the court in which the complaint is on file. The magistrate shall immediately deliver to the defendant a copy of the complaint, inform the defendant that he or she has the right to have the assistance of counsel, ask the defendant if he or she desires the assistance of counsel, and allow the defendant reasonable time to send for counsel. However, in a capital case, the court shall inform the defendant that the defendant must be represented in court by counsel at all stages of the preliminary and trial proceedings and that the representation will be at the defendant's expense if the defendant is able to employ counsel or at public expense if he or she is unable to employ counsel, inquire of him or her whether he or she is able to employ counsel and, if so, whether the defendant desires to employ counsel of the defendant's choice or to have counsel assigned for him or her, and allow the defendant a reasonable time to send for his or her chosen or assigned counsel. If the defendant desires and is unable to employ counsel, the court shall assign counsel to defend him or her; in a capital case, if the defendant is able to employ counsel and either refuses to employ counsel or appears without counsel after having had a reasonable time to employ counsel, the court shall assign counsel to defend him or her. If it appears that the defendant may be a minor, the magistrate shall ascertain whether that is the case, and if the magistrate concludes that it is probable that the defendant is a minor, he or she shall immediately either notify the parent or guardian of the minor, by telephone or messenger, of the arrest, or appoint counsel to represent the minor.
Ca. Pen. Code § 859