Skip to content

Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.

fix(init): allow graft CLI in generated Claude permissions — headless runs were denied

Shrish Dwivedi0702f6c2042c
diff --git a/src/claude/settings-merge.ts b/src/claude/settings-merge.ts
index 560568ca..d0cdd244 100644
--- a/src/claude/settings-merge.ts
+++ b/src/claude/settings-merge.ts
@@ -2,6 +2,7 @@ type Json = Record<string, any>;
const SL_CMD = 'node "${CLAUDE_PROJECT_DIR:-.}/.claude/helpers/graft-statusline.cjs"';
const FOOTER = 'graft/[\\w./-]+\\.md';
+const ALLOW_ENTRIES = ['Bash(graft:*)', 'Bash(npx graft:*)'];
function hookCmd(arg: string): string {
return `node "\${CLAUDE_PROJECT_DIR:-.}/.claude/helpers/graft-hooks.cjs" ${arg}`;
@@ -41,5 +42,14 @@ export function mergeGraftSettings(existing: Json): { merged: Json; warnings: st
if (!footer.includes(FOOTER)) footer.push(FOOTER);
merged.footerLinksRegexes = footer;
+ // headless/subagent runs hard-deny Bash by default; without an allowlist entry
+ // `graft ask`'s own Bash calls (and the skill it installs) can't run out-of-box.
+ merged.permissions = { ...(merged.permissions ?? {}) };
+ const allow = Array.isArray(merged.permissions.allow) ? [...merged.permissions.allow] : [];
+ for (const entry of ALLOW_ENTRIES) {
+ if (!allow.includes(entry)) allow.push(entry);
+ }
+ merged.permissions.allow = allow;
+
return { merged, warnings };
}
diff --git a/test/claude-init.test.ts b/test/claude-init.test.ts
index 63ebe3e3..19cdcd7a 100644
--- a/test/claude-init.test.ts
+++ b/test/claude-init.test.ts
@@ -29,6 +29,7 @@ test('runInit scaffolds settings + both shims + the skill (build skipped)', () =
const s = JSON.parse(readFileSync(join(d, '.claude', 'settings.json'), 'utf8'));
assert.ok(s.statusLine.command.includes('graft-statusline.cjs'));
assert.ok(s.hooks.Stop[0].hooks[0].command.includes('graft-hooks.cjs'));
+ assert.deepEqual(s.permissions.allow, ['Bash(graft:*)', 'Bash(npx graft:*)']);
});
test('runInit overwrites a stale skill file', () => {
@@ -57,6 +58,16 @@ test('runInit is idempotent', () => {
runInit(d, { build: false });
const s = JSON.parse(readFileSync(join(d, '.claude', 'settings.json'), 'utf8'));
assert.equal(s.hooks.PostToolUse.length, 1);
+ assert.deepEqual(s.permissions.allow, ['Bash(graft:*)', 'Bash(npx graft:*)']);
+});
+
+test('runInit appends the allowlist to a pre-existing permissions block, preserving unrelated entries', () => {
+ const d = fresh();
+ mkdirSync(join(d, '.claude'), { recursive: true });
+ writeFileSync(join(d, '.claude', 'settings.json'), JSON.stringify({ permissions: { allow: ['Bash(ls)'] } }));
+ runInit(d, { build: false });
+ const s = JSON.parse(readFileSync(join(d, '.claude', 'settings.json'), 'utf8'));
+ assert.deepEqual(s.permissions.allow, ['Bash(ls)', 'Bash(graft:*)', 'Bash(npx graft:*)']);
});
test('postinstall prints the nudge in a fresh dir', () => {
diff --git a/test/claude-settings-merge.test.ts b/test/claude-settings-merge.test.ts
index 310e2ef6..a306e1ce 100644
--- a/test/claude-settings-merge.test.ts
+++ b/test/claude-settings-merge.test.ts
@@ -43,5 +43,41 @@ test('re-running is idempotent (no duplicate Graft entries or footer)', () => {
test('foreign top-level keys survive', () => {
const { merged } = mergeGraftSettings({ model: 'claude-sonnet-5', permissions: { allow: ['Bash(ls)'] } });
assert.equal(merged.model, 'claude-sonnet-5');
- assert.deepEqual(merged.permissions.allow, ['Bash(ls)']);
+ assert.deepEqual(merged.permissions.allow, ['Bash(ls)', 'Bash(graft:*)', 'Bash(npx graft:*)']);
+});
+
+test('fresh init adds the graft CLI allowlist', () => {
+ const { merged } = mergeGraftSettings({});
+ assert.deepEqual(merged.permissions.allow, ['Bash(graft:*)', 'Bash(npx graft:*)']);
+});
+
+test('re-init does not duplicate allowlist entries', () => {
+ const once = mergeGraftSettings({}).merged;
+ const twice = mergeGraftSettings(once).merged;
+ assert.deepEqual(twice.permissions.allow, ['Bash(graft:*)', 'Bash(npx graft:*)']);
+});
+
+test('pre-existing unrelated allow entries are preserved and ours appended', () => {
+ const existing = { permissions: { allow: ['Bash(ls)', 'Bash(git:*)'] } };
+ const { merged } = mergeGraftSettings(existing);
+ assert.deepEqual(merged.permissions.allow, ['Bash(ls)', 'Bash(git:*)', 'Bash(graft:*)', 'Bash(npx graft:*)']);
+});
+
+test('pre-existing allow list already containing Bash(graft:*) is left unchanged aside from the missing entry', () => {
+ const existing = { permissions: { allow: ['Bash(graft:*)'] } };
+ const { merged } = mergeGraftSettings(existing);
+ assert.deepEqual(merged.permissions.allow, ['Bash(graft:*)', 'Bash(npx graft:*)']);
+});
+
+test('pre-existing allow list already containing both entries is unchanged', () => {
+ const existing = { permissions: { allow: ['Bash(graft:*)', 'Bash(npx graft:*)'] } };
+ const { merged } = mergeGraftSettings(existing);
+ assert.deepEqual(merged.permissions.allow, ['Bash(graft:*)', 'Bash(npx graft:*)']);
+});
+
+test('permissions object with no allow key gets one added; other keys preserved', () => {
+ const existing = { permissions: { deny: ['Bash(rm:*)'] } };
+ const { merged } = mergeGraftSettings(existing);
+ assert.deepEqual(merged.permissions.deny, ['Bash(rm:*)']);
+ assert.deepEqual(merged.permissions.allow, ['Bash(graft:*)', 'Bash(npx graft:*)']);
});