feat: project rules with .claw/rules/ and multi-framework auto-import#2830
Open
TheArchitectit wants to merge 8 commits intoultraworkers:mainfrom
Open
feat: project rules with .claw/rules/ and multi-framework auto-import#2830TheArchitectit wants to merge 8 commits intoultraworkers:mainfrom
TheArchitectit wants to merge 8 commits intoultraworkers:mainfrom
Conversation
Adds a project rules system for loading instruction files into the
system prompt, plus auto-import from other AI coding frameworks.
## New rule locations (auto-loaded, sorted alphabetically)
- `.claw/rules/*.md` / `.claw/rules/*.txt` / `.claw/rules/*.mdc`
- `.claw/rules.local/*.md` — personal/local rules (gitignored)
- Existing: `CLAUDE.md`, `CLAUDE.local.md`, `.claw/CLAUDE.md`,
`.claw/instructions.md`
## Auto-import from other frameworks
When users switch to claw-code from another tool, their existing
rules are automatically detected and loaded:
- Cursor: `.cursorrules`, `.cursor/rules/`
- GitHub Copilot: `.github/copilot-instructions.md`
- Windsurf: `.windsurfrules`, `.windsurfrules/`
- Aider: `.aider.conf.yml` instructions block
- Pi (Plandex): `.plandex/instructions.md`, `.plandex/plan.md`
- OpenCode: `opencode.json` instructions field
- Crush: `.crush/CLAUDE.md`, `.crush/rules/`
## Config option
`rulesImport` in settings.json controls framework auto-import:
- `"auto"` (default) — import from all detected frameworks
- `"none"` — only load .claw/rules/ and CLAUDE.md files
- `["cursor", "copilot"]` — import only from listed frameworks
```json
{
"rulesImport": "auto"
}
```
💘 Generated with Crush
Assisted-by: GLM 5.1 FP8 via Crush <[email protected]>
Some OpenAI-compatible providers (e.g., GLM-5) omit the `id` field in streaming and non-streaming responses. Adding #[serde(default)] allows the parser to accept these responses instead of failing with "missing field `id`". Co-Authored-By: Claude Opus 4.7 <[email protected]>
Adds scripts/install.sh that builds the release binary and links it to ~/.local/bin/claw. Run after code changes to update the CLI. Co-Authored-By: Claude Opus 4.7 <[email protected]>
When a provider returns HTML (e.g., error page, wrong endpoint) instead of JSON in an SSE stream, provide a clear error message instead of hanging or failing with a cryptic parse error. Co-Authored-By: Claude Opus 4.7 <[email protected]>
When a provider returns a JSON error (e.g., {"error":{"message":"..."}})
without SSE framing (no "data:" prefix), the SSE parser was silently
ignoring it and hanging. Now detects and surfaces these errors.
Also handles HTML responses that lack SSE framing.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
Some providers (GLM, DeepSeek) emit reasoning tokens in `reasoning_content` or nested `thinking.content` fields instead of `content`. Added support for these fields so reasoning models work correctly. Co-Authored-By: Claude Opus 4.7 <[email protected]>
The final streaming chunk from some providers contains only finish_reason and usage, with no delta field. Made it optional to prevent parse errors. Co-Authored-By: Claude Opus 4.7 <[email protected]>
When preserve_recent_messages == 0, raw_keep_from equals messages.len(), causing index out of bounds when accessing session.messages[k]. Added k >= session.messages.len() check to prevent panic. Reason: Compaction with preserve_recent_messages=0 triggered OOB access when checking for tool-use/tool-result pair preservation at boundary. Co-Authored-By: Claude Opus 4.7 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a project rules system for loading instruction files into the system prompt, plus auto-import from other AI coding frameworks so users switching to claw-code don't have to duplicate their rules.
Problem this solves
No structured way to organize project rules
Before: rules could only go in
CLAUDE.mdor.claw/CLAUDE.md— single files. No way to organize rules by topic, no way to gitignore personal rules.Fix:
.claw/rules/directory — drop any.md,.txt, or.mdcfiles, auto-loaded alphabetically..claw/rules.local/for personal rules that don't get committed.Switching from Cursor/Copilot/Windsurf = duplicate all rules
Before: users coming from other AI coding tools had to manually copy their rules into CLAUDE.md.
Fix: claw-code auto-detects and imports rules from all major frameworks:
.cursorrules,.cursor/rules/.github/copilot-instructions.md.windsurfrules,.windsurfrules/.aider.conf.ymlinstructions block.plandex/instructions.md,.plandex/plan.mdopencode.jsoninstructions field.crush/CLAUDE.md,.crush/rules/No way to control which frameworks get imported
Fix:
rulesImportconfig insettings.json:"auto"(default) — import from all detected frameworks"none"— only load.claw/rules/andCLAUDE.mdfiles["cursor", "copilot"]— import only from listed frameworksHow it works
All loaded files are deduplicated by content hash, so the same rule appearing in both
.cursorrulesand.claw/rules/cursor.mdwon't appear twice.Example directory structure
Template support (.mdc files)
.claw/rules/also loads.mdc(Markdown Context) files — the same format used by Cursor's rules.Files changed
runtime/src/prompt.rsdiscover_instruction_files()scans.claw/rules/,.claw/rules.local/, and 7 framework locations. Addedpush_rules_dir(),push_framework_imports(),read_aider_instructions(),read_opencode_instructions()runtime/src/config.rsRulesImportConfigenum,rules_importfield, accessor, parserruntime/src/config_validate.rsrulesImportfield validationruntime/src/lib.rsRulesImportConfigTest plan
cargo build --release— clean build.claw/rules/test.mdand verify it appears in system prompt.claw/rules.local/personal.mdand verify it loads.cursorrulesand verify auto-import"rulesImport": "none"and verify framework files skipped💘 Generated with Crush