fix: auto-configure sub-agent permissions for parallel research#44
Open
JianyuLin1999 wants to merge 2 commits intoeze-is:mainfrom
Open
fix: auto-configure sub-agent permissions for parallel research#44JianyuLin1999 wants to merge 2 commits intoeze-is:mainfrom
JianyuLin1999 wants to merge 2 commits intoeze-is:mainfrom
Conversation
Claude Code sub-agents don't inherit session-level permissions from settings.local.json (anthropics/claude-code#18950), causing parallel research tasks to fail when sub-agents try to use Bash (CDP curl), WebSearch, or WebFetch. This adds an `ensurePermissions()` step to `check-deps.mjs` that automatically writes the required permissions to `~/.claude/settings.json` (global scope, inherited by all agents including sub-agents). The function is idempotent, non-blocking on failure, and handles fresh installs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
|
在claude code官方更优雅地解决之前我们可以使用一个脚本,确保子agents自动得到权限 |
The initial approach (writing to permissions.allow in settings.json) was incorrect — sub-agents don't inherit permissions.allow at any scope level (anthropics/claude-code#18950, #37730, #25526). PreToolUse hooks are the only permission mechanism that works for sub-agents (highest priority in the permission evaluation flow). This commit: - Adds approve-tools-hook.mjs: auto-approves CDP curl (localhost only), skill scripts, WebSearch, and Jina WebFetch - Replaces ensurePermissions() with ensureHooks() in check-deps.mjs: installs the hook to ~/.claude/hooks/ and registers it in settings.json - Hook is idempotent, non-blocking on failure, auto-refreshes on update Tested with 45 E2E tests covering: all CDP endpoints, dangerous command rejection, WebSearch/WebFetch conditional approval, edge cases, idempotency, existing config preservation, and auto-refresh. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Claude Code 子 Agent 不继承任何级别的
permissions.allow,导致并行调研功能中子 Agent 执行 CDP curl 命令、WebSearch、WebFetch 时被权限拒绝。相关平台 issues:
这是所有使用并行调研功能的用户都会遇到的问题。
Solution
PreToolUse hooks 是唯一对子 Agent 生效的权限机制(权限评估最高优先级)。
新增
approve-tools-hook.mjs,由check-deps.mjs自动安装到~/.claude/hooks/并注册到settings.json。Hook 放行范围:curl ... http://localhost:\d+/node ... (check-deps|cdp-proxy|match-site)r.jina.ai/*其他所有工具调用不输出(走默认权限流程),不影响安全性。
设计要点:
check-deps.mjs调用链,用户无需执行额外命令Changes
scripts/approve-tools-hook.mjsscripts/check-deps.mjsensureHooks()替代原来的ensurePermissions()SKILL.mdREADME.mdTest plan
通过 45 个 E2E 测试:
Hook 行为(28 tests):
Hook 安装(17 tests):
hooks: ok,不重复注册hooks: updated🤖 Generated with Claude Code