|
26 | 26 | /** |
27 | 27 | * Persists Claude environment variables into CLAUDE_ENV_FILE for Bash tool invocations. |
28 | 28 | * <p> |
29 | | - * Appends {@code CLAUDE_PROJECT_DIR}, {@code CLAUDE_PLUGIN_ROOT}, and |
30 | | - * {@code CLAUDE_SESSION_ID} to the env file so they are available in all subsequent |
31 | | - * Bash tool calls. |
| 29 | + * Appends {@code CLAUDE_PROJECT_DIR} and {@code CLAUDE_PLUGIN_ROOT} to the env file so they are available in all |
| 30 | + * subsequent Bash tool calls. {@code CLAUDE_SESSION_ID} is injected natively by Claude Code (v2.1.77+) and must |
| 31 | + * not be written here — writing it would corrupt sibling session env files when multiple sessions run concurrently. |
32 | 32 | * <p> |
33 | 33 | * Only writes for new sessions (source="startup"). On resumed (source="resume") or |
34 | 34 | * compacted (source="compact") sessions, the env file already has the correct content |
@@ -95,10 +95,8 @@ public Result handle(HookInput input) |
95 | 95 | String pluginRoot = scope.getClaudePluginRoot().toString(); |
96 | 96 | validateEnvValue(projectPath, "CLAUDE_PROJECT_DIR"); |
97 | 97 | validateEnvValue(pluginRoot, "CLAUDE_PLUGIN_ROOT"); |
98 | | - validateEnvValue(sessionId, "CLAUDE_SESSION_ID"); |
99 | 98 | String content = "export CLAUDE_PROJECT_DIR=\"" + projectPath + "\"\n" + |
100 | | - "export CLAUDE_PLUGIN_ROOT=\"" + pluginRoot + "\"\n" + |
101 | | - "export CLAUDE_SESSION_ID=\"" + sessionId + "\"\n"; |
| 99 | + "export CLAUDE_PLUGIN_ROOT=\"" + pluginRoot + "\"\n"; |
102 | 100 |
|
103 | 101 | try |
104 | 102 | { |
@@ -214,7 +212,7 @@ private String writeToResumedSessionDir(Path sessionEnvBase, Path envPath, Strin |
214 | 212 | * <p> |
215 | 213 | * After {@code /clear}, Claude Code's session env loader may cache files from an old session directory and not |
216 | 214 | * re-read from the new session directory. Writing to all sibling directories ensures that whichever directory the |
217 | | - * cache reads from, it gets the current {@code CLAUDE_SESSION_ID}. |
| 215 | + * cache reads from, it gets the current {@code CLAUDE_PROJECT_DIR} and {@code CLAUDE_PLUGIN_ROOT}. |
218 | 216 | * |
219 | 217 | * @param sessionEnvBase the parent directory containing all session-env subdirectories |
220 | 218 | * @param envPath the CLAUDE_ENV_FILE path (used to identify the already-written directory) |
|
0 commit comments