Files
claude-code/src/components/BypassPermissionsModeDialog.tsx
claude-code-best 6dd378bf15 fix: 退出启动对话框时终端残留一行内容
gracefulShutdownSync 启动异步 shutdown 后同步返回,React 立即
重新渲染组件,与 cleanupTerminalModes() 中的 Ink unmount 产生
竞态条件,导致退出后终端残留对话框内容。

修复方案:引入 pendingExitCode state,退出路径先清空画面
(渲染 null),在 useEffect 中延迟到下一个 tick 再调用
gracefulShutdownSync,确保 Ink 在终端清理前已完成空帧刷新。

影响三个启动对话框:TrustDialog、BypassPermissionsModeDialog、
DevChannelsDialog。

Co-Authored-By: glm-5.1 <zai-org@claude-code-best.win>
2026-05-22 22:25:51 +08:00

83 lines
2.6 KiB
TypeScript

import React, { useCallback } from 'react';
import { logEvent } from 'src/services/analytics/index.js';
import { Box, Link, Newline, Text } from '@anthropic/ink';
import { gracefulShutdownSync } from '../utils/gracefulShutdown.js';
import { updateSettingsForSource } from '../utils/settings/settings.js';
import { Select } from './CustomSelect/index.js';
import { Dialog } from '@anthropic/ink';
type Props = {
onAccept(): void;
};
export function BypassPermissionsModeDialog({ onAccept }: Props): React.ReactNode {
const [pendingExitCode, setPendingExitCode] = React.useState<number | null>(null);
// Clear screen before shutdown so residual dialog content doesn't leak
// to the terminal. Deferred to next tick so Ink flushes the null render.
React.useEffect(() => {
if (pendingExitCode !== null) {
const code = pendingExitCode;
const timer = setTimeout(() => gracefulShutdownSync(code));
return () => clearTimeout(timer);
}
}, [pendingExitCode]);
React.useEffect(() => {
logEvent('tengu_bypass_permissions_mode_dialog_shown', {});
}, []);
function onChange(value: 'accept' | 'decline') {
switch (value) {
case 'accept': {
logEvent('tengu_bypass_permissions_mode_dialog_accept', {});
updateSettingsForSource('userSettings', {
skipDangerousModePermissionPrompt: true,
});
onAccept();
break;
}
case 'decline': {
setPendingExitCode(1);
break;
}
}
}
const handleEscape = useCallback(() => {
setPendingExitCode(0);
}, []);
if (pendingExitCode !== null) {
return null;
}
return (
<Dialog title="WARNING: Claude Code running in Bypass Permissions mode" color="error" onCancel={handleEscape}>
<Box flexDirection="column" gap={1}>
<Text>
In Bypass Permissions mode, Claude Code will not ask for your approval before running potentially dangerous
commands.
<Newline />
This mode should only be used in a sandboxed container/VM that has restricted internet access and can easily
be restored if damaged.
</Text>
<Text>
By proceeding, you accept all responsibility for actions taken while running in Bypass Permissions mode.
</Text>
<Link url="https://code.claude.com/docs/en/security" />
</Box>
<Select
options={[
{ label: 'No, exit', value: 'decline' },
{ label: 'Yes, I accept', value: 'accept' },
]}
onChange={value => onChange(value as 'accept' | 'decline')}
/>
</Dialog>
);
}