|
14 | 14 | from codegen.cli.api.endpoints import API_ENDPOINT |
15 | 15 | from codegen.cli.auth.token_manager import get_current_token |
16 | 16 | from codegen.cli.commands.claude.claude_log_watcher import ClaudeLogWatcherManager |
17 | | -from codegen.cli.commands.claude.claude_session_api import update_claude_session_status, generate_session_id |
| 17 | +from codegen.cli.commands.claude.claude_session_api import ( |
| 18 | + update_claude_session_status, |
| 19 | + generate_session_id, |
| 20 | + create_claude_session, |
| 21 | +) |
18 | 22 | from codegen.cli.commands.claude.config.mcp_setup import add_codegen_mcp_server, cleanup_codegen_mcp_server |
19 | 23 | from codegen.cli.commands.claude.hooks import cleanup_claude_hook, ensure_claude_hook, get_codegen_url |
20 | 24 | from codegen.cli.commands.claude.quiet_console import console |
@@ -86,6 +90,16 @@ def _run_claude_interactive(resolved_org_id: int, no_mcp: bool | None) -> None: |
86 | 90 | os.environ["CODEGEN_CLAUDE_SESSION_ID"] = session_id |
87 | 91 | os.environ["CODEGEN_CLAUDE_ORG_ID"] = str(resolved_org_id) |
88 | 92 |
|
| 93 | + # Proactively create the backend session as a fallback in case hooks fail |
| 94 | + try: |
| 95 | + agent_run_id = create_claude_session(session_id, resolved_org_id) |
| 96 | + if agent_run_id: |
| 97 | + console.print("✅ Backend session created", style="green") |
| 98 | + else: |
| 99 | + console.print("⚠️ Could not create backend session at startup (will rely on hooks)", style="yellow") |
| 100 | + except Exception as e: |
| 101 | + console.print(f"⚠️ Session creation error at startup: {e}", style="yellow") |
| 102 | + |
89 | 103 | # Set up Claude hook for session tracking |
90 | 104 | if not ensure_claude_hook(): |
91 | 105 | console.print("⚠️ Failed to set up session tracking hook", style="yellow") |
|
0 commit comments