Skip to content

Commit b2437a7

Browse files
committed
fix: prevent extension hang when Claude Code is installed
- Add detection for Claude Code extension during activation - Implement 30-second timeout protection to prevent hanging - Add graceful error handling with user-friendly messages - Add small delay when Claude Code is detected to prevent race conditions - Refactor activation logic into separate performActivation function Fixes #6548
1 parent 305a5da commit b2437a7

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

src/extension.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,44 @@ export async function activate(context: vscode.ExtensionContext) {
5959
context.subscriptions.push(outputChannel)
6060
outputChannel.appendLine(`${Package.name} extension activated - ${JSON.stringify(Package)}`)
6161

62+
// Check for potential extension conflicts
63+
const claudeCodeExtension = vscode.extensions.getExtension("anthropic.claude-code")
64+
if (claudeCodeExtension) {
65+
outputChannel.appendLine(`[Warning] Claude Code extension detected. Implementing conflict prevention measures.`)
66+
67+
// Add a small delay to prevent race conditions during activation
68+
await new Promise((resolve) => setTimeout(resolve, 100))
69+
}
70+
71+
// Wrap the activation process with a timeout to prevent hanging
72+
const ACTIVATION_TIMEOUT = 30000 // 30 seconds
73+
const activationPromise = performActivation(context, outputChannel)
74+
75+
try {
76+
await Promise.race([
77+
activationPromise,
78+
new Promise((_, reject) => setTimeout(() => reject(new Error("Activation timeout")), ACTIVATION_TIMEOUT)),
79+
])
80+
} catch (error) {
81+
outputChannel.appendLine(`[Error] Extension activation failed: ${error}`)
82+
// Show a user-friendly error message
83+
vscode.window
84+
.showErrorMessage(
85+
`Roo Code activation failed. ${claudeCodeExtension ? "This may be due to a conflict with Claude Code extension. " : ""}Please try reloading the window.`,
86+
"Reload Window",
87+
)
88+
.then((selection) => {
89+
if (selection === "Reload Window") {
90+
vscode.commands.executeCommand("workbench.action.reloadWindow")
91+
}
92+
})
93+
throw error
94+
}
95+
96+
return activationPromise
97+
}
98+
99+
async function performActivation(context: vscode.ExtensionContext, outputChannel: vscode.OutputChannel) {
62100
// Migrate old settings to new
63101
await migrateSettings(context, outputChannel)
64102

@@ -180,7 +218,13 @@ export async function activate(context: vscode.ExtensionContext) {
180218
registerTerminalActions(context)
181219

182220
// Allows other extensions to activate once Roo is ready.
183-
vscode.commands.executeCommand(`${Package.name}.activationCompleted`)
221+
// Use a try-catch to prevent activation completion from blocking
222+
try {
223+
await vscode.commands.executeCommand(`${Package.name}.activationCompleted`)
224+
} catch (error) {
225+
outputChannel.appendLine(`[Warning] Failed to execute activationCompleted command: ${error}`)
226+
// Continue activation even if this fails
227+
}
184228

185229
// Implements the `RooCodeAPI` interface.
186230
const socketPath = process.env.ROO_CODE_IPC_SOCKET_PATH

0 commit comments

Comments
 (0)