fix: prevent REPL freeze and silent hangs for 3P providers#456
fix: prevent REPL freeze and silent hangs for 3P providers#456deadlydiamond wants to merge 1 commit intoGitlawb:mainfrom
Conversation
… OpenAI, Gemini) Third-party providers with smaller context windows (e.g. DeepSeek's 64K) cannot handle the full Claude Code system prompt (~50K+ tokens), 50 tool definitions (~104KB), and plugin hook context injection (~14K+ tokens). This causes the REPL to silently freeze with no error message. Changes: - Add trimmed system prompt for 3P providers (~500 tokens vs ~50K) - Filter tools to 15 essential ones in OpenAI shim (Bash, Read, Write, Edit, Grep, Glob, Agent, Skill, WebSearch, WebFetch, etc.) - Skip SessionStart/UserPromptSubmit hooks for 3P providers - Skip plugin management (useManagePlugins) for 3P providers - Skip performStartupChecks for 3P providers - Add 10s timeout on command loading as safety net - Export is3PProvider() utility for consistent detection Root cause: Claude Code was designed for Claude's 200K context window. The system prompt, tool schemas, and plugin hooks combined exceed the context limits of most third-party models, causing them to silently drop the connection with no error. Fixes Gitlawb#435, relates to Gitlawb#337, Gitlawb#433 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
gnanam1990
left a comment
There was a problem hiding this comment.
Thanks for digging into the freeze. The root cause analysis in the PR description is useful, but the current implementation appears to fix it by disabling broader parts of the product than intended. I see a few blocking issues:
-
src/utils/hooks.ts:1978andsrc/utils/hooks.ts:3016
This disables all hooks for OpenAI/Gemini, not just the startup/prompt hooks described in the PR.executeHooks/executeHooksOutsideREPLare the generic dispatchers, so this also suppresses unrelated hook events and user automation. That is a much larger behavior change than "skip SessionStart and UserPromptSubmit to avoid oversized requests." -
src/services/api/openaiShim.ts:963andsrc/services/api/openaiShim.ts:972
The tool filtering runs on the shared OpenAI shim path, so it also affects GitHub Models requests, not just the "3P providers" called out in the PR. The description frames this as a context-window workaround for smaller providers, but the implementation removes tools for other OpenAI-compatible paths too. That needs to be scoped more carefully or justified/tested explicitly. -
src/main.tsx:2023
The new 10sgetCommands()timeout is global startup behavior, not limited to the affected REPL/provider path. On slower environments this can now silently continue with an empty command set for unaffected users as well. That feels too broad for a fix targeted at 3P interactive freezes. -
src/screens/REPL.tsx:781andsrc/screens/REPL.tsx:795
The new provider checks use exact string equality (=== '1') instead of the repo's normal truthy parsing (isEnvTruthy). If a user hasCLAUDE_CODE_USE_OPENAI=trueor another accepted truthy value, this path won't activate and the freeze remains.\n\nI think the overall direction is reasonable, but I'd want this narrowed so it:\n- only skips the specific hook/plugin/startup work actually implicated in the freeze,\n- only trims tools for the providers that need it,\n- avoids introducing a global startup timeout regression,\n- uses consistent provider detection across the codebase.
Summary
Fixes the REPL freeze that occurs when using third-party providers (DeepSeek, OpenAI-compat, Gemini, Ollama, Groq) in interactive mode. The CLI silently hangs with no error message after the user submits their first message.
Root cause: Claude Code's system prompt (~50K+ tokens), 50 tool definitions (~104KB request body), and plugin hook context injection (~14K+ tokens from claude-mem alone) exceed the context limits of most 3P models (e.g. DeepSeek's 64K token limit). The provider silently drops the connection instead of returning an error.
Changes
prompts.ts): DetectsCLAUDE_CODE_USE_OPENAI/CLAUDE_CODE_USE_GEMINIand sends a ~500 token prompt with essential coding agent instructions instead of the full ~50K promptopenaiShim.ts): Limits tools to 15 essential ones (Bash, Read, Write, Edit, Grep, Glob, Agent, Skill, WebSearch, WebFetch, etc.) reducing request body from ~104KBhooks.ts,sessionStart.ts): Skips SessionStart and UserPromptSubmit hooks for 3P providers — these inject thousands of tokens of context that push requests past provider limitsREPL.tsx): DisablesuseManagePluginsandperformStartupChecksfor 3P providers — the plugin loading pipeline triggers heavy I/O and AppState churn that freezes the React REPLmain.tsx): Adds 10-second timeout ongetCommands()as a safety netenvUtils.ts): Exportsis3PProvider()for consistent 3P detectionWhat works after this fix
All core coding agent tools: Bash, Read, Write, Edit, Grep, Glob, Agent, WebSearch, WebFetch, TaskCreate, TodoWrite, AskUserQuestion
What's disabled for 3P providers
Plugin skills (/brainstorm, /plan, etc.), plugin hooks, plugin MCP servers, claude-mem memory, and the full Claude-style system prompt. These require Claude's 200K context window and are architecturally incompatible with smaller-context models.
Future architectural work needed
The proper long-term fix would require:
/skillinvocation, not startup)Test plan
bun run smokepassesbun run buildsucceeds--barestill works-pmode works with all providersFixes #435, relates to #337, #433
🤖 Generated with Claude Code