Translate

2025年7月18日金曜日

GitHub Actions で実行させているClaude Codeにテスト実行などをさせるためのBash権限を追加する方法

先の記事でも書きましたが、Claude Code をIssueやPull RequestのリアクションをClaude Codeにやらせる場合、一旦ローカルPCにClaude Codeをインストールして、git cloneしたGitHubリポジトリ内でclaudeコマンドで実行した後、/install-github-app したあとgit pushすることで設定できます。

そのとき私の環境では .github/workflow/ 以下に claude.yml claude-code-review.yml が作成されました。

これらの Claude CodeはGitHub側のホストで実行されますが、Claude Codeからいろんなコマンドを実行させるには権限を付与する必要があります。

その権限付与は前の記事でも書いた allowed_tools に "Bash(<実行許可するコマンド>)" を追加します。


たとえば、Node.js/JavaScript/TypeScriptプロジェクトで単体テストさせるには:


allowed_tools: "View, GlobTool, GrepTool, BatchTool, Bash(npm install), Bash(npm test), Bash(npm run test:*), Bash(npm run build), Bash(npm run lint)"


Pythonの単体テストの場合は:

allowed_tools: "View, GlobTool, GrepTool, BatchTool, Bash(pip install *), Bash(pytest), Bash(pytest *), Bash(python -m pytest), Bash(tox)"


Rustの単体テストの場合は:

allowed_tools: "View, GlobTool, GrepTool, BatchTool, Bash(cargo test), Bash(cargo build), Bash(cargo clippy)"


おそらくめんどくさくなって "Bash" としてしまうと思いますが、rm -rf / とか curlによる外部通信、機密情報の漏洩など、意図しない危険なコマンドが実行される可能性があるので、推奨しません。

エラーが出たらそのたびに権限を追加するつもりで運用するのが良いと思います。


2025年7月7日月曜日

GitHub Actions で実行させているClaude Code に複数のMCPツールを追加する

 Claude Code をIssueやPull RequestのリアクションをClaude Codeにやらせる場合、
一旦ローカルPCにClaude Codeをインストールして、git cloneしたGitHubリポジトリ内でclaudeコマンドで実行した後、/install-github-app したあとgit pushすることで設定できます。

が、上記方法ではMCPツールは(ローカルPC上のClaude CodeにMCPツールを設定していても)登録されません。

MCPツールを増やすには先の作業で追加した .github/workflows/claude.yaml.github/workflows/claude-code-review.yaml に GitHub Claude Code Actions に書かれている通り設定すればいいのですが、allowed_toolsに2つのMCPツールの名前をstringで記述する必要があります。

stringなのでシングルクォートをつかって以下のように設定すれば動作します(beta版で動作確認):

        :
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

          mcp_config: |
            {
              "mcpServers": {
                "sequential-thinking": {
                  "command": "npx",
                  "args": [
                    "-y",
                    "@modelcontextprotocol/server-sequential-thinking"
                  ]
                },
                "perplexity-ask": {
                  "command": "npx",
                  "args": [
                    "-y",
                    "server-perplexity-ask"
                  ],
                  "env": {
                    "PERPLEXITY_API_KEY": "${{ secrets.PERPLEXITY_API_KEY }}"
                  }
                }
              }
            }
          allowed_tools:
"View, GlobTool, GrepTool, BatchTool, mcp__sequential-thinking__sequentialthinking, mcp__perplexity-ask__perplexity_ask"

          :





ご参考まで。

#あと、インテントにも注意。allowed_toolsmcp_configと同じインテントです 

 p.s.

ほかのパーミッション、例えば Bash(git: *) を追加したい場合は、以下のように記述します:

 

 allowed_tools: "Bash(git: *), View, GlobTool, GrepTool, BatchTool, mcp__sequential-thinking__sequentialthinking, mcp__perplexity-ask__perplexity_ask" 

 

GitHub Actions で実行させているClaude Codeにテスト実行などをさせるためのBash権限を追加する方法

先の記事 でも書きましたが、Claude Code をIssueやPull RequestのリアクションをClaude Codeにやらせる場合、一旦ローカルPCにClaude Codeをインストールして、 git clone したGitHubリポジトリ内でclaudeコマンドで実...