-
Notifications
You must be signed in to change notification settings - Fork 0
Claude Code - Skip run_tool HITL elicitation in bypassPermissions mode #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eshwar-sundar-glean
merged 4 commits into
main
from
skip-elicitation-in-bypass-permissions
Jul 1, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d8bb762
Skip run_tool HITL elicitation in bypassPermissions mode
eshwar-sundar-glean b0d87ea
Clear stale bypass marker on resume via per-call hook overwrite
eshwar-sundar-glean cf28641
Align marker path fallback with the hook (~/.glean, not tmpdir)
eshwar-sundar-glean 42666f1
Key marker path off CLAUDE_PLUGIN_DATA only, mirroring the hook exactly
eshwar-sundar-glean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,11 @@ import type { Server } from "@modelcontextprotocol/sdk/server/index.js"; | |
| import type { CallToolResult, Tool } from "@modelcontextprotocol/sdk/types.js"; | ||
| import { EmptyResultSchema } from "@modelcontextprotocol/sdk/types.js"; | ||
| import fs from "node:fs/promises"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
| import { callRemoteTool } from "../remote-client.js"; | ||
| import { buildCompactArgs, writeApprovalArgsFile } from "./approval-args.js"; | ||
| import { resolveSessionId } from "../session-id.js"; | ||
|
|
||
| const DEFAULT_FILE_ARG_MAX_BYTES = 1 * 1024 * 1024; | ||
|
|
||
|
|
@@ -240,6 +242,45 @@ function primeElicitationCancellation(mcpServer: Server): void { | |
| }); | ||
| } | ||
|
|
||
| // Path to the per-session permission-mode marker the PreToolUse hook writes | ||
| // immediately before each run_tool call (see hooks/auto-approve-run-tool.mjs). | ||
| // This resolution MUST match the hook's exactly. The hook cannot see the | ||
| // server-only PLUGIN_DATA_DIR that start.sh derives, so both sides key off | ||
| // CLAUDE_PLUGIN_DATA (falling back to ~/.glean) — the one anchor available to | ||
| // both processes. Under start.sh, PLUGIN_DATA_DIR resolves to this same path. | ||
| function permissionModeMarkerPath(): string { | ||
| const base = | ||
| process.env.CLAUDE_PLUGIN_DATA || path.join(os.homedir(), ".glean"); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now this is clean because this is only applicable to claude and cursor is not regressed because of this |
||
| const sessionId = resolveSessionId() | ||
| .replace(/[^a-zA-Z0-9_-]/g, "-") | ||
| .slice(0, 64); | ||
| return path.join(base, "glean-hitl-mode", `${sessionId}.json`); | ||
| } | ||
|
|
||
| // Claude Code's live permission mode for THIS session, as captured by the hook | ||
| // on the current call. Returns null when the marker is missing, unreadable, or | ||
| // malformed — the caller treats null as "unknown" and keeps the approval gate, | ||
| // so any failure fails toward prompting, never toward a silent bypass. | ||
| // | ||
| // Resume safety: the PreToolUse hook rewrites this marker with the CURRENT mode | ||
| // on every run_tool call (see hooks/auto-approve-run-tool.mjs), and PreToolUse | ||
| // always runs before the tool executes, so the value read here is the one | ||
| // written for this exact call. A session first launched with | ||
| // --dangerously-skip-permissions and later resumed WITHOUT it (same session id) | ||
| // therefore has its stale bypass marker overwritten with the resumed mode on | ||
| // the resumed session's first run_tool call, re-engaging the gate. | ||
| async function currentPermissionMode(): Promise<string | null> { | ||
| try { | ||
| const raw = await fs.readFile(permissionModeMarkerPath(), "utf-8"); | ||
| const parsed = JSON.parse(raw) as { permission_mode?: unknown }; | ||
| return typeof parsed.permission_mode === "string" | ||
| ? parsed.permission_mode | ||
| : null; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| export async function handleRunTool( | ||
| remoteClient: Client, | ||
| mcpServer: Server, | ||
|
|
@@ -288,8 +329,20 @@ export async function handleRunTool( | |
| } | ||
|
|
||
| const hitlEnabled = process.env.ENABLE_HITL === "true"; | ||
| if (hitlEnabled && mcpServer.getClientCapabilities()?.elicitation) { | ||
| if (toolMeta?.requires_approval) { | ||
| if ( | ||
| hitlEnabled && | ||
| toolMeta?.requires_approval && | ||
| mcpServer.getClientCapabilities()?.elicitation | ||
| ) { | ||
| // In bypassPermissions mode (`claude --dangerously-skip-permissions`) the | ||
| // user has opted out of every approval prompt for the session, so our own | ||
| // elicitation gate is just a redundant popup — skip it and execute | ||
| // directly. The mode comes from the PreToolUse hook, which writes it keyed | ||
| // by session id immediately before this call, so it reflects the current | ||
| // call and never leaks across sessions. Any other or unknown mode keeps the | ||
| // gate. Only bypassPermissions is skipped (deliberately narrow). | ||
| const bypass = (await currentPermissionMode()) === "bypassPermissions"; | ||
| if (!bypass) { | ||
| const message = await buildApprovalMessage( | ||
| mcpServer, | ||
| toolName, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.