Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Created May 15, 2026 14:21
Show Gist options
  • Select an option

  • Save wullemsb/e51121ca8bfdd1c09c794deae7dc48ac to your computer and use it in GitHub Desktop.

Select an option

Save wullemsb/e51121ca8bfdd1c09c794deae7dc48ac to your computer and use it in GitHub Desktop.
using GitHub.Copilot.SDK;
await using var client = new CopilotClient();
await client.StartAsync();
await using var session = await client.CreateSessionAsync(new SessionConfig
{
OnPermissionRequest = async (request, invocation) =>
{
// request.Kind — string discriminator for the type of operation being requested:
// "shell" — executing a shell command
// "write" — writing or editing a file
// "read" — reading a file
// "mcp" — calling an MCP tool
// "custom_tool" — calling one of your registered tools
// "url" — fetching a URL
// "memory" — accessing or modifying assistant memory
// "hook" — invoking a registered hook
// request.ToolCallId — the tool call that triggered this request
// request.ToolName — name of the tool (for custom-tool / mcp)
// request.FileName — file being written (for write)
// request.FullCommandText — full shell command text (for shell)
if (request.Kind == "shell")
{
// Deny shell commands
return new PermissionRequestResult { Kind = PermissionRequestResultKind.Rejected };
}
return new PermissionRequestResult { Kind = PermissionRequestResultKind.Approved };
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment