Skip to content

fix: handle missing session_id when Cursor runs claude-code hooks#1306

Open
Zubairu wants to merge 1 commit intothedotmack:mainfrom
Zubairu:fix/cursor-session-init-400
Open

fix: handle missing session_id when Cursor runs claude-code hooks#1306
Zubairu wants to merge 1 commit intothedotmack:mainfrom
Zubairu:fix/cursor-session-init-400

Conversation

@Zubairu
Copy link

@Zubairu Zubairu commented Mar 9, 2026

Problem

When Cursor IDE runs Claude Code-compatible hooks, it sends conversation_id instead of session_id in the hook input. The UserPromptSubmit hook (new-hook.ts) reads session_id directly, so it becomes undefined, and the subsequent call to /api/sessions/init fails with HTTP 400 because contentSessionId is required.

This causes Cursor to show a blocking error dialog:

Submission blocked by hook
Hook blocked with message: Hook error: Error: Session initialization failed: 400

The error happens every time a user submits a prompt in Cursor's built-in agent when claude-mem hooks are active.

Root Cause

new-hook.ts interface and destructuring only reads session_id:

// Before
const { session_id, cwd, prompt } = input;

Cursor provides conversation_id, not session_id, so contentSessionId sent to the worker is undefined → 400.

Fix

Two-part fix:

  1. Accept conversation_id as fallback when session_id is absent
  2. Skip gracefully (return success) when neither ID is available, instead of throwing an error that blocks the submission
// After
const session_id = input.session_id ?? input.conversation_id;
if (!session_id) {
  console.log(STANDARD_HOOK_RESPONSE);
  return;
}

Testing

Reproduced by using Cursor's built-in agent with claude-mem hooks active. After this fix, Cursor submits prompts without the blocking error.

🤖 Generated with Claude Code

When Cursor IDE runs claude-code hooks in compatibility mode, it sends
conversation_id instead of session_id. This caused the UserPromptSubmit
hook to call /api/sessions/init with an empty contentSessionId, resulting
in a 400 error and blocking prompt submission with:
  "Submission blocked by hook: Session initialization failed: 400"

Fix:
- Accept conversation_id as fallback when session_id is not present
- Skip gracefully (return success) when neither ID is available

This allows claude-mem to work correctly when Cursor's agent runs
Claude Code-compatible hooks without providing a session_id.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant