|  | 
| 19 | 19 | from codegen.cli.commands.claude.claude_session_api import ( | 
| 20 | 20 |  create_claude_session, | 
| 21 | 21 |  generate_session_id, | 
|  | 22 | + get_cli_rules, | 
| 22 | 23 |  update_claude_session_status, | 
| 23 | 24 | ) | 
| 24 | 25 | from codegen.cli.commands.claude.config.mcp_setup import add_codegen_mcp_server, cleanup_codegen_mcp_server | 
| @@ -221,13 +222,46 @@ def _run_claude_interactive(resolved_org_id: int, no_mcp: bool | None) -> None: | 
| 221 | 222 |  console.print("🔵 Starting Claude Code session...", style="blue") | 
| 222 | 223 | 
 | 
| 223 | 224 |  try: | 
|  | 225 | + # Fetch CLI rules for system prompt | 
|  | 226 | + console.print("📋 Fetching CLI rules...", style="blue") | 
|  | 227 | + cli_rules = get_cli_rules(resolved_org_id) | 
|  | 228 | + | 
|  | 229 | + # Build Claude command | 
|  | 230 | + claude_cmd = [claude_path, "--session-id", session_id] | 
|  | 231 | + | 
|  | 232 | + # Add system prompt if CLI rules were fetched successfully | 
|  | 233 | + if cli_rules: | 
|  | 234 | + system_prompt_parts = [] | 
|  | 235 | + | 
|  | 236 | + # Add organization rules if available | 
|  | 237 | + if cli_rules.get("organization_rules"): | 
|  | 238 | + system_prompt_parts.append("Organization Rules:") | 
|  | 239 | + system_prompt_parts.append(cli_rules["organization_rules"]) | 
|  | 240 | + | 
|  | 241 | + # Add user custom prompt if available | 
|  | 242 | + if cli_rules.get("user_custom_prompt"): | 
|  | 243 | + if system_prompt_parts: # Add separator if we already have org rules | 
|  | 244 | + system_prompt_parts.append("\n") | 
|  | 245 | + system_prompt_parts.append("User Custom Prompt:") | 
|  | 246 | + system_prompt_parts.append(cli_rules["user_custom_prompt"]) | 
|  | 247 | + | 
|  | 248 | + # Combine all parts into system prompt | 
|  | 249 | + if system_prompt_parts: | 
|  | 250 | + system_prompt = "\n".join(system_prompt_parts) | 
|  | 251 | + claude_cmd.extend(["--append-system-prompt", system_prompt]) | 
|  | 252 | + console.print("✅ Added CLI rules to system prompt", style="green") | 
|  | 253 | + else: | 
|  | 254 | + console.print("⚠️ CLI rules response was empty", style="yellow") | 
|  | 255 | + else: | 
|  | 256 | + console.print("⚠️ Could not fetch CLI rules, continuing without system prompt", style="yellow") | 
|  | 257 | + | 
| 224 | 258 |  # Launch Claude Code with our session ID | 
| 225 | 259 |  console.print(f"🚀 Launching Claude Code with session ID: {session_id[:8]}...", style="blue") | 
| 226 | 260 | 
 | 
| 227 | 261 |  url = get_codegen_url(session_id) | 
| 228 | 262 |  console.print(f"\n🔵 Codegen URL: {url}\n", style="bold blue") | 
| 229 | 263 | 
 | 
| 230 |  | - process = subprocess.Popen([claude_path, "--session-id", session_id]) | 
|  | 264 | + process = subprocess.Popen(claude_cmd) | 
| 231 | 265 | 
 | 
| 232 | 266 |  # Start log watcher for the session | 
| 233 | 267 |  console.print("📋 Starting log watcher...", style="blue") | 
| @@ -288,7 +322,7 @@ def signal_handler(signum, frame): | 
| 288 | 322 |  console.print("✅ Claude Code finished successfully", style="green") | 
| 289 | 323 | 
 | 
| 290 | 324 |  except FileNotFoundError: | 
| 291 |  | - logger.error( | 
|  | 325 | + logger.exception( | 
| 292 | 326 |  "Claude Code executable not found", | 
| 293 | 327 |  extra={"operation": "claude.interactive", "org_id": resolved_org_id, "claude_session_id": session_id, "error_type": "claude_executable_not_found", **_get_session_context()}, | 
| 294 | 328 |  ) | 
|  | 
0 commit comments