Claude shrink hook: `allow` decision, changed command text and lost input fields
What happen
In compress mode, the Claude Code PreToolUse shrink hook rewrites a Bash command to <caveman> shrink -- <command>. The source shows three defects:
- Approval. The hook returns
permissionDecision: "allow"for each command that its filter accepts. The filter accepts commands that change state, for examplegit push --force,git reset --hard,kubectl delete,awsandgh. - Changed command text. Permission rules evaluate the rewritten input. A rule such as
Bash(git push:*)can then stop matching the command. Removingallowdoes not fix this defect. - Lost input fields.
updatedInputcontains onlycommand. The hook reference states thatupdatedInputreplaces the whole input. Thus the input losestimeout,run_in_backgroundanddescription.
I verified the source part of this report. I did not verify the host behavior yet. Each host statement below is a prediction from the Claude Code documentation until the host tests run.
1. The hook returns allow
The Claude Code output of shrinkHook is:
{ hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "allow", updatedInput: { command: rewritten } } }shouldShrink accepts a command whose first word is in SHRINK_ALLOW:
git cargo go npm pnpm yarn pip pip3 pytest make jest vitest tsc eslint mypy ruff pylint mvn gradle
dotnet rspec bundle grep rg ag egrep fgrep find ls tree du df ps docker kubectl terraform helm
aws gcloud az ghThe filter rejects shell operators and some streaming flags. It excludes a few first-two-token pairs, for example git commit, docker exec and terraform apply. The pair check reads only the first two tokens, so a global option before the subcommand passes the filter:
git -C . commitpasses, although the filter excludesgit commit.docker --context example exec example idpasses, although the filter excludesdocker exec.
The streaming pattern rejects -f, so git push -f does not pass. git push --force passes.
The hook reference states that deny and ask rules still apply after a hook returns allow. Thus the predicted effect is narrower than "every accepted command runs without a prompt". Where no rule covers the command and the permission mode asks, the allow decision can remove that prompt.
The code comment above shrinkHook describes the same risk for Codex (#1037). The fix for #1037 removed Codex from the hook. The Claude Code branch still returns allow.
2. The rewrite changes the text that rules match
The rewritten command is:
'<path to caveman>' shrink -- git push --dry-run origin mainThe hook reference states that permission rules evaluate the rewritten input. A rule for Bash(git push:*) can then stop matching the command. This defect stays after the fix removes allow. This report makes no claim about other PreToolUse hooks. Matching hooks run in parallel, and the reference does not state that one hook receives the output of another.
I saw this problem in one Claude Code session. That session entered a git worktree through the EnterWorktree tool. In it, a plain git status was refused with this message:
This session is isolated in the worktree ..., but this command runs caveman with a git command among its operands: what runs it, and from which directory or root, cannot be read here (name git right after the launcher and its options) ... Refusing to run it
Git worked again after I set think.mode to record. I did not record the Claude Code version. The component that produced the refusal is not known. The host tests below check if the refusal depends on the rewrite.
3. The rewrite loses input fields
updatedInput is { command: rewritten }. The hook reference states that updatedInput replaces the whole input. An input with timeout, run_in_background or description loses these fields. This changes how the command runs, not only how rules match it.
Expected
- The shrink hook returns no permission decision. The normal permission flow of Claude Code decides.
- Permission rules match the original command. If the host cannot match rules against the original command, the hook does not rewrite it.
- The rewrite copies each input field and changes only
command. - Two decisions stay separate: which commands have output that the hook can compress, and which permission decision applies. The hook makes only the first decision.
Proposed fix
- Remove
permissionDecision: "allow"from the Claude Code output ofshrinkHook. If the host requires a decision together withupdatedInput, stop the rewrite for Claude Code, as #1037 did for Codex. - Copy the original
tool_inputintoupdatedInputand replace onlycommand. - Keep rule matching on the rewritten text safe. If the hook cannot do this, do not rewrite commands that a permission rule can cover.
- Make the filter read the subcommand after global options, or remove the exclusion pairs together with the
allowdecision.
Acceptance criteria, one for each defect:
- Approval: with the hook present, a command without a matching rule gives the same prompt as with the hook absent.
- Rule matching: an ask rule and a deny rule for the original command apply with the hook present.
- Input fields: each input field except
commandis equal before and after the rewrite. - Filter: tests include global options before the subcommand, for example
git -C . commit, and flags that write, for examplegit diff --output=file.
Before/after example
Input: git push --force origin main
Got: {"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "allow",
"updatedInput": {"command": "'<path to caveman>' shrink -- git push --force origin main"}}}
Want: {"hookSpecificOutput": {"hookEventName": "PreToolUse",
"updatedInput": {<all original input fields>, "command": "<rewritten command>"}}}
with no permission decision, and permission rules that still match the original command.
If the host cannot match rules against the original command, no rewrite.Platform
- Claude Code
- Codex
- Other: ___
Version / install method
caveman v2.7.0: the global npm CLI @caveman-ai/cli with the native Claude Code integration, which writes the caveman shrink-hook PreToolUse entry into ~/.claude/settings.json. Source details:
- caveman v2.7.0, plugin cache
caveman/caveman/2.7.0 packages/cli/src/index.ts, SHA-25683d332977a47d3bc281b3780819519ba779409fa41e04964d59c1f1d4a354d35SHRINK_ALLOWat line 13864,shouldShrinkat lines 13877–13893, and theshrinkHookoutput at line 13940mainon 2026-09-28, with the same code (line numbers onmaincan change).
Reproduction
Source part (verified)
Run the extracted shouldShrink and shrinkHook functions of the pinned file above with simulated input, configuration, executable lookup and output. Do not run the command strings. The source part shows:
- the
allowdecision forgit push --force,git reset --hard,kubectl delete,aws s3 rmandgh repo delete - the two filter bypasses above
- an
updatedInputthat contains onlycommand
Host part (not run yet)
Fixture:
- A source repository and a bare destination repository, both new, in a temporary directory.
GIT_CONFIG_GLOBAL=/dev/nullandGIT_CONFIG_NOSYSTEM=1, so no user or system Git configuration applies.- In the local configuration of both repositories:
core.hooksPathset to an empty directory,protocol.allow=neverandprotocol.file.allow=always. Thus no Git hook, remote helper or external transport runs. A localgit push --dry-runcan run apre-pushhook, so this control is necessary. - The command text is
git push --dry-run origin main, with no-coption, because a-coption changes the tokens thatshouldShrinkreads. - Before each case, the fixture makes sure that the remote references are unchanged and the hooks directory is empty.
Record for each run: the Claude Code version, the permission mode, the permission rules and the active hooks.
Conditions. Each condition runs in a new session with the same permission mode and the same rules:
- A: no shrink hook.
- B: the hook as released:
allowand the rewrittenupdatedInput. - C: the same rewritten
updatedInputand nopermissionDecision. - D:
allowand anupdatedInputequal to the original input.
Comparisons. Each pair changes one thing only:
- Approval defect: B against C, and D against A.
- Rewrite defect: C against A, and B against D.
- Rule matching: the rewrite comparisons, in a case with an ask rule and a case with a deny rule. A case without a matching rule gives evidence only for the approval comparisons.
- Input fields: a separate case whose original input has
command,timeout,run_in_backgroundanddescription. It compares the input that the tool receives in C with the original input. The permission cases use an input withcommandonly. - Worktree refusal: the rewrite comparisons in a worktree session. A refusal in B and C, and none in A and D, connects the refusal to the rewrite. It does not name the component that refuses.
For each case and condition, record these items:
- The original command
- The rewritten command
- If a prompt appeared
- If the command ran
- The input fields that the tool received
Workaround
caveman config set think.shrink false
caveman doctor claude --fixAfter these commands, ~/.claude/settings.json has no shrink-hook entry, and the other caveman hooks stay. You can also set think.mode to record, but that setting turns off all compression.
Related
- #1037: Codex re-prompts for already-approved commands after the shrink rewrite. The fix removed Codex from the hook.
- #1049: the native install always added the shrink hook. The fix made
think.shrink=falsework. That issue notes that theallowdecision widens the permission grant on Codex.
Generated with Claude Code
Source: JuliusBrussee/caveman