@jjdenhertog/ai-driven-development
Version:
AI-driven development workflow with learning capabilities for Claude
84 lines • 2.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = addHooks;
const fs_extra_1 = require("fs-extra");
const node_path_1 = require("node:path");
const logger_1 = require("../logger");
function addHooks(path) {
const claudeSettingsPath = (0, node_path_1.join)(path, '.claude', 'settings.json');
const claudeSettingsDir = (0, node_path_1.join)(path, '.claude');
// Ensure ~/.claude directory exists
(0, fs_extra_1.ensureDirSync)(claudeSettingsDir);
// Define the hooks configuration
// Only log essential hooks for meaningful insights:
// - PreToolUse: What tool is about to run and its inputs
// - PostToolUse: Tool results and timing
// - Notification: Claude's status messages and progress updates
const hooksConfig = {
"PreToolUse": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "aidev log raw"
}
]
}
],
"Stop": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "aidev log raw"
}
]
}
],
"PostToolUse": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "aidev log raw"
}
]
}
],
"Notification": [
{
"hooks": [
{
"type": "command",
"command": "aidev log raw"
}
]
}
]
};
// Read existing settings or create new
let settings = {};
if ((0, fs_extra_1.existsSync)(claudeSettingsPath)) {
try {
settings = (0, fs_extra_1.readJsonSync)(claudeSettingsPath);
}
catch (_a) {
(0, logger_1.log)('Warning: Could not parse existing Claude settings.json', 'warn');
settings = {};
}
}
// Ensure hooks object exists
if (!settings.hooks) {
settings.hooks = {};
}
// Simply overwrite our hooks while preserving any others
for (const [hookType, hookConfig] of Object.entries(hooksConfig)) {
settings.hooks[hookType] = hookConfig;
}
(0, fs_extra_1.writeFileSync)(claudeSettingsPath, JSON.stringify(settings, null, 2));
(0, logger_1.log)('Updated Claude Code hooks configuration in .claude/settings.json', 'success');
}
//# sourceMappingURL=addHooks.js.map