Handle Claude Code's startup sequence: 1. Optional workspace trust dialog → press Enter to accept 2. Wait for the ❯ chat prompt
(child, pexpect_mod)
| 439 | |
| 440 | |
| 441 | def _wait_for_claude(child, pexpect_mod) -> None: |
| 442 | """ |
| 443 | Handle Claude Code's startup sequence: |
| 444 | 1. Optional workspace trust dialog → press Enter to accept |
| 445 | 2. Wait for the ❯ chat prompt |
| 446 | """ |
| 447 | TRUST_PATTERNS = [ |
| 448 | "Quick safety check", |
| 449 | "Is this a project you", |
| 450 | "trust", |
| 451 | ] |
| 452 | READY_PATTERNS = [ |
| 453 | r"❯\s", |
| 454 | r"❯$", |
| 455 | r">\s*$", |
| 456 | pexpect_mod.TIMEOUT, |
| 457 | ] |
| 458 | |
| 459 | # Phase 1 — wait for either the trust dialog or the ready prompt |
| 460 | try: |
| 461 | idx = child.expect( |
| 462 | TRUST_PATTERNS + READY_PATTERNS, |
| 463 | timeout=12, |
| 464 | ) |
| 465 | hit_trust = idx < len(TRUST_PATTERNS) |
| 466 | except (pexpect_mod.TIMEOUT, pexpect_mod.EOF): |
| 467 | hit_trust = False |
| 468 | |
| 469 | if hit_trust: |
| 470 | # Accept the trust dialog with Enter and wait for the chat prompt |
| 471 | time.sleep(0.4) |
| 472 | child.sendline("") |
| 473 | try: |
| 474 | child.expect(READY_PATTERNS, timeout=10) |
| 475 | except (pexpect_mod.TIMEOUT, pexpect_mod.EOF): |
| 476 | pass |
| 477 | |
| 478 | # Phase 2 — give the UI a moment to finish rendering |
| 479 | time.sleep(0.8) |
| 480 | |
| 481 | |
| 482 | def _run_basic_fallback(cli_name: str, cmd: str, prompt_text: str) -> str: |