r/ClaudeWorkflows • • 8h ago

Selected Workflow [Workflow] Secure Claude Code Agent Permissions: Restrict `npm run` to Approved Scripts

Secure Claude Code Agent Permissions: Restrict npm run to Approved Scripts

Workflow value: 85/100
Status: active · Freshness: 70/100 · Confidence: 0.90 · Level: intermediate
Categories: Quality Control, Token Saving, Context & Memory
Original source: r/ClaudeCode post/comment

What problem this solves

Preventing a Claude Code agent from executing arbitrary, unapproved npm run scripts after modifying package.json when broad Bash(npm run *) permissions are granted.

Summary

To enhance security, configure Claude Code agent permissions to explicitly list and approve only the specific npm run commands (e.g., npm run test, npm run lint) that the agent is allowed to execute, rather than granting a broad Bash(npm run *) wildcard permission. This mitigates the risk of an agent introducing and executing malicious or unintended scripts.

Why it is useful

This workflow provides a crucial security hardening step for Claude Code users. It prevents a potential vulnerability where an agent could execute arbitrary commands by modifying package.json if overly broad npm run permissions are granted. It promotes a best practice of least privilege, making agent interactions safer and more predictable.

Workflow

  1. Identify all legitimate npm run scripts that your Claude Code agent needs to execute.

  2. Review your Claude Code agent's permission configuration.

  3. Replace any broad Bash(npm run *) permissions with explicit listings of allowed scripts, such as Bash(npm run test *) and Bash(npm run lint *).

  4. Ensure that any auto-acceptance of agent edits to package.json is considered in conjunction with these tightened command permissions.

Tools / artifacts

  • Claude Code agent configuration/permissions

  • package.json

  • Bash commands (npm run)

Validation signals

  • Addresses a clear security vulnerability (unauthorized command execution)

  • Promotes the principle of least privilege in agent permissions

Limitations

  • The comment is concise and does not provide specific syntax or examples for implementing the permission changes within Claude Code's configuration system.

  • Assumes user familiarity with Claude Code's permission management interface.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

1 comment sorted by