Skip to content

Instantly share code, notes, and snippets.

@maoyeedy
Last active April 8, 2025 00:58
Show Gist options
  • Save maoyeedy/f874eac8d1c5c125b3dec87628f262f0 to your computer and use it in GitHub Desktop.
Save maoyeedy/f874eac8d1c5c125b3dec87628f262f0 to your computer and use it in GitHub Desktop.
[Userscript] Toggles claude.ai sidebar with "Ctrl+\"
// ==UserScript==
// @name Claude Sidebar Toggle
// @namespace https://github.com/Maoyeedy
// @version 1.0
// @description Toggle Claude sidebar with a keyboard shortcut
// @author Maoyeedy
// @match https://claude.ai/*
// @grant none
// ==/UserScript==
(function () {
'use strict'
// CUSTOMIZE YOUR SHORTCUT HERE
const TOGGLE_SHORTCUT = {
key: '\\', // Default to Backslash key
ctrlKey: true, // Default true for Ctrl
altKey: false, // Default false for Alt
}
// Toggle sidebar function
function toggleSidebar () {
const pinButton = document.querySelector('button[data-testid="pin-sidebar-toggle"]')
if (pinButton) {
pinButton.click()
} else {
console.log('[Claude Sidebar Toggle] No toggle button found')
}
}
// Keyboard listener
document.addEventListener('keydown', function (event) {
if (event.key === TOGGLE_SHORTCUT.key &&
event.ctrlKey === TOGGLE_SHORTCUT.ctrlKey &&
event.altKey === TOGGLE_SHORTCUT.altKey &&
!event.repeat) {
event.preventDefault()
toggleSidebar()
}
})
})()
@maoyeedy
Copy link
Author

maoyeedy commented Apr 8, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment