Feature request for product/service
Cursor SDK
Describe the request
An embedding application may already have its own approval system, interactive UI, or external permission protocol. It needs to allow or deny a Cursor-native tool call before the SDK
executes it, using state that already lives in the host process.
The TypeScript SDK currently documents hooks as file-based only. There is no programmatic hook callback. preToolUse runs as an external command registered in .cursor/hooks.json or
~/.cursor/hooks.json. An SDK embedder therefore cannot directly route a native tool request through authorization state already held in the host process.
A command hook runs in a separate process. That works for project-level static policy, but an embedding application may already own its session state, interactive approval UI, ACP
connection, authorization policy, and run cancellation state. To use those from a command hook, the embedder must build IPC in both directions:
Cursor hook process → host application → approval decision → hook process → Cursor native execution
That IPC exists only because the hook cannot run inside the SDK host process.
Please add an optional programmatic preToolUse callback for local SDK agents. It should:
- run before native Shell, Read, Write, and other native tools
- execute in the SDK host process
- wait asynchronously
- return allow or deny
- prevent native execution when denied
- receive cancellation or an equivalent signal
- apply to the parent local agent, not only Task children
Embedding applications may use this callback as a security boundary. It should be possible to configure fail-closed behavior when the callback throws, times out, the run is cancelled, or
the approval system is unavailable. The existing file-hook failClosed behavior is a useful precedent. A failure in a security callback should not silently become an allow when
fail-closed behavior is requested.
This sketch is only an example. Cursor should choose the final types, event shape, and cancellation mechanism:
const agent = await Agent.create({
local: {
hooks: {
preToolUse: async (event) => {
return { permission: “allow” }; // or “deny”
}
}
}
});
File-based hooks should remain the project policy boundary. A programmatic callback would be an additional integration surface for SDK embedders, not a replacement for
.cursor/hooks.json.
In one integration, the host already has its own approval policy and an ACP-connected UI. Because Cursor SDK hooks run as external commands, that integration currently needs a local IPC
bridge only to ask the host whether a native Cursor tool may execute. An in-process callback would remove that transport layer while keeping the existing approval policy unchanged.
References: