fix(setup): auto-allowlist bd commands in Claude Code (#511)
Add bd to Claude Code allowedTools when running `bd setup claude` so that all bd commands (create, update, close, etc.) can run without requiring per-command approval. Changes: - Add addAllowedTool() and removeAllowedTool() helper functions - InstallClaude() now adds "Bash(bd:*)" to allowedTools - RemoveClaude() cleans up the allowedTools entry - Add tests for new functionality Users who have already run `bd setup claude` can run it again to add the missing allowedTools entry while keeping their existing hooks. Fixes #511 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -65,6 +65,11 @@ func InstallClaude(project bool, stealth bool) {
|
||||
fmt.Println("✓ Registered PreCompact hook")
|
||||
}
|
||||
|
||||
// Add bd to allowedTools so commands don't require per-command approval
|
||||
if addAllowedTool(settings, "Bash(bd:*)") {
|
||||
fmt.Println("✓ Added bd to allowedTools (no per-command approval needed)")
|
||||
}
|
||||
|
||||
// Write back to file
|
||||
data, err = json.MarshalIndent(settings, "", " ")
|
||||
if err != nil {
|
||||
@@ -149,6 +154,9 @@ func RemoveClaude(project bool) {
|
||||
removeHookCommand(hooks, "SessionStart", "bd prime --stealth")
|
||||
removeHookCommand(hooks, "PreCompact", "bd prime --stealth")
|
||||
|
||||
// Remove bd from allowedTools
|
||||
removeAllowedTool(settings, "Bash(bd:*)")
|
||||
|
||||
// Write back
|
||||
data, err = json.MarshalIndent(settings, "", " ")
|
||||
if err != nil {
|
||||
@@ -164,6 +172,49 @@ func RemoveClaude(project bool) {
|
||||
fmt.Println("✓ Claude hooks removed")
|
||||
}
|
||||
|
||||
// addAllowedTool adds a tool pattern to allowedTools if not already present
|
||||
// Returns true if tool was added, false if already exists
|
||||
func addAllowedTool(settings map[string]interface{}, tool string) bool {
|
||||
// Get or create allowedTools array
|
||||
allowedTools, ok := settings["allowedTools"].([]interface{})
|
||||
if !ok {
|
||||
allowedTools = []interface{}{}
|
||||
}
|
||||
|
||||
// Check if tool already in list
|
||||
for _, t := range allowedTools {
|
||||
if t == tool {
|
||||
fmt.Printf("✓ Tool already in allowedTools: %s\n", tool)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Add tool to array
|
||||
allowedTools = append(allowedTools, tool)
|
||||
settings["allowedTools"] = allowedTools
|
||||
return true
|
||||
}
|
||||
|
||||
// removeAllowedTool removes a tool pattern from allowedTools
|
||||
func removeAllowedTool(settings map[string]interface{}, tool string) {
|
||||
allowedTools, ok := settings["allowedTools"].([]interface{})
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// Filter out the tool
|
||||
var filtered []interface{}
|
||||
for _, t := range allowedTools {
|
||||
if t != tool {
|
||||
filtered = append(filtered, t)
|
||||
} else {
|
||||
fmt.Printf("✓ Removed %s from allowedTools\n", tool)
|
||||
}
|
||||
}
|
||||
|
||||
settings["allowedTools"] = filtered
|
||||
}
|
||||
|
||||
// addHookCommand adds a hook command to an event if not already present
|
||||
// Returns true if hook was added, false if already exists
|
||||
func addHookCommand(hooks map[string]interface{}, event, command string) bool {
|
||||
|
||||
Reference in New Issue
Block a user