-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmigrate-disabled-hooks.js
More file actions
executable file
·85 lines (66 loc) · 2.36 KB
/
migrate-disabled-hooks.js
File metadata and controls
executable file
·85 lines (66 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env node
/**
* Migration script to convert old .disabled hooks to new stub format
* This prevents "file not found" errors when Claude tries to execute disabled hooks
*/
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const hooksDir = path.join(process.env.HOME, '.claude', 'hooks');
console.log(chalk.cyan('\n🔄 Migrating disabled hooks to new format...\n'));
if (!fs.existsSync(hooksDir)) {
console.log(chalk.yellow('No hooks directory found. Nothing to migrate.'));
process.exit(0);
}
const files = fs.readdirSync(hooksDir);
const disabledHooks = files.filter(f => f.endsWith('.py.disabled'));
if (disabledHooks.length === 0) {
console.log(chalk.green('✅ No disabled hooks found to migrate.'));
process.exit(0);
}
console.log(`Found ${disabledHooks.length} disabled hook(s) to migrate:\n`);
let migrated = 0;
let failed = 0;
for (const file of disabledHooks) {
const hookName = file.replace('.py.disabled', '');
const disabledPath = path.join(hooksDir, file);
const hookPath = path.join(hooksDir, `${hookName}.py`);
const originalPath = path.join(hooksDir, `${hookName}.py.original`);
console.log(` • ${hookName}...`);
try {
// Move .disabled to .original
fs.renameSync(disabledPath, originalPath);
// Create stub file
const stubContent = `#!/usr/bin/env python3
"""
Stub for disabled hook: ${hookName}
This hook has been disabled but remains in place to prevent errors.
To re-enable, use: claude-hooks enable ${hookName}
"""
import json
import sys
# Read input to prevent broken pipe errors
try:
json.load(sys.stdin)
except:
pass
# Exit cleanly with a message
print(f"Hook '${hookName}' is currently disabled", file=sys.stderr)
sys.exit(0)
`;
fs.writeFileSync(hookPath, stubContent);
fs.chmodSync(hookPath, '755');
console.log(chalk.green(` ✅ Migrated successfully`));
migrated++;
} catch (error) {
console.log(chalk.red(` ❌ Failed: ${error.message}`));
failed++;
}
}
console.log('\n' + chalk.gray('─'.repeat(50)));
console.log(chalk.green(`✅ Successfully migrated: ${migrated}`));
if (failed > 0) {
console.log(chalk.red(`❌ Failed to migrate: ${failed}`));
}
console.log(chalk.gray('\nDisabled hooks will now exit cleanly without errors.'));
console.log(chalk.gray('Use "claude-hooks enable <hook-name>" to re-enable hooks.\n'));