Cursor "keep" button click event trigger

I am trying to add auditing logic which gets triggered only when user click “keep” button for the code snipped suggestion. I tried two approaches:

  1. Extension capturing onDidSaveDocument event
  2. Cursor hooks for afterFileEdit event.

The problem with both the approaches is that cursor seems to write the file even if user is yet to click keep or undo. And then reverts in case of undo. Because of this, all file saving kind of events triggers logic before the user click keep. In case of my auditing, I might audit false code changes if user later clicks undo.

Is there a way to execute my logic only when user clicks keep button for the suggested code snippet.

Hi Bhavya,

You’re right that both afterFileEdit and onDidSaveDocument will fire when the agent writes changes to disk, which happens before you click Keep or Undo. Today, we don’t yet have a dedicated hook/event that fires specifically when a user accepts or rejects changes in the review flow.

The other lifecycle hooks (e.g., stop, sessionEnd) also won’t line up with that moment, since they’re tied to the agent loop rather than the user’s review action.

This is a known gap and something we’ve heard requests for from other users as well. There’s currently no timeline for when review-flow hooks might be supported, but I’ve noted your use case.

As a practical workaround for auditing, a git-based approach can work well, for example, diffing the working tree against a known baseline at commit time (via a git pre-commit hook) so you capture only the changes that ultimately persist after review.

Best,
Mohit