anthropics / anthropics/claude-code

[BUG] Startup workspace-trust dialog does not warn about hooks in .claude/settings.json, while the /cd dialog does

Đang mở
#94,277 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
area:hooks area:security bug has repro platform:macos
Ngôn ngữ chính
Python
Star
145k
Fork
23.1k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

### Preflight Checklist

- [x] I have searched [existing issues](https://github.com/anthropics/claude-code/issues?q=is%3Aissue%20state%3Aopen%20label%3Abug) and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code

### What's Wrong?

The two trust dialogs disclose different things for the same directory.

Starting `claude` inside an untrusted directory whose `.claude/settings.json` defines a
`PreToolUse` command hook shows (2.1.270, verbatim):

```
Accessing workspace:
/Users/flo/claude-poc-sandbox/parent/sub
Quick safety check: Is this a project you created or one you trust? (Like your
own code, a well-known open source project, or work from your team). If not,
take a moment to review what's in this folder first.
Claude Code'll be able to read, edit, and execute files here.
Security guide
❯ No, exit
Yes, I trust this folder
```

No mention of hooks. Using `/cd` into the very same directory from a trusted session shows:

```
Moving to a new directory:
/Users/flo/claude-poc-sandbox/parent/sub
This session hasn't worked here before. Is this a directory you created or one you trust?
Claude Code'll be able to read, edit, and execute files here.
⚠ This directory configures hooks that run commands, declared in .claude/settings.json
These will apply to this session as soon as you move. Only proceed if you trust this configuration.
❯ No, stay put
Yes, move here
```

The startup dialog already inspects the settings file for pre-approved permissions (see #87012,
"This folder pre-approves 35 tool permissions in .claude/settings.local.json"), so the hook check
that `/cd` performs should be cheap to add there. Hooks are the more consequential of the two:
they run commands on the first tool call regardless of what the user later approves.

### What Should Happen?

The startup trust dialog should carry the same hook warning as the `/cd` dialog, naming the file
and ideally the event types and commands, e.g.:

```
⚠ This folder configures hooks that run commands, declared in .claude/settings.json
PreToolUse: /Users/flo/claude-poc-sandbox/fire.sh SUB_HOOK
These will run as soon as you start using tools. Only proceed if you trust this configuration.
```

### Error Messages/Logs

```shell
n/a (dialog text above)
```

### Steps to Reproduce

1. Create an untrusted repo with a command hook:
```sh
mkdir -p /tmp/hookrepo/.claude && cd /tmp/hookrepo && git init -q
cat > .claude/settings.json <<'JSON'
{"hooks":{"PreToolUse":[{"matcher":"","hooks":[{"type":"command","command":"touch /tmp/hookrepo/HOOK_FIRED"}]}]}}
JSON
```
Make sure `~/.claude.json` has no `projects["/tmp/hookrepo"]` entry.
2. `cd /tmp/hookrepo && claude` → dialog shown without any hook warning. Choose "No, exit".
3. `cd /tmp && claude`, trust `/tmp` if asked, then `/cd /tmp/hookrepo` → dialog shown **with**
the hook warning.
4. Accept in step 3, ask Claude to run `ls`, observe `/tmp/hookrepo/HOOK_FIRED` exists.
(Same would happen after accepting in step 2, without having been told.)

### Claude Model

Other

### Is this a regression?

I don't know

### Last Working Version

n/a

### Claude Code Version

2.1.270

### Platform

Anthropic API

### Operating System

macOS

### Terminal/Shell

iTerm2

### Additional Information

- Related: #87012 (same dialog, truncated permissions list), #92911 (trust prompt suppressed,
hooks silently disabled), #67319 (VS Code never shows the dialog).
- The `/cd` dialog's behavior is good and not documented; the docs for `/cd` (v2.1.246 notes)
say settings are re-read but not that trust is re-evaluated. Worth a line in the docs.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.