Guest User

Bulk delete claude chats

a guest
Jun 30th, 2024
1,572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. ### Introduction
  2.  
  3. This script automates the process of deleting conversation histories from the Claude AI platform. It performs two main tasks:
  4.  
  5. 1. **Extract Chat IDs:**
  6. - The script looks through your recent conversations on the Claude AI platform and gathers the unique IDs of these conversations.
  7.  
  8. 2. **Delete Conversations:**
  9. - After collecting the chat IDs, the script sends requests to the Claude AI server to delete each conversation one by one. It includes a short delay between each deletion to avoid overwhelming the server.
  10.  
  11. ### How to Use
  12.  
  13. 1. **Log into the Claude AI platform.**
  14. 2. **Go to the [Claude AI Recents](https://claude.ai/recents) page.**
  15. 3. **Open your browser's developer console (usually by pressing `F12` or `Ctrl+Shift+I`).**
  16. 4. **Copy and paste the script below into the console and press `Enter`.**
  17. 5. **Be careful, it will also delete your existing chat.**
  18.  
  19. The script will automatically extract the IDs of your recent conversations and delete them for you, providing real-time logging of its actions.
  20.  
  21. ### The Script
  22.  
  23. ```javascript
  24. // Function to extract chat IDs
  25. async function extractChatIds() {
  26. console.log("Extracting chat IDs...");
  27.  
  28. const ul = document.querySelector('ul.flex.flex-col.gap-3');
  29.  
  30. if (!ul) {
  31. console.error('The specified ul element was not found.');
  32. return [];
  33. }
  34.  
  35. const anchors = ul.querySelectorAll('a');
  36.  
  37. const chatIds = Array.from(anchors).map(anchor => {
  38. const href = anchor.getAttribute('href');
  39. const match = href.match(/\/chat\/([^/]+)/);
  40. return match ? match[1] : null;
  41. }).filter(Boolean);
  42.  
  43. console.log('Extracted chat IDs:', chatIds);
  44. return chatIds;
  45. }
  46.  
  47. // Function to delete a single conversation
  48. async function deleteConversation(conversationId) {
  49. const orgId = 'ee679dba-8c8b-49fc-a787-e4dfd6258143';
  50. const url = `https://claude.ai/api/organizations/${orgId}/chat_conversations/${conversationId}`;
  51.  
  52. console.log(`Attempting to delete conversation: ${conversationId}`);
  53.  
  54. try {
  55. const response = await fetch(url, {
  56. method: 'DELETE',
  57. headers: {
  58. 'Content-Type': 'application/json',
  59. 'anthropic-client-sha': 'unknown',
  60. 'anthropic-client-version': 'unknown'
  61. },
  62. });
  63.  
  64. if (!response.ok) {
  65. throw new Error(`HTTP error! status: ${response.status}`);
  66. }
  67.  
  68. console.log(`Successfully deleted conversation: ${conversationId}`);
  69. } catch (error) {
  70. console.error(`Failed to delete conversation ${conversationId}:`, error);
  71. }
  72. }
  73.  
  74. // Function to delete all conversations with a delay
  75. async function deleteAllConversations(conversationIds) {
  76. console.log(`Deleting ${conversationIds.length} conversations...`);
  77.  
  78. for (const id of conversationIds) {
  79. await deleteConversation(id);
  80. // Add a delay to avoid rate limiting
  81. await new Promise(resolve => setTimeout(resolve, 1000));
  82. }
  83.  
  84. console.log("Task completed, all conversations deleted.");
  85. }
  86.  
  87. // Main function to extract chat IDs and delete them
  88. async function main() {
  89. const conversationIds = await extractChatIds();
  90. if (conversationIds.length > 0) {
  91. await deleteAllConversations(conversationIds);
  92. } else {
  93. console.log('No chat IDs found to delete.');
  94. }
  95. }
  96.  
  97. // Run the main function
  98. main();
  99. ```
Advertisement
Add Comment
Please, Sign In to add comment