Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .claude/settings.local.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"hooks": {
"PreToolUse": [
{
"matcher": "Bash|Write|Edit",
"matcher": "Bash|Write|Edit|Replace",
"hooks": [
{
"type": "command",
Expand All @@ -20,7 +20,7 @@
],
"PostToolUse": [
{
"matcher": "Write|Edit",
"matcher": "Write|Edit|Replace",
"hooks": [
{
"type": "command",
Expand Down
38 changes: 32 additions & 6 deletions scripts/deploy-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,43 @@ function deployTo(targetDir) {
if (fs.existsSync(templateSrc)) {
copyFile(templateSrc, path.join(targetClaude, SETTINGS_TEMPLATE));

// settings.local.json を生成 (テンプレートの {{PROJECT_DIR}} を置換)
// settings.local.json を生成 (hooks のみ更新、既存 permissions 等は保持)
const template = fs.readFileSync(templateSrc, "utf8");
const resolved = template.replace(
/\{\{PROJECT_DIR\}\}/g,
targetDir.replace(/\\/g, "\\\\")
);
fs.writeFileSync(
path.join(targetClaude, "settings.local.json"),
resolved
);
console.log(" generated: settings.local.json");
const newSettings = JSON.parse(resolved);
if (
!newSettings ||
typeof newSettings !== "object" ||
Array.isArray(newSettings) ||
!newSettings.hooks ||
typeof newSettings.hooks !== "object" ||
Array.isArray(newSettings.hooks)
) {
throw new Error("Invalid settings template: `hooks` object is required");
}
const settingsDest = path.join(targetClaude, "settings.local.json");

if (fs.existsSync(settingsDest)) {
try {
const parsed = JSON.parse(fs.readFileSync(settingsDest, "utf8"));
const existing =
parsed && typeof parsed === "object" && !Array.isArray(parsed)
? parsed
: {};
existing.hooks = newSettings.hooks;
fs.writeFileSync(settingsDest, JSON.stringify(existing, null, 2) + "\n");
console.log(" updated: settings.local.json (hooks merged, permissions preserved)");
} catch {
fs.writeFileSync(settingsDest, JSON.stringify(newSettings, null, 2) + "\n");
console.log(" WARN: existing settings.local.json was invalid, regenerated");
}
} else {
fs.writeFileSync(settingsDest, JSON.stringify(newSettings, null, 2) + "\n");
console.log(" generated: settings.local.json");
}
}

return true;
Expand Down