Skip to content

fix(llm): pass long Claude Code system prompts through a file - #2456

Merged
pancacake merged 1 commit into
HKUDS:devfrom
Mahdi-Hasan:fix/2333-claude-code-long-system-prompt
Nov 5, 2026
Merged

pancacake merged 1 commit into
HKUDS:devfrom
Mahdi-Hasan:fix/2333-claude-code-long-system-prompt

Conversation

@Mahdi-Hasan

Copy link
Copy Markdown
Contributor

Description

On Windows, the Claude Code provider fails for any capability with a system prompt over about 32K characters. Mastery Path (about 45K) is the first one users hit.

Cause:

  • _build_options passed system_prompt as a string. The SDK puts that on the command line as --system-prompt <text>.
  • Windows CreateProcess caps the whole command line at 32,767 characters. The spawn fails with WinError 206.
  • Python raises that as FileNotFoundError, and the SDK reports it as "Claude Code not found at: ...", which points at the wrong problem.

Changes:

  • Prompts over 8,000 characters are written to system-prompt-<sha256[:16]>.md in the provider's existing temp workspace. They are passed as the SDK's {"type": "file", "path": ...} option (SystemPromptFile, present in the pinned claude-agent-sdk>=0.2.174).
  • The write goes through a unique staging name and replace, so concurrent sessions with the same prompt never read a partial file.
  • Prompts at or under the limit stay inline, so short-prompt behavior is unchanged.

The approach follows the fix proposed in the issue by the reporter.

Related Issues

Module(s) Affected

  • Other: services/llm
  • tests

Checklist

  • This PR targets dev (not main).
  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run the pre-commit hooks. All pass except deeptutor-repo-hygiene, which calls python3 and fails only on Windows. python scripts/check_repo_hygiene.py passes.
  • I have added relevant tests for my changes.
  • I have updated the documentation (if necessary). Not needed: no user docs cover this path.
  • My changes do not introduce any new security vulnerabilities.

Additional Notes

  • Two new tests in tests/services/llm/test_claude_code_provider.py: a long prompt becomes a file option with the full text and no leftover .tmp, and a prompt exactly at the limit stays inline.
  • test_claude_code_provider.py: 15 passed.
  • Confirmed SystemPromptFile exists in claude-agent-sdk==0.2.174. Not run against a real claude.exe here.

🤖 Generated with Claude Code

The Claude Agent SDK turns a string system prompt into
`--system-prompt <text>` on the CLI command line. Windows caps the whole
command line at 32,767 characters, so Mastery Path (about 45K characters)
failed to spawn with WinError 206. Python raises that as
FileNotFoundError, and the SDK reports it as "Claude Code not found".

Prompts over 8,000 characters are now written to a content-addressed file
in the provider's temp workspace and passed as the SDK's
`{"type": "file", "path": ...}` option. Shorter prompts stay inline.

Fixes HKUDS#2333

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants