Skip to content

No way to use tool arguments in hooks - when.toolArgs is exact only and templates have no args #12

Closed

Description

@bendtherules

Hi, thanks for the plugin.

I wanted a hook that only runs for certain edit files, but hit two gaps:

  • when.toolArgs only does exact string matches, so I can't filter by pattern like *.ts.
  • run and inject templates don't have tool arguments at all. They only have id, agent, tool, cmd, stdout, stderr, exitCode, so I can't branch on the arguments inside the command either.

This is generic, not just edit. The same is true for grep with pattern, bash with command, etc. If the hook can't see the tool's arguments, there's no way to make it conditional on them.

Would it be possible to expose arguments in templates as args.<key> (for example args.filePath, args.pattern) with empty string if missing? That would let me do:

run: "sh -c 'case \"{args.filePath}\" in *.ts|*.js) echo \"[JS Edit Reminder] ...\";; esac'"

And for filtering, allowing a simple glob or regex in when.toolArgs would also help.

Happy to raise a PR if you agree with the approach - just let me know what shape you prefer, thanks!

Activity

  1. changed the title [-]No way to use tool arguments in hooks — when.toolArgs is exact only and templates have no args[/-] [+]No way to use tool arguments in hooks - when.toolArgs is exact only and templates have no args[/+] on Sep 2, 2026
  2. shanebishop1 commented on Sep 8, 2026

    @shanebishop1
    Owner

    Hi @bendtherules, thanks for bringing this up! I agree that tool arguments should be available more generally.

    0.70 has been released with the adjustments merged in #13, which solves this with a broader implementation such that:

    • Existing string and string-array values still use exact matching.
    • { glob: "..." } and { regex: "..." } can now be used for any tool argument, including arguments from custom tools.
    • Direct argument values are available in inject and toast templates through placeholders such as {args.filePath}.
    • Commands can access the complete argument object as JSON through the file referenced by OPENCODE_HOOK_ARGS_FILE.

    For example, your original use case can now be configured directly:

    when:
      phase: before
      tool: edit
      toolArgs:
        filePath:
          glob: "**/*.{ts,js}"
    

    Let me know if this works well for your use case. Thanks again for the suggestion!

  3. bendtherules commented on Sep 8, 2026

    @bendtherules
    Author

    This looks great. Thanks for adding it 👍

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions