Skip to content

コードのリポジトリでclaude.aiのコネクタの読み込みを切る道具を足す - #8

Merged
BoxPistols merged 2 commits into
mainfrom
feat/connector-scope
Sep 27, 2026
Merged

BoxPistols merged 2 commits into
mainfrom
feat/connector-scope

Conversation

@BoxPistols

Copy link
Copy Markdown
Owner

Closes #3

tools/connector-scope.pyを足しました。コードのリポジトリ(gitのルートにpackage.jsonやpyproject.tomlなどがある)の.claude/settings.local.jsonにdisableClaudeAiConnectors: trueを書きます。引数なしでは対象を表示するだけで、--applyを付けたときだけ書き込みます。

既にdisableClaudeAiConnectorsをtrueかfalseに決めているリポジトリは触りません。既存の.claude/settings.local.jsonのキーは残し、ファイルは.git/info/excludeに足してcommitされないようにします。

確かめたこと

  • テストを2件足した(表示だけでは書き込まない、コードのリポジトリだけ切り既存の判断と設定を残す)。書き込む値を壊すとテストが落ちることを確かめた
  • 手元の約70のリポジトリで、表示だけのモードで判定が期待どおりになることを確かめた(書き込みはしていない)

プラグインの中身は変えていないので、plugin.jsonの版は上げていません。

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 969ee4b4-f48e-4049-bed2-96bc4d32272a

📥 Commits

Reviewing files that changed from the base of the PR and between 1f5bb6f and 4cc1a58.

📒 Files selected for processing (3)
  • README.md
  • tests/test_env_kit.py
  • tools/connector-scope.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

This PR adds a useful tool (connector-scope.py) to disable Claude.ai connectors in code repositories, which can reduce token usage by ~30%. The implementation includes comprehensive tests and documentation.

Critical Issues Found (Must Fix)

Resource Leaks (3 instances): File handles opened without context managers in both test and production code. These must be fixed to prevent resource exhaustion and file locking issues, especially on Windows.

All critical issues have actionable code suggestions attached. Once the resource leaks are fixed, this should be ready to merge.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Comment thread tools/connector-scope.py Outdated
return
path = os.path.join(common if os.path.isabs(common) else os.path.join(repo, common), 'info', 'exclude')
line = '.claude/settings.local.json'
cur = open(path, encoding='utf-8').read().splitlines() if os.path.exists(path) else []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Resource Leak: File opened but never closed. This can cause resource exhaustion when processing many repositories or prevent file operations on Windows.

Suggested change
cur = open(path, encoding='utf-8').read().splitlines() if os.path.exists(path) else []
with open(path, encoding='utf-8') as f:
cur = f.read().splitlines() if os.path.exists(path) else []

Comment thread tests/test_env_kit.py Outdated
def test_表示だけでは書き込まない(self):
out = self.run_scope()
self.assertIn('切る対象は1件', out)
local = json.load(open(os.path.join(self.root, 'app', '.claude', 'settings.local.json'), encoding='utf-8'))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Resource Leak: File handle not closed after opening. This can cause resource exhaustion in tests or prevent file deletion on Windows.

Suggested change
local = json.load(open(os.path.join(self.root, 'app', '.claude', 'settings.local.json'), encoding='utf-8'))
with open(os.path.join(self.root, 'app', '.claude', 'settings.local.json'), encoding='utf-8') as f:
local = json.load(f)

Comment thread tests/test_env_kit.py Outdated

def test_コードのリポジトリだけ切り既存の判断と設定を残す(self):
self.run_scope('--apply')
local = json.load(open(os.path.join(self.root, 'app', '.claude', 'settings.local.json'), encoding='utf-8'))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 Resource Leak: File handle not closed after opening. This can cause resource exhaustion in tests or prevent file deletion on Windows.

Suggested change
local = json.load(open(os.path.join(self.root, 'app', '.claude', 'settings.local.json'), encoding='utf-8'))
with open(os.path.join(self.root, 'app', '.claude', 'settings.local.json'), encoding='utf-8') as f:
local = json.load(f)

@BoxPistols

Copy link
Copy Markdown
Owner Author

ファイルを閉じていない3件を直しました。connector-scope.pyの1件目は、提案のままだと存在を確かめる前に開いてしまうので、存在を確かめてからwithで開く形にしています。テストは読み込みを小さな関数にまとめました。

@BoxPistols
BoxPistols merged commit b37e0d0 into main Sep 27, 2026
4 checks passed
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