#1133·caveman

Claude shrink hook: `allow` decision, changed command text and lost input fields

Author: zsltgCreated Sep 28, 2026Updated Sep 28, 2026

What happen

In compress mode, the Claude Code PreToolUse shrink hook rewrites a Bash command to <caveman> shrink -- <command>. The source shows three defects:

  1. Approval. The hook returns permissionDecision: "allow" for each command that its filter accepts. The filter accepts commands that change state, for example git push --force, git reset --hard, kubectl delete, aws and gh.
  2. Changed command text. Permission rules evaluate the rewritten input. A rule such as Bash(git push:*) can then stop matching the command. Removing allow does not fix this defect.
  3. Lost input fields. updatedInput contains only command. The hook reference states that updatedInput replaces the whole input. Thus the input loses timeout, run_in_background and description.

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:

typescript
{ hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "allow", updatedInput: { command: rewritten } } }

shouldShrink accepts a command whose first word is in SHRINK_ALLOW:

bash
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 gh

The 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 . commit passes, although the filter excludes git commit.
  • docker --context example exec example id passes, although the filter excludes docker 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 main

The 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

  1. Remove permissionDecision: "allow" from the Claude Code output of shrinkHook. If the host requires a decision together with updatedInput, stop the rewrite for Claude Code, as #1037 did for Codex.
  2. Copy the original tool_input into updatedInput and replace only command.
  3. Keep rule matching on the rewritten text safe. If the hook cannot do this, do not rewrite commands that a permission rule can cover.
  4. Make the filter read the subcommand after global options, or remove the exclusion pairs together with the allow decision.

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 command is equal before and after the rewrite.
  • Filter: tests include global options before the subcommand, for example git -C . commit, and flags that write, for example git 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-256 83d332977a47d3bc281b3780819519ba779409fa41e04964d59c1f1d4a354d35
  • SHRINK_ALLOW at line 13864, shouldShrink at lines 13877–13893, and the shrinkHook output at line 13940
  • main on 2026-09-28, with the same code (line numbers on main can 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 allow decision for git push --force, git reset --hard, kubectl delete, aws s3 rm and gh repo delete
  • the two filter bypasses above
  • an updatedInput that contains only command

Host part (not run yet)

Fixture:

  • A source repository and a bare destination repository, both new, in a temporary directory.
  • GIT_CONFIG_GLOBAL=/dev/null and GIT_CONFIG_NOSYSTEM=1, so no user or system Git configuration applies.
  • In the local configuration of both repositories: core.hooksPath set to an empty directory, protocol.allow=never and protocol.file.allow=always. Thus no Git hook, remote helper or external transport runs. A local git push --dry-run can run a pre-push hook, so this control is necessary.
  • The command text is git push --dry-run origin main, with no -c option, because a -c option changes the tokens that shouldShrink reads.
  • 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: allow and the rewritten updatedInput.
  • C: the same rewritten updatedInput and no permissionDecision.
  • D: allow and an updatedInput equal 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_background and description. It compares the input that the tool receives in C with the original input. The permission cases use an input with command only.
  • 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

bash
caveman config set think.shrink false
caveman doctor claude --fix

After 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=false work. That issue notes that the allow decision widens the permission grant on Codex.

Generated with Claude Code