Repository navigation
Fix #187: Stop writing chat system prompts into the project's CLAUDE.md - #307
zwanski-start wants to merge 1 commit into
Conversation
…t's CLAUDE.md
The assistant and spec-creation chat sessions wrote their restrictive
system prompts ("What You CANNOT Do: modify source code...") to the
project's root CLAUDE.md. Claude Code, Cursor and other tools read that
file outside AutoForge, so the rules blocked normal editing, and any
user-authored CLAUDE.md was overwritten.
The prompts now go to .autoforge/{assistant,spec}_system_prompt.md and
are passed with --system-prompt-file, which still avoids the Windows
command line length limit. A root CLAUDE.md left behind by an older
version is removed when it still starts with one of the generated
prompts; user-written CLAUDE.md files are left alone (and are still
loaded as project context via setting_sources).
Requires claude-agent-sdk>=0.1.51 (first release with SystemPromptFile).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🔍 QA report: ✅ PassedTester: Ken (cubefarm agent, in a fresh session) · Round: 1 · Author: Dennis The PR moves the assistant and spec chat system prompts out of the project's root CLAUDE.md into .autoforge/{assistant,spec}_system_prompt.md and passes them with --system-prompt-file. The prompt still never goes on the command line, so the Windows length limit is still avoided, and a user-written CLAUDE.md is kept and still loaded through setting_sources. A probe with a mocked SDK client confirmed the CLI command both sessions build, that old generated CLAUDE.md files are removed (including ones with CRLF endings) and that user files are kept. ruff, mypy, pytest and the UI build/lint give the same results as on master, and the PR introduces no regressions.
🧪 Commands run
No browser screenshots were taken in this round. Posted by cubefarm · merges automatically once GitHub's checks pass |
… (Windows command line too long) Adaptations: port remove_legacy_claude_md and its prompt-prefix list from AutoForgeAI#307 and call it from write_system_prompt_file, so a CLAUDE.md generated by older versions is removed while a user-authored one is never touched. Keep my-features' requirements pins (claude-agent-sdk>=0.1.81, mcp<2). New test_chat_claude_md.py starts the assistant and spec sessions against a fake SDK client: a pre-existing CLAUDE.md stays unchanged (it was overwritten before this change), none is created, and legacy generated files are removed. Integrates AutoForgeAI#316 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeH26pcsqoxPb3CDs8g1VN
Problem
AssistantChatSessionandSpecChatSessionwrote their system prompts to the project's rootCLAUDE.md, so the SDK would pick them up throughsetting_sources=["project"]. This was done to get around the Windows command-line length limit. The catch is that Claude Code, Cursor and other tools also read that file. Outside AutoForge, the assistant's "What You CANNOT Do: modify source code / run bash" rules then blocked normal editing. It also overwrote anyCLAUDE.mdthe user had written.Fix
write_system_prompt_file()inserver/services/chat_constants.pywrites the prompt to.autoforge/{assistant,spec}_system_prompt.md. Both sessions now pass it withsystem_prompt={"type": "file", ...}, which the CLI receives as--system-prompt-file. The prompt still never goes on the command line, so the Windows limit is still avoided.remove_legacy_claude_md()cleans up projects that older versions already broke. It deletes the rootCLAUDE.mdonly if the file still starts with one of the two generated prompts: the assistant prompt, or thecreate-spec.mdfrontmatter. ACLAUDE.mdthe user wrote is never touched.setting_sourcesstays as it was, so the user's realCLAUDE.mdis still loaded as project context for the chat sessions.*_system_prompt.mdto the generated.autoforge/.gitignore.claude-agent-sdkfrom>=0.1.39to>=0.1.51in both requirements files. 0.1.51 is the first release that supportsSystemPromptFile/--system-prompt-file; I checked the published wheels for 0.1.46–0.1.52.CLAUDE.md.Verification
ruff check .: passes.mypy server/services/ autoforge_paths.py: the same errors as on master (unusedtype: ignorecomments); this change adds none.python test_security.pypasses.pytest test_client.py test_ws_security.py: 31 passed.CLAUDE.mdis removed and a user-written one is kept. The SDK builds--system-prompt-file <path>from the option.AssistantChatSessionon a temp project whoseCLAUDE.mdsaid "this project uses tabs for indentation":CLAUDE.mdwas unchanged afterwards, and.autoforge/assistant_system_prompt.mdwas created.Assumptions
CLAUDE.mdis safe, because its content was always regenerated on every chat start. Matching on the prefix is a conservative test, so a hand-written file is not deleted.system_promptinline and doesn't touchCLAUDE.md, so I left it unchanged.Closes #187
🤖 Generated with Claude Code