using GitHub.Copilot; using GitHub.Copilot.Rpc; var permissionLog = new List(); using var client = new CopilotClient(); await client.StartAsync(); try { await using var session = await client.CreateSessionAsync(new SessionConfig { Model = "claude-haiku-4.5", OnPermissionRequest = (request, invocation) => { var toolName = request switch { PermissionRequestCustomTool ct => ct.ToolName, PermissionRequestShell sh => "shell", PermissionRequestWrite wr => wr.FileName ?? "write", PermissionRequestRead rd => rd.Path ?? "read", PermissionRequestMcp mcp => mcp.ToolName ?? "mcp", _ => request.Kind, }; permissionLog.Add($"approved:{toolName}"); return Task.FromResult(PermissionDecision.ApproveOnce()); }, Hooks = new SessionHooks { OnPreToolUse = (input, invocation) => Task.FromResult(new PreToolUseHookOutput { PermissionDecision = "allow" }), }, }); var response = await session.SendAndWaitAsync(new MessageOptions { Prompt = "List the files in the current directory using glob with pattern '*.md'.", }); if (response != null) { Console.WriteLine(response.Data?.Content); } Console.WriteLine("\n--- Permission request log ---"); foreach (var entry in permissionLog) { Console.WriteLine($" {entry}"); } Console.WriteLine($"\nTotal permission requests: {permissionLog.Count}"); } finally { await client.StopAsync(); }