Automatically add all shell commands executed by Cursor AI to your Atuin shell history with proper directory scoping.
This hook integration captures every shell command that Cursor runs and adds it to your Atuin history database. Commands are properly scoped to your workspace directory, making them searchable and filterable just like commands you type manually in your terminal.
- Never Lose AI-Generated Commands: All commands Cursor runs are preserved in your searchable Atuin history
- Directory Scoping: Commands are associated with the correct workspace directory, enabling directory-filtered search
- Seamless Integration: Works transparently - no changes to your workflow required
- Complex Command Support: Handles pipes, redirects, multiline commands, heredocs, and special characters
- Cross-Session Access: Search and reuse Cursor's commands from any terminal session
- Learn from AI: Review what commands Cursor used to solve problems for future reference
- Atuin installed and configured
- Cursor editor
jqcommand-line JSON processor (recommended but not required)
- Create the hooks directory:
mkdir -p ~/.cursor/hooks- Create
~/.cursor/hooks.json:
{
"version": 1,
"hooks": {
"beforeShellExecution": [
{
"command": "./hooks/atuin-capture-cwd.sh"
}
],
"afterShellExecution": [
{
"command": "./hooks/atuin-history.sh"
}
]
}
}-
Create
~/.cursor/hooks/atuin-capture-cwd.sh(see file below) -
Create
~/.cursor/hooks/atuin-history.sh(see file below) -
Make scripts executable:
chmod +x ~/.cursor/hooks/atuin-capture-cwd.sh
chmod +x ~/.cursor/hooks/atuin-history.sh- Restart Cursor
The integration uses two hooks:
- beforeShellExecution (
atuin-capture-cwd.sh): Captures the workspace directory before the command runs and stores it temporarily - afterShellExecution (
atuin-history.sh): After the command completes, adds it to Atuin history in the correct directory context
Cursor's beforeShellExecution hook provides the cwd (current working directory), but we want to record commands after they execute successfully. The afterShellExecution hook doesn't include cwd, so we use a temporary file to pass the directory context between hooks.
Once installed, the integration works automatically. Every command Cursor executes will appear in your Atuin history.
# Search all Atuin history (including Cursor commands)
atuin search
# List commands from current directory only
atuin history list --cwd
# Search with Ctrl+R (if configured)
# Commands from Cursor will appear alongside your manual commands- Commands are added with exit code 0 (successful completion)
- The
--separator is used to handle commands starting with dashes - Falls back to
workspace_roots[0]whencwdis empty (Cursor's current behavior) - Uses a subshell to avoid changing the parent shell's directory
- Temporary files are cleaned up after use
- Works with or without
jq(degrades gracefully)
- Check that hooks are configured: Cursor Settings → Hooks tab
- Verify scripts are executable:
ls -l ~/.cursor/hooks/*.sh - Restart Cursor after making changes
- Check Atuin is working:
atuin history list
The hook uses workspace_roots[0] from Cursor. If you have multiple workspace roots, only the first will be used.
MIT
Created to bridge Cursor AI and Atuin shell history for a seamless command-line workflow.