hotkey
lobehub/lobe-chat
Add or edit LobeHub keyboard shortcuts with proper scoping, conflict detection, and i18n support.
What is hotkey?
This skill enables adding and managing keyboard shortcuts in LobeHub Chat. Use it when you need to create new hotkeys, register them with scope and conflict handling, add translations, and wire them to UI actions via hooks.
- Define hotkey constants in HotkeyEnum and register them with key combinations and scopes
- Create and register hooks (useHotkeyById, useRegisterChatHotkeys) to bind hotkeys to chat actions
- Add i18n translations for hotkey titles and descriptions across locales
- Configure hotkey scope (global vs. chat-specific) and detect conflicts with system shortcuts
- Integrate hotkeys into UI components with tooltip display using the Tooltip component
- Support platform-agnostic key combinations using Key.Mod for Cmd/Ctrl detection
How to install hotkey
npx skills add https://github.com/lobehub/lobe-chat --skill hotkey- Access to LobeHub Chat source code (src/ directory)
- Familiarity with TypeScript and React hooks
- Understanding of LobeHub's i18n structure and locale files
- Knowledge of the @lobehub/ui KeyMapEnum and combineKeys utility
How to use hotkey
- 1.Define the new hotkey in src/types/hotkey.ts by adding an entry to HotkeyEnum
- 2.Register the hotkey in src/const/hotkeys.ts with key combination, group, and scope
- 3.Add i18n translations in src/locales/default/hotkey.ts for title and description
- 4.Create a custom hook in src/hooks/useHotkeys/ that calls useHotkeyById with your action
- 5.Register the hook in useRegisterChatHotkeys or appropriate scope hook
- 6.Optionally add a Tooltip to UI components displaying the hotkey using useUserStore selectors
Use cases
- Adding a new keyboard shortcut like Cmd/Ctrl+Shift+Backspace to clear chat messages
- Creating chat-scoped hotkeys that only activate in conversation context
- Implementing hotkey settings UI that displays available shortcuts and detects conflicts
- Adding multilingual hotkey descriptions for international users
- Binding complex key combinations (modifier + multiple keys) to specific chat actions
- LobeHub Chat developers extending keyboard navigation
- Contributors adding new chat features with hotkey support
- Developers implementing accessibility features via keyboard shortcuts
- Teams managing hotkey conflicts across a large codebase
hotkey FAQ
Global scope hotkeys work everywhere in the app; chat scope hotkeys only activate when in a conversation. Choose based on whether the action is chat-specific or app-wide.
Use Key.Mod from @lobehub/ui instead of hardcoding Ctrl or Cmd. The combineKeys utility automatically maps to the correct key for each platform.
Check the HotkeyInput component warnings during development. Verify the conflict list and choose an alternative key combination that doesn't clash with browser or OS shortcuts.
Add translations to src/locales/default/hotkey.ts with the same key structure. The i18n system will automatically load the correct language based on user settings.
Verify that the scope is activated (check RegisterHotkeys hook is called), the HotkeyEnum constant exists, and the key combination is registered in HOTKEYS_REGISTRATION.
Full instructions (SKILL.md)
Source of truth, from lobehub/lobe-chat.
name: hotkey description: 'Add or edit LobeHub keyboard shortcuts. Use for HotkeyEnum, HOTKEYS_REGISTRATION, combineKeys, useHotkeyById, tooltip hotkeys, shortcut scope, conflicts, or Cmd/Ctrl key combos.' user-invocable: false
Adding Keyboard Shortcuts Guide
Steps to Add a New Hotkey
1. Update Hotkey Constant
In src/types/hotkey.ts:
export const HotkeyEnum = {
// existing...
ClearChat: 'clearChat', // Add new
} as const;
2. Register Default Hotkey
In src/const/hotkeys.ts:
import { KeyMapEnum as Key, combineKeys } from '@lobehub/ui';
export const HOTKEYS_REGISTRATION: HotkeyRegistration = [
{
group: HotkeyGroupEnum.Conversation,
id: HotkeyEnum.ClearChat,
keys: combineKeys([Key.Mod, Key.Shift, Key.Backspace]),
scopes: [HotkeyScopeEnum.Chat],
},
];
3. Add i18n Translation
In src/locales/default/hotkey.ts:
const hotkey: HotkeyI18nTranslations = {
clearChat: {
desc: '清空当前会话的所有消息记录',
title: '清空聊天记录',
},
};
4. Create and Register Hook
In src/hooks/useHotkeys/chatScope.ts:
export const useClearChatHotkey = () => {
const clearMessages = useChatStore((s) => s.clearMessages);
return useHotkeyById(HotkeyEnum.ClearChat, clearMessages);
};
export const useRegisterChatHotkeys = () => {
useClearChatHotkey();
// ...other hotkeys
};
5. Add Tooltip (Optional)
const clearChatHotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.ClearChat));
<Tooltip hotkey={clearChatHotkey} title={t('clearChat.title', { ns: 'hotkey' })}>
<Button icon={<DeleteOutlined />} onClick={clearMessages} />
</Tooltip>;
Best Practices
- Scope: Choose global or chat scope based on functionality
- Grouping: Place in appropriate group (System/Layout/Conversation)
- Conflict check: Ensure no conflict with system/browser shortcuts
- Platform: Use
Key.Modinstead of hardcodedCtrlorCmd - Clear description: Provide title and description for users
Troubleshooting
- Not working: Check scope and RegisterHotkeys hook
- Not in settings: Verify HOTKEYS_REGISTRATION config
- Conflict: HotkeyInput component shows warnings
- Page-specific: Ensure correct scope activation
Related skills
More from lobehub/lobe-chat and the wider catalog.

i18n
Manage multilingual UI strings in LobeHub using react-i18next with flat key conventions.

linear
Manage Linear issues from code: retrieve, update status, link PRs, and add completion comments.

modal
LobeHub imperative modal conventions for createModal, confirmModal, and useModalContext patterns.

project-overview
LobeHub monorepo architecture map for navigating code layers, packages, and project structure.

react
LobeHub React component conventions for TSX UI, styling, routing, and state management.

testing
Vitest testing guide for writing, fixing, and debugging tests in LobeHub projects.