← All articles
Guide · 2026-11-13

Advanced prompt engineering: writing reusable system prompts and constraint lists for agents

Published 2026-11-13 ·Mentions: Claude Code, Cursor
Advanced prompt engineering: writing reusable system prompts and constraint lists for agents
System prompts should set constraints before letting the agent act: store rules in layers, write them as verifiable sentences, scope them by file path, and verify they take effect with the official audit and inspection methods.

1. Conclusion: write the constraints before letting the agent act

When writing system prompts for an agent, set the constraints first and only then let it act: the more specific and verifiable the constraints, the less the agent drifts.

This guide is for people already coding with Claude Code or Cursor.

2. What to prepare

Prepare a codebase you are actively working on, plus either Claude Code or Cursor. Check whether the project already has a CLAUDE.md, an AGENTS.md, or files under .cursor/rules, and read them if so; then pick three things you have repeatedly corrected the agent on — they become the first three entries of your constraint list.

No extra paid service is needed: rule files are plain text inside the project.

3. Step by step: start from one system prompt

Start by creating a CLAUDE.md at the project root for Claude Code, or a rule file under .cursor/rules for Cursor, with just three parts: what the project is, the commands used most, and the conventions that must be followed. Keep a single CLAUDE.md under 200 lines; if it grows longer, split it into files under .claude/rules/.

Then write each constraint as a verifiable sentence: write use 2-space indentation instead of format code properly, and write run npm test before committing instead of remember to test. In Cursor, rules use frontmatter fields description, globs, and alwaysApply to control scope: set alwaysApply for rules that always apply, fill in globs for rules tied to certain files, and leave them blank for rules invoked manually with @.

Next, layer the rules: personal preferences go in ~/.claude/CLAUDE.md or Cursor User Rules, where they apply only to you; team agreements go in the project-root CLAUDE.md or .cursor/rules and travel with the code; rules for one directory only are scoped with the paths field in .claude/rules/ or globs in Cursor. With layers in place, the agent reads only the parts relevant to the task.

Finally, verify: in Claude Code run /context and confirm your rule files appear in the memory file list; in Cursor open a relevant file and check whether the rule is referenced. Once verified, use the rules on a real task for two rounds and watch whether the agent still repeats the listed mistakes.

4. Common problems and fixes

If rules exist but the agent ignores them, check two things: whether the sentences are too vague, in which case rewrite them as verifiable sentences; and whether two rules contradict each other. Claude Code offers /doctor prompt-audit, which reviews instruction files for outdated and conflicting content.

When rules pile up and crowd the context, move locally scoped content into path-scoped rule files that load only when needed. The Cursor documentation advises splitting rules longer than 500 lines into smaller composable rules, and referencing templates with @ mentions instead of copying them into rules, so the agent reads them only when needed.

When a team mixes Claude Code and Cursor, do not maintain only one copy of the rules: the first reads CLAUDE.md and .claude/rules/, while the second reads .mdc files in .cursor/rules and AGENTS.md. Keep one copy on each side with matching content, and use AGENTS.md as the shared base both tools can read.

5. Notes

A system prompt is context, not enforced configuration — the Claude Code documentation states plainly that CLAUDE.md is context rather than enforced configuration; to block an action for real, use a mechanism such as a PreToolUse hook instead of relying on a sentence to stop the agent.

Put secrets, internal addresses, and test accounts only in personal files that stay out of version control, such as CLAUDE.local.md, and add them to .gitignore. Review rule files regularly and delete outdated commands and paths: stale rules mislead the agent.

The steps in this article were checked against the official pages on 2026-11-13; if platform rules change, the official pages apply.

Tools mentioned

Coding & Development · Paid — Anthropic agentic terminal coding tool capable of autonomous multi-file edits, testing, and Git workflows.
Coding & Development · Free tier + paid — AI-first code editor built on VS Code with fast multi-line Tab predictions and codebase-wide Agent.

Sources

  1. How Claude remembers your project
  2. Rules | Cursor Docs

This article is compiled from the public sources above and does not reproduce the originals in full; see the official sources for details.

Sign in to Lumo

Sign in with a one-time code sent to your email — no password. Your saved tools will sync across your devices.

The code is only used to sign you in. We store just your email and saved list (privacy policy, in Chinese).

—

Signed in. Your saved tools sync across all your devices.

0saved
View saved tools

Send feedback

Found a mistake, missing something, or have a suggestion? Tell us.