Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Introduction
- This script automates the process of deleting conversation histories from the Claude AI platform. It performs two main tasks:
- 1. **Extract Chat IDs:**
- - The script looks through your recent conversations on the Claude AI platform and gathers the unique IDs of these conversations.
- 2. **Delete Conversations:**
- - 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.
- ### How to Use
- 1. **Log into the Claude AI platform.**
- 2. **Go to the [Claude AI Recents](https://claude.ai/recents) page.**
- 3. **Open your browser's developer console (usually by pressing `F12` or `Ctrl+Shift+I`).**
- 4. **Copy and paste the script below into the console and press `Enter`.**
- 5. **Be careful, it will also delete your existing chat.**
- The script will automatically extract the IDs of your recent conversations and delete them for you, providing real-time logging of its actions.
- ### The Script
- ```javascript
- // Function to extract chat IDs
- async function extractChatIds() {
- console.log("Extracting chat IDs...");
- const ul = document.querySelector('ul.flex.flex-col.gap-3');
- if (!ul) {
- console.error('The specified ul element was not found.');
- return [];
- }
- const anchors = ul.querySelectorAll('a');
- const chatIds = Array.from(anchors).map(anchor => {
- const href = anchor.getAttribute('href');
- const match = href.match(/\/chat\/([^/]+)/);
- return match ? match[1] : null;
- }).filter(Boolean);
- console.log('Extracted chat IDs:', chatIds);
- return chatIds;
- }
- // Function to delete a single conversation
- async function deleteConversation(conversationId) {
- const orgId = 'ee679dba-8c8b-49fc-a787-e4dfd6258143';
- const url = `https://claude.ai/api/organizations/${orgId}/chat_conversations/${conversationId}`;
- console.log(`Attempting to delete conversation: ${conversationId}`);
- try {
- const response = await fetch(url, {
- method: 'DELETE',
- headers: {
- 'Content-Type': 'application/json',
- 'anthropic-client-sha': 'unknown',
- 'anthropic-client-version': 'unknown'
- },
- });
- if (!response.ok) {
- throw new Error(`HTTP error! status: ${response.status}`);
- }
- console.log(`Successfully deleted conversation: ${conversationId}`);
- } catch (error) {
- console.error(`Failed to delete conversation ${conversationId}:`, error);
- }
- }
- // Function to delete all conversations with a delay
- async function deleteAllConversations(conversationIds) {
- console.log(`Deleting ${conversationIds.length} conversations...`);
- for (const id of conversationIds) {
- await deleteConversation(id);
- // Add a delay to avoid rate limiting
- await new Promise(resolve => setTimeout(resolve, 1000));
- }
- console.log("Task completed, all conversations deleted.");
- }
- // Main function to extract chat IDs and delete them
- async function main() {
- const conversationIds = await extractChatIds();
- if (conversationIds.length > 0) {
- await deleteAllConversations(conversationIds);
- } else {
- console.log('No chat IDs found to delete.');
- }
- }
- // Run the main function
- main();
- ```
Advertisement
Add Comment
Please, Sign In to add comment