Skip to content

hookDevOps and cloudgithub-actions

Protect CI Workflows

A Claude Code hook that pauses for your approval before the agent edits GitHub Actions workflows, GitLab CI, Jenkinsfile or other pipeline files.

npx workspacetemplates add protect-ci-workflows --tool claude-code

Writes 1 file to .claude/

.claude/settings.jsonmerge into your file16 lines · 955 BFile
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "node -e \"let d='';process.stdin.on('data',x=>d+=x).on('end',()=>{let j={};try{j=JSON.parse(d)}catch(e){return}const i=j.tool_input||{};const f=String(i.file_path||'').split(String.fromCharCode(92)).join('/');const n=f.split('/').pop();const hit=/^(.*[/])?[.]github[/]workflows[/][^/]+[.]ya?ml/.test(f)||/^(.*[/])?[.]github[/]actions[/]/.test(f)||['.gitlab-ci.yml','azure-pipelines.yml','Jenkinsfile','bitbucket-pipelines.yml'].includes(n)||/[.]circleci[/]config[.]yml/.test(f);if(hit){console.log(JSON.stringify({hookSpecificOutput:{hookEventName:'PreToolUse',permissionDecision:'ask',permissionDecisionReason:'This file controls CI and can touch secrets and deployments. Review the change before it is written.'}}))}})\"",
            "timeout": 10
          }
        ]
      }
    ]
  }
}

What it does

Pipeline files run with your secrets and deploy rights, so a small edit can have a large reach. This PreToolUse hook does not block them. It switches the permission prompt on for those files, even if you allowed edits in general.

It matches workflow and action files under .github, plus GitLab CI, Azure Pipelines, Bitbucket Pipelines, CircleCI and Jenkinsfile. You see the proposed change and approve or reject it.

Example

you › Speed up CI by caching node_modules in the build workflow.

agent › Claude Code stops and shows the edit to .github/workflows/build.yml. You approve it, or reject it and ask for a change.

Questions

Is the edit refused outright?
No. The hook asks for a decision, so you can still approve a good change and nothing is lost.
Does it work when I run in accept-edits mode?
Yes. The ask decision overrides auto-accept for the matched files, while other files keep their normal mode.
  • Block Global Installs

    HookDevOps and cloud

    Free
  • Block npm Publish

    Hooknode

    Free
  • Check Node Version

    Hooknode

    Free
  • Protect Lockfiles

    HookDevOps and cloud

    Free