Skip to content

Commit 1678fa8

Browse files
authored
Rpatel/create session on claude (#1222)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [ ] I have updated the documentation or added new documentation as needed
1 parent 26911ec commit 1678fa8

File tree

1 file changed

+15
-1
lines changed
  • src/codegen/cli/commands/claude

1 file changed

+15
-1
lines changed

src/codegen/cli/commands/claude/main.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
from codegen.cli.api.endpoints import API_ENDPOINT
1515
from codegen.cli.auth.token_manager import get_current_token
1616
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+
)
1822
from codegen.cli.commands.claude.config.mcp_setup import add_codegen_mcp_server, cleanup_codegen_mcp_server
1923
from codegen.cli.commands.claude.hooks import cleanup_claude_hook, ensure_claude_hook, get_codegen_url
2024
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:
8690
os.environ["CODEGEN_CLAUDE_SESSION_ID"] = session_id
8791
os.environ["CODEGEN_CLAUDE_ORG_ID"] = str(resolved_org_id)
8892

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+
89103
# Set up Claude hook for session tracking
90104
if not ensure_claude_hook():
91105
console.print("⚠️ Failed to set up session tracking hook", style="yellow")

0 commit comments

Comments
 (0)