anthropics / anthropics/claude-code

Background subagents (e.g. via /code-review) silently auto-deny gated Bash commands instead of prompting

未关闭
#87,994 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area:agents area:permissions bug has repro platform:windows stale
主要语言
Python
星标
145k
派生
23.1k
PR 合并指标
PR 指标待抓取

描述

## Summary

Since the v2.1.232 change ("Non-teammate agent spawns in interactive sessions now run in the background by default"), gated Bash commands executed inside a background subagent are silently auto-denied instead of surfacing an interactive permission prompt to the user. There is no queue, retry, or notification — the subagent just receives a denial and (in my case) silently degraded to a wrong result instead of failing loudly.

## Reproduction

1. Running Claude Code 2.1.234 on Windows.
2. Ran `/code-review 9953` to review a specific GitHub PR by number.
3. `/code-review` (background-by-default since v2.1.221) spawned a subagent to resolve and review the target.
4. The subagent correctly resolved PR 9953 via `gh pr view 9953` (got the real title/branch back).
5. To get the PR's actual content, it ran `git fetch origin refs/pull/9953/head:pr-9953` and `git fetch origin main`. Both are gated commands not in my allowlist.
6. Because the subagent runs in the background, these calls got the literal tool result `"This command requires approval"` immediately — no prompt ever reached me, and there was no way to approve them.
7. With every fetch path blocked, the subagent fell back to reviewing an unrelated local branch's diff and returned a full, confident-looking code review for the wrong changes entirely — with nothing indicating the fetches had failed.

## Why this matters

- This is effectively silent privilege downgrade with no user-visible signal: normal foreground usage prompts for `git fetch`; the exact same command inside a backgrounded subagent just fails closed with no way to grant it, and the calling flow doesn't surface that failure to the user either.
- I want to keep a strict "always ask" permission posture (no blanket allowlisting), but that posture is currently incompatible with any skill/command that spawns background subagents (e.g. `/code-review`), since those subagents structurally cannot ask.
- The only workaround I've found is `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1`, which disables *all* backgrounding (fire-and-forget agents, Ctrl+B, concurrent review agents, long-running background Bash), not just the permission-prompt gap. That's a much blunter fix than the actual problem calls for.
- This looks related to the already-closed #36042 ("Background sub-agents silently blocked by permission prompts"), closed "not planned," but it's now hitting a first-party bundled command (`/code-review`), not just custom MCP tool usage, which raises the stakes.

## Suggested fixes (any of these would help)

- Surface a queued/async permission prompt for background subagent tool calls, so approving mid-run is possible instead of only pre-launch prediction.
- At minimum, make the auto-deny result loud: have the calling skill/agent detect "requires approval" denials and report to the user that the review is incomplete/degraded, rather than silently substituting a different target.
- Let `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS` (or a new, narrower setting) apply only to permission-gated calls, so foreground-prompting can be preserved without losing backgrounding entirely.

## Environment

- Claude Code 2.1.234
- Windows 11, Git Bash
- Permission mode: default (no allowlist for `git fetch`/`gh`)

贡献指南

这个仓库没有索引到贡献指南

调研方向

Reproduce the issue with Claude Code 2.1.234 on Windows using `/code-review 9953`, with no allowlist entries for `git fetch` or `gh`. Observe the background subagent's results for `gh pr view 9953` and the two fetch commands; done means gated commands no longer disappear silently, either by surfacing an approval path or clearly reporting that the review is incomplete.

由索引模型根据 Issue 内容生成。

评估

技术栈
git, github, python
领域
cli, developer-experience, security
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
活跃
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。