Repository navigation
コードのリポジトリでclaude.aiのコネクタの読み込みを切る道具を足す - #8
Conversation
|
Warning Review limit reachedNext included review available in 43 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
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. Comment |
There was a problem hiding this comment.
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.
| 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 [] |
There was a problem hiding this comment.
🛑 Resource Leak: File opened but never closed. This can cause resource exhaustion when processing many repositories or prevent file operations on Windows.
| 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 [] |
| 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')) |
There was a problem hiding this comment.
🛑 Resource Leak: File handle not closed after opening. This can cause resource exhaustion in tests or prevent file deletion on Windows.
| 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) |
|
|
||
| def test_コードのリポジトリだけ切り既存の判断と設定を残す(self): | ||
| self.run_scope('--apply') | ||
| local = json.load(open(os.path.join(self.root, 'app', '.claude', 'settings.local.json'), encoding='utf-8')) |
There was a problem hiding this comment.
🛑 Resource Leak: File handle not closed after opening. This can cause resource exhaustion in tests or prevent file deletion on Windows.
| 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) |
|
ファイルを閉じていない3件を直しました。connector-scope.pyの1件目は、提案のままだと存在を確かめる前に開いてしまうので、存在を確かめてからwithで開く形にしています。テストは読み込みを小さな関数にまとめました。 |
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されないようにします。
確かめたこと
プラグインの中身は変えていないので、plugin.jsonの版は上げていません。