Skip to content

hook claude: mark a fish wrap in the decision instead of matching the rewritten string #4762

Closed

Description

@KuSh

Follow-up from #4127, which adds the opt-in fish wrap (hooks.wrap_fish_scripts = true) on rtk hook claude. Everything below needs the flag on; with it off, the hook answers exactly as before.

Two places rediscover from strings what the decision already knows.

1. The explicit ask is chosen by matching the rewritten command. process_claude_payload_from_decision treats any rewritten command that starts with rtk run --shell fish -c ' as a wrap. It exempts a command the agent already typed in that form. The exemption compares the typed text, so it misses when the rewrite rules normalise the start of the command. Measured with fish on PATH, the flag on, and settings allowing Bash(rtk:*) and Bash(git:*):

typed command rewritten decision
rtk run --shell fish -c 'echo ok' && git status rtk run --shell fish -c 'echo ok' && rtk git status allow (as without the flag)
\, newline, rtk run --shell fish -c 'echo ok' && git status the same ask

The second row is only an extra prompt: a settings deny still wins over a hook's ask. But every normalisation the rewrite rules gain at the start of a command becomes another such case.

2. The attestation gate re-implements part of try_wrap. permissions::claude_hook_deny_rules_for walks the Claude settings a second time whenever a command is provably fish. It does so even when try_wrap will refuse the command anyway:

  • its first word is rtk;
  • it has a substitution or a file redirect;
  • it has \\, \' or &|;
  • its comment parses differently in the two shells;
  • or the verdict is already Deny.

Measured with an unparsable ~/.claude/settings.json: rtk git status; and true prints the failed to parse permissions warning 4 times, where git status prints it 2 times. For a command that is wrapped, the verdict and the attestation also read the same files twice. One load_permission_rules_tracking call could feed both.

What would remove both:

  • decide_with_wrap says when it wrapped, through a distinct HookDecision variant or a flag on AskRewrite. The Claude hook sets ask from that, and fish_script::is_wrapped plus the typed-form exemption go away.
  • The attestation is computed lazily, after try_wrap's pure gates and the fish probe pass, from the same settings read as the verdict.

Tests that should hold afterwards:

  • the line-continuation row above gives allow;
  • with the flag on and an unparsable settings file, a fish command try_wrap refuses warns as often as git status;
  • every wrap RTK builds still carries "permissionDecision": "ask" (a_wrap_carries_an_explicit_ask).

Activity

  1. rtk-wshm-sync-bot commented on Oct 23, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 78%

    Summary

    Fish-wrap detection in rtk hook claude re-derives wrap state by string-matching rewritten commands and re-walks permission settings separately, causing missed exemptions and duplicate file reads; should instead propagate wrap state from decide_with_wrap/try_wrap.

    📁 Relevant files
    • src/hook/claude.rs
    • src/fish_script.rs
    • src/permissions.rs

    Suggested Actions

    1. Follow-up from feat(hooks): wrap unambiguously-fish scripts as rtk run --shell fish #4127; add a HookDecision/AskRewrite field so decide_with_wrap reports wrap state directly
    2. Remove fish_script::is_wrapped and the typed-form exemption in favor of that explicit signal
    3. Make attestation computation lazy, reusing the single load_permission_rules_tracking read from the verdict
    4. Verify the three listed tests (a_wrap_carries_an_explicit_ask, line-continuation allow, duplicate-warning count) pa…

    Triaged automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions