Skip to content

Commit c9be2bb

Browse files
sylvansysclaude
andauthored
fix(worktree): Fix plugin cache race condition and TypeScript check cwd (#330)
- Move symlink update AFTER plugin installation to prevent hooks from executing against empty cache directories - Normalize TypeScript hook cwd to worktree/repo root using detectWorktree to fix false positives in monorepos where input.cwd is a subdirectory - Enable github-orchestration plugin in settings Fixes #329 Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c08a4d2 commit c9be2bb

4 files changed

Lines changed: 37 additions & 18 deletions

File tree

.claude/settings.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,10 @@
9191
"enabledPlugins": {
9292
"plugin-dev@claude-code-plugins": true,
9393
"feature-dev@claude-code-plugins": true,
94-
"github-orchestration@constellos-local": true,
9594
"nextjs-supabase-ai-sdk-dev@constellos": true,
96-
"nextjs-supabase-ai-sdk-dev@constellos-local": true,
97-
"project-context@constellos-local": true
95+
"github-orchestration@constellos": true
9896
},
9997
"extraKnownMarketplaces": {
100-
"constellos-local": {
101-
"source": {
102-
"source": "directory",
103-
"path": "${CLAUDE_PROJECT_DIR}/.claude-plugin"
104-
}
105-
},
10698
"claude-code-plugins": {
10799
"source": {
108100
"source": "github",

claude-worktree.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,8 @@ _cw_main() {
766766
# Get worktree-specific cache directory (per-worktree isolation)
767767
local wt_cache_dir=$(_cw_get_worktree_cache_dir "$worktree_dir")
768768

769-
# Update symlink to point to this worktree's cache
770-
# This ensures each worktree has isolated cache without breaking others
771-
_cw_update_cache_symlink "$wt_cache_dir"
769+
# NOTE: Symlink update is deferred until AFTER plugins are installed
770+
# This prevents race condition where hooks execute from empty cache
772771

773772
local current_path=$(claude plugin marketplace list 2>/dev/null | grep -A1 "constellos-local" | grep "Directory" | sed 's/.*(\(.*\))/\1/')
774773

@@ -876,6 +875,12 @@ _cw_main() {
876875
fi
877876
done <<< "$plugins"
878877
fi
878+
879+
# Update symlink AFTER plugins are installed to prevent race condition
880+
# where SessionStart hooks execute from empty cache directory
881+
if [[ -n "$wt_cache_dir" ]]; then
882+
_cw_update_cache_symlink "$wt_cache_dir"
883+
fi
879884
fi
880885
set -e
881886

plugins/nextjs-supabase-ai-sdk-dev/hooks/run-session-typechecks.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import type { StopInput, StopHookOutput } from '../shared/types/types.js';
1111
import { runHook } from '../shared/hooks/utils/io.js';
1212
import { findConfigFile } from '../shared/hooks/utils/config-resolver.js';
13+
import { detectWorktree } from '../shared/hooks/utils/worktree.js';
1314
import { exec } from 'child_process';
1415
import { promisify } from 'util';
1516

@@ -49,12 +50,22 @@ async function handler(input: StopInput): Promise<StopHookOutput> {
4950
console.log('[run-session-typechecks] Session ID:', input.session_id);
5051
}
5152

52-
// Find tsconfig.json
53-
const tsconfigDir = await findConfigFile(input.cwd, 'tsconfig.json');
53+
// Normalize cwd to worktree/repo root for consistent config resolution
54+
// This fixes false positives in monorepos where input.cwd might be a subdirectory
55+
const worktreeInfo = detectWorktree(input.cwd);
56+
const searchRoot = worktreeInfo.worktreePath;
57+
58+
if (DEBUG) {
59+
console.log('[run-session-typechecks] Search root:', searchRoot);
60+
console.log('[run-session-typechecks] Is worktree:', worktreeInfo.isWorktree);
61+
}
62+
63+
// Find tsconfig.json starting from repo/worktree root
64+
const tsconfigDir = await findConfigFile(searchRoot, 'tsconfig.json');
5465

5566
if (!tsconfigDir) {
5667
// No tsconfig.json found - skip with warning visible in systemMessage
57-
const warning = `⚠️ TypeScript check skipped: tsconfig.json not found (searched from ${input.cwd})`;
68+
const warning = `⚠️ TypeScript check skipped: tsconfig.json not found (searched from ${searchRoot})`;
5869
if (DEBUG) {
5970
console.warn(`[run-session-typechecks] ${warning}`);
6071
}

plugins/nextjs-supabase-ai-sdk-dev/hooks/run-task-typechecks.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { SubagentStopInput, SubagentStopHookOutput } from '../shared/types/
1111
import { runHook } from '../shared/hooks/utils/io.js';
1212
import { getAgentEdits } from '../shared/hooks/utils/subagent-state.js';
1313
import { findConfigFile } from '../shared/hooks/utils/config-resolver.js';
14+
import { detectWorktree } from '../shared/hooks/utils/worktree.js';
1415
import { exec } from 'child_process';
1516
import { promisify } from 'util';
1617

@@ -92,12 +93,22 @@ async function handler(input: SubagentStopInput): Promise<SubagentStopHookOutput
9293
};
9394
}
9495

95-
// Find tsconfig.json
96-
const tsconfigDir = await findConfigFile(input.cwd, 'tsconfig.json');
96+
// Normalize cwd to worktree/repo root for consistent config resolution
97+
// This fixes false positives in monorepos where input.cwd might be a subdirectory
98+
const worktreeInfo = detectWorktree(input.cwd);
99+
const searchRoot = worktreeInfo.worktreePath;
100+
101+
if (DEBUG) {
102+
console.log('[run-task-typechecks] Search root:', searchRoot);
103+
console.log('[run-task-typechecks] Is worktree:', worktreeInfo.isWorktree);
104+
}
105+
106+
// Find tsconfig.json starting from repo/worktree root
107+
const tsconfigDir = await findConfigFile(searchRoot, 'tsconfig.json');
97108

98109
if (!tsconfigDir) {
99110
// No tsconfig.json found - skip with warning visible in systemMessage
100-
const warning = `⚠️ TypeScript check skipped: tsconfig.json not found (searched from ${input.cwd})`;
111+
const warning = `⚠️ TypeScript check skipped: tsconfig.json not found (searched from ${searchRoot})`;
101112
if (DEBUG) {
102113
console.warn(`[run-task-typechecks] ${warning}`);
103114
}

0 commit comments

Comments
 (0)