fix(cli-claude): stop rewriting Bash commands in PreToolUse auth-scrub hook#202
Open
danljungstrom wants to merge 1 commit into
Open
Conversation
…b hook The Agent SDK PreToolUse hook prepended an `unset ANTHROPIC_API_KEY ...;` prelude to every Bash command before Claude Code's permission layer saw it, which broke Bash prefix allow rules (e.g. `Bash(gh:*)`), triggered auto-mode "unsetting auth tokens" denials for benign commands, and spammed mobile permission prompts showing the preamble instead of the real command. Auth-token isolation remains enforced via subprocess env scrubbing (isolateClaudeRuntimeAuthEnv / buildClaudeSubprocessEnv); shell snapshots capture only PATH, so the command rewrite added no protection beyond the env scrub. Co-Authored-By: Claude Fable 5 <[email protected]>
Contributor
WalkthroughThe Claude Agent SDK no longer rewrites Bash commands through a ChangesClaude hook removal
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
Removes the Bash command rewrite from the Claude Agent SDK PreToolUse auth-scrub hook. Auth-token isolation stays enforced via subprocess env scrubbing; the hook no longer mutates commands before Claude Code's permission layer sees them.
Why
The hook prepended an
unset ANTHROPIC_API_KEY ...;prelude to every Bash command, which:Bash(gh:*)), since the rewritten command no longer started with the allowed prefixThe rewrite added no protection beyond the existing env scrub: subprocess env is already sanitized by
isolateClaudeRuntimeAuthEnv/buildClaudeSubprocessEnv, and shell snapshots capture onlyPATH.How to test
cd apps/cli && yarn vitest run src/backends/claude/remote/claudeRemoteAgentSdk.optionsAndHooks.test.ts— hook tests assert Bash commands pass through unmodified and env scrubbing still applies.cd apps/cli && yarn typecheckBash(gh:*)allow rule in.claude/settings.json; run aghcommand and confirm it is auto-allowed without a permission prompt (previously denied/prompted because the command was rewritten).ANTHROPIC_API_KEYset in the daemon environment is still absent from the spawned Claude subprocess env.Screenshots / recording (UI changes)
N/A — CLI-only change.
Notes (optional)
Security: no weakening of auth isolation. The command mutation was a redundant second layer on top of subprocess env scrubbing, and it broke permission-rule matching as a side effect. Changed files:
apps/cli/src/backends/claude/remote/agentSdk/buildClaudeAgentSdkHooks.ts— remove Bash command mutationapps/cli/src/backends/claude/remote/claudeRemoteAgentSdk.optionsAndHooks.test.ts— update hook tests to assert pass-throughChecklist
dev(notmain)AI-assisted (Claude Code). Verified by running the updated hook test file and CLI typecheck locally.
🤖 Generated with Claude Code