Skip to content

feat(hooks): add if field to markitdown and deny-vendor-write hooks#124

Merged
amondnet merged 4 commits intomainfrom
amondnet/fantastic-shrimp
Mar 28, 2026
Merged

feat(hooks): add if field to markitdown and deny-vendor-write hooks#124
amondnet merged 4 commits intomainfrom
amondnet/fantastic-shrimp

Conversation

@amondnet
Copy link
Copy Markdown
Contributor

@amondnet amondnet commented Mar 28, 2026

Summary

  • Add if field (permission rule syntax filter) to markitdown PreToolUse hook — only fires on binary doc extensions (*.pptx, *.docx, *.xlsx, *.xls, *.ppt, *.doc) instead of every Read call
  • Add if field to deny-vendor-write PreToolUse hook — only fires on edits targeting vendor/ or sources/ paths instead of every Edit/Write call
  • Reduces unnecessary hook process spawns for improved performance

Test plan

  • Verify markitdown hook still shows warning when reading .docx/.pptx/.xlsx files
  • Verify markitdown hook does NOT fire on .ts/.md/.json reads
  • Verify deny-vendor-write still blocks edits to vendor/ and sources/ paths
  • Verify deny-vendor-write does NOT fire on normal file edits
  • claude plugin validate plugins/markitdown passes

Summary by cubic

Added an if filter to the markitdown PreToolUse hook so it only runs on binary document reads, reducing unnecessary hook spawns. Dropped the planned deny-vendor-write filter due to permission rule limits (no alternation).

  • New Features

    • markitdown PreToolUse now runs only for Read on: .pptx, .docx, .xlsx, .xls, .ppt, .doc
  • Refactors

    • Split markitdown into six single-pattern entries since permission rules don’t support alternation.

Written for commit 5250912. Summary will update on new commits.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
claude-code-plugins Ready Ready Preview, Comment Mar 28, 2026 2:52pm

Request Review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the if field to several hooks to improve performance by filtering tool-call invocations before spawning processes. It also includes a new track for this feature with a plan and specification. Several critical issues were identified in the implementation: the added if fields in .claude/settings.json and plugins/markitdown/hooks/hooks.json contain syntax errors (missing commas) that break JSON parsing. Additionally, the glob patterns used for vendor/sources filtering are too broad and should be refined to target specific directories. There is also a consistency issue in the specification regarding PDF support that does not match the actual implementation.

Comment thread .claude/settings.json Outdated
Comment thread plugins/markitdown/hooks/hooks.json Outdated
Comment thread .please/docs/tracks/active/hooks-if-field-20260328/plan.md Outdated
Comment thread .please/docs/tracks/active/hooks-if-field-20260328/spec.md Outdated
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 6 files

Confidence score: 4/5

  • This PR is likely safe to merge with minimal risk: the reported issue is moderate-low severity (4/10) and appears limited to hook filtering behavior rather than core runtime functionality.
  • In .claude/settings.json, the *vendor* / *sources* patterns are substring matches, so the hook may still trigger on unrelated files and reduce the expected performance improvement.
  • Pay close attention to .claude/settings.json - tighten the filter patterns to target actual vendor/sources directories and avoid unintended hook executions.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".claude/settings.json">

<violation number="1" location=".claude/settings.json:10">
P2: The new hook filter is too broad: `*vendor*`/`*sources*` match substrings rather than vendor/sources directories, so the hook can still spawn on unrelated edits and miss the intended performance reduction.

(Based on your team's feedback about narrowing hook `if` filters to avoid unnecessary process overhead.) [FEEDBACK_USED]</violation>
</file>
Architecture diagram
sequenceDiagram
    participant Claude as Claude Code Engine
    participant Engine as Hook Evaluator
    participant Script as External Hook Script
    participant FS as File System / Tool

    Note over Claude,FS: Tool Invocation Flow (e.g., Read, Edit, Write)

    Claude->>Engine: Trigger PreToolUse Hook
    
    Note over Engine: NEW: Evaluate "if" field<br/>(Permission Rule Syntax)

    alt Pattern Matches (e.g., Read(*.docx) or Edit(*vendor*))
        Engine->>Script: CHANGED: Spawn process and execute script
        Script-->>Engine: Return exit code/validation
        
        alt Hook Allowed
            Engine-->>Claude: Continue tool execution
            Claude->>FS: Perform File Operation
            FS-->>Claude: Operation Result
        else Hook Denied
            Engine-->>Claude: Block tool execution (Error)
        end

    else Pattern Does NOT Match (e.g., Read(*.ts) or Edit(src/))
        Note over Engine,Script: NEW: Skip process spawn (Performance Gain)
        Engine-->>Claude: Continue tool execution
        Claude->>FS: Perform File Operation
        FS-->>Claude: Operation Result
    end
Loading

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread .claude/settings.json Outdated
@amondnet
Copy link
Copy Markdown
Contributor Author

All review feedback addressed:

  1. Settings hook if removed — permission rule syntax (gitignore-based) doesn't support | alternation, making 4 tools × 2 paths = 8 entries impractical. The script already handles filtering efficiently.
  2. Markitdown hook split into 6 entries — one per extension (Read(*.pptx), Read(*.docx), etc.). The suggested Read(*.pptx|*.docx) syntax is invalid since gitignore patterns have no alternation operator.
  3. Spec fixed — removed *.pdf reference (not handled by check-binary-doc.sh)
  4. Plan updated — T-2 descoped, added syntax limitation discovery

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".please/docs/tracks/active/hooks-if-field-20260328/plan.md">

<violation number="1" location=".please/docs/tracks/active/hooks-if-field-20260328/plan.md:47">
P3: The T-2 descoping update is not propagated through the rest of the plan, leaving contradictory guidance in the same document.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread .please/docs/tracks/active/hooks-if-field-20260328/plan.md
Add permission rule syntax filters to reduce unnecessary hook process
spawns. Markitdown hook now only fires on binary doc extensions
(pptx/docx/xlsx/xls/ppt/doc). Deny-vendor-write hook now only fires
on edits targeting vendor/ or sources/ paths.
Permission rule syntax (gitignore spec) does not support | alternation.
Split markitdown hook into 6 separate entries, one per extension.
Remove if field from deny-vendor-write hook — would require 8 entries
(4 tool types × 2 paths), too verbose for the benefit.
@amondnet amondnet force-pushed the amondnet/fantastic-shrimp branch from 72eaae6 to 5250912 Compare March 28, 2026 14:52
@amondnet amondnet merged commit 9503e5a into main Mar 28, 2026
6 checks passed
@amondnet amondnet deleted the amondnet/fantastic-shrimp branch March 28, 2026 14:55
@pleaeai-bot pleaeai-bot Bot mentioned this pull request Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant