Skip to content

fix(cmd): add support for custom system prompt and improve the existing prompt - #2976

Closed
taoeffect wants to merge 18 commits into
charmbracelet:mainfrom
taoeffect:system-prompt
Closed

taoeffect wants to merge 18 commits into
charmbracelet:mainfrom
taoeffect:system-prompt

Conversation

@taoeffect

@taoeffect taoeffect commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

This PR greatly improves the system prompt handling of Crush.

Adds the ability to override the system prompt:

-p --sys-prompt                           Use a custom system prompt file

It does this while preserving all of the custom template logic in coder.md.tpl for injecting environment status, skills, memory, etc.

Users can also now override the default system prompt with their own by modifying ~/.config/crush/crush.json or their project-local .crush/crush.json:

{
  "options": {
    "system_prompt_path": "/path/to/system-prompt.md"
  }
}

Project-local override:

{
  "options": {
    "data_directory": "./.crush",
    "system_prompt_path": "./.crush/system-prompt.md"
  }
}

The existing non-templated system prompt directives have been moved to default_system_prompt.md and have been greatly improved.

Problems Fixed With Existing System Prompt

The existing system prompt had many problems:

  1. It was very long and contained many DRY violations (repititions)
  2. It contained self-contradictions like "read only target sections using offset and limit" vs "Read entire file before editing"
  3. It was dogmatic about coding choices that should be left to users (e.g. "NEVER ADD COMMENTS")

So I first ran the original system prompt through Gemini 3.5 Flash, GPT-5.5, and Opus 4.7 to both condense it by fixing DRY violations, and also verifying multiple times that the condensed version preserved all original directives. Then I went manually in and made some adjustments to the original directives to make them less dogmatic and allow users to override the defaults (e.g. "NEVER COMMENT!") with their own directives.

The new default system prompt is now 38.8% shorter while preserving all directives and removing dogmatic language that infringes on reasonable user-choices.

AI Disclosure

GPT-5.5 (xhigh) and Qwen 3.7 Max were used in the coding of this PR with 2 rounds of review (GPT-5.5 and Copilot).

GPT-5.5, Opus 4.7, and Gemini 3.5 Flash were used in the refining, improvement, and verification of the new default system prompt, along with myself.

  • I have read CONTRIBUTING.md.
  • I have created a discussion that was approved by a maintainer (for new features).

taoeffect added 8 commits May 21, 2026 10:24
Separate the static coder instructions from dynamic prompt sections so the default body can be embedded and injected through prompt data. This preserves existing rendering while creating a clean seam for configurable system prompt overrides.
Add a config option for pointing Crush at a custom coder system prompt file and load it during prompt rendering. This keeps the embedded default as the fallback while surfacing unreadable configured files as render errors.
Add focused tests for default, configured, and runtime system prompt rendering precedence, plus CLI flag and backend workspace override propagation.

Fix backend workspace snapshots to include the runtime system prompt override so client/server workspaces preserve the effective override without persisting it.
Document configured and one-off custom system prompt usage so users can discover the new override paths.

Add schema coverage to keep options.system_prompt_path exposed in generated configuration docs.
Copilot AI review requested due to automatic review settings May 21, 2026 19:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for customizing the agent “system prompt” via both config and a CLI runtime override, and threads that value through local and server-backed workspace creation into prompt rendering.

Changes:

  • Add options.system_prompt_path (schema + config) and a runtime override (--sys-prompt / -p)
  • Plumb SystemPromptPath through proto workspace creation, backend workspace creation, and prompt rendering
  • Introduce a built-in default system prompt template and tests for schema + prompt + CLI + backend behavior

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/proto/proto.go Adds SystemPromptPath to workspace proto payloads
internal/config/store.go Adds runtime override storage for system prompt path
internal/config/config.go Adds options.system_prompt_path to config + JSON schema
internal/cmd/root.go Adds --sys-prompt/-p flag and wires it into local/server setup
internal/cmd/system_prompt_test.go New tests for flag presence/inheritance and local override plumbing
internal/cmd/schema_test.go Ensures JSON schema includes system_prompt_path
internal/backend/backend.go Applies system prompt override during workspace creation and exposes it via proto
internal/backend/backend_test.go Tests backend workspace creation carries system prompt override through
internal/agent/templates/default_system_prompt.md Adds embedded default system prompt content
internal/agent/templates/coder.md.tpl Switches coder template to consume .SystemPrompt variable
internal/agent/prompts.go Embeds default system prompt and applies as default option
internal/agent/prompt/prompt.go Implements system prompt selection (default/config/override) + reads file
internal/agent/prompt/prompt_test.go Tests default/config/override precedence for prompt building
README.md Documents config + CLI usage for custom system prompts
.gitignore Ignores .agents/* subdirectories

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/agent/prompt/prompt.go Resolved
Comment thread internal/agent/prompt/prompt_test.go Resolved
Comment thread internal/cmd/system_prompt_test.go Resolved
Comment thread internal/agent/prompt/prompt.go Fixed
taoeffect added 2 commits May 21, 2026 13:18
Use the effective prompt working directory when loading custom system prompt files so runtime working directory overrides behave consistently with rendered prompt context.
Refresh prompt tests and glm-5.1 cassettes to cover the behavior and keep agent VCR fixtures aligned with the updated default prompt.
Exercise system prompt CLI override behavior at the config-store boundary instead of initializing a full local workspace. This avoids opening app resources under the test TempDir on Windows while still covering the runtime override path used by workspace setup.
taoeffect added 5 commits May 21, 2026 13:59
Test system prompt CLI override behavior without initializing config loading or temp workspaces. This avoids Windows cleanup failures from process-global setup while keeping coverage on the runtime override path used by local workspace startup.
Short-circuit pre-cancelled jq invocations before parse/compile work and replace a fixed background-shell sleep with a bounded completion wait so Windows race CI is not dependent on tight scheduler timing. Also refine the default system prompt coding guidance.

💘 Generated with Crush

Assisted-by: Crush:[GPT-5.1 Codex Max]
Update all glm-5.1 VCR cassettes to reflect the new coding_style
section and "user told you to do so" autonomy directive added to
the default system prompt.

💘 Generated with Crush

Assisted-by: Crush:[Qwen 3.7 Max]
@Artyrm

Artyrm commented Jun 9, 2026

Copy link
Copy Markdown

Yes, custom prompt is a must.

@taoeffect

Copy link
Copy Markdown
Contributor Author

This feature is available in my fork which tracks upstream if you need it: https://github.com/taoeffect/crush

@Artyrm

Artyrm commented Jun 13, 2026

Copy link
Copy Markdown

Thank you, I'll give it a shot.

@Jelloeater

Copy link
Copy Markdown

@taoeffect @Artyrm That would be a nice small patch. If i recall correctly you can do something similar with Pi https://github.com/earendil-works/pi/tree/main/packages/coding-agent#context-files and Opencode? https://www.reddit.com/r/opencodeCLI/comments/1p13hsz/default_prompts_for_models/

@andrinoff

andrinoff commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Thank you for your contribution! This pull request has merge conflicts and has had no activity for over 2 months, so we are closing it to keep the queue manageable. If you would still like to get this merged, please rebase onto the latest main branch and reopen it.

@andrinoff andrinoff closed this Oct 21, 2026
@taoeffect

Copy link
Copy Markdown
Contributor Author

You mean you preferred your solution in #4141 over mine. That's fine but be honest.

@andrinoff

Copy link
Copy Markdown
Member

That's not mine (look at the commit), and this PR was automatically closed. Does this one has something over the new one by Kieran?

@andrinoff

Copy link
Copy Markdown
Member

Looking at this PR (and sorry I didn't see this PR earlier) it seems to miss out on:

  1. Customisable prompts per agent (normal, subagents, planning, e.t.c.)

  2. crushrc

  3. Kieran's (again, not mine) implementation seems much smaller

If you do have any features to add to that PR, please, do say, either I'll pass it on to Kieran, or can apply a patch to the branch.

Sorry again for not noticing this PR earlier. Thank you for your work here!

@taoeffect

taoeffect commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

I do see that Kieran's is more inline with Crush's current needs (i.e. the crushrc and the new (?) prompts for specific contexts).

I would request:

  • Adding support for crush.json as well for those who prefer Crush's original config format
  • Adding support for global vs project-local overrides (the way this PR does)
  • Adding the ability to override from the CLI (the -p --sys-prompt from this PR)
  • Improving the default system prompt (see the improvements made in this PR)

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.

Custom System Prompt Support system prompts globally(not per-project)

6 participants