perf(hooks): add .planning/ sentinel check before config read in context monitor (#1930)

The context monitor hook read and parsed config.json on every
PostToolUse event. For non-GSD projects (no .planning/ directory),
this was unnecessary I/O. Add a quick existsSync check for the
.planning/ directory before attempting to read config.json.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tibsfox
2026-04-07 14:25:21 -07:00
committed by GitHub
parent 602b34afb7
commit d12d31f8de

View File

@@ -52,17 +52,19 @@ process.stdin.on('end', () => {
process.exit(0);
}
// Check if context warnings are disabled via config
// Check if context warnings are disabled via config.
// Quick sentinel check: skip config read entirely for non-GSD projects (#P2.5).
const cwd = data.cwd || process.cwd();
const configPath = path.join(cwd, '.planning', 'config.json');
if (fs.existsSync(configPath)) {
const planningDir = path.join(cwd, '.planning');
if (fs.existsSync(planningDir)) {
try {
const configPath = path.join(planningDir, 'config.json');
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
if (config.hooks?.context_warnings === false) {
process.exit(0);
}
} catch (e) {
// Ignore config parse errors
// Ignore config read/parse errors (config may not exist in .planning/)
}
}