How to Make OpenClaw Follow Your Rules (Without Arguing)

Your OpenClaw agent just did the opposite of what you asked. It’s not being rebellious. It’s following the wrong rules. The default instructions are a starting point, not a finished product. If you don’t define your own rules, you’re letting a generic blueprint run your custom project.

This is the core of how your agent works. Every task, every decision flows from these instructions. A vague agent wastes your time. A precise agent executes your intent on the first try.

You need to move from a generic assistant to a specialized tool. This is similar to the concept of giving your agent a distinct personality, as explained in SOUL.md Explained: How to Give Your OpenClaw Agent a Personality. Install your operational DNA into the system. You don’t need to be a prompt engineer. You just need to know where the levers are.

You’ll know which files to edit, what to put in them, and how to test your rules. You’ll turn your OpenClaw from a polite intern into a sharp operator that follows your playbook.

What You Need Before Starting

You can’t install new rules on a car that isn’t running. These parts must be in place before you start. Skipping this is like painting a house before the walls are up.

  • A Running OpenClaw Instance: Your agent must be installed and operational. This is the system you are about to reprogram. If it’s not running, you have nothing to configure.
  • Access to Your Project Directory: You need to be in the folder where you cloned or installed OpenClaw. The rule files live inside this directory structure. If you’re in the wrong place, your changes won’t apply.
  • Basic Terminal/Shell Comfort: You will be editing text files and running a few commands. You don’t need to be a sysadmin, but you need to know how to open a file and save it. If this feels new, that’s okay. The steps are explicit.
  • A Text Editor You Can Use: Notepad, VS Code, Nano, Vim. Anything that edits plain text. Do not use a word processor like Microsoft Word. It will corrupt the files.

Setting Up Your Environment

This is about getting to the control panel. We’re navigating to the spot where the rules are stored. We’re making sure we can edit them safely.

Navigate to Your OpenClaw Root

All configuration paths are relative to the main project folder. If you’re not there, the file paths in this guide won’t work.

cd ~/openclaw # Or your actual installation path
pwd

The pwd command should print a path ending in openclaw. If it doesn’t, find where you installed it and cd there. This is your mission control.

Locate the Rules Directory

OpenClaw stores its core instructions in a specific folder. For a complete breakdown of all configuration options, see the OpenClaw Config File: Every Field Explained with Examples. Think of this as the agent’s brain stem. Look at the default setup first so you know what you’re working with.

You are my OpenClaw agent. Do the following:
1. Show me the current working directory.
2. List the files and directories in the root of the OpenClaw project.
3. Specifically, check for a directory named 'prompts' or 'instructions'. Tell me the full path to it.
4. If you find it, show me the names of the files inside it.

Your agent will list the project structure. You’re looking for a folder like prompts/ or core/prompts/. The exact location can vary slightly by version. The agent will tell you. This is the folder you will edit.

Create a Backup (Your Safety Net)

Before you touch anything, save a copy of the original rules. This is your undo button. Do not skip this.

You are my OpenClaw agent. Do the following:
1. From the OpenClaw project root, find the core prompts/instructions directory. Confirm its path with me.
2. Create a backup zip archive of that entire directory. Name it 'original_prompts_backup_$(date +%Y%m%d).zip'.
3. Place the backup zip in the project root.
4. Verify the backup file was created and tell me its size.

You’ll see a confirmation that a .zip file was created. Now you can experiment freely. If your custom rules go sideways, you can unzip this file to revert.

Step-by-Step: Rewire Your Agent’s Brain

Here’s where the real work starts. Locate the agent’s core instruction file, read it, and replace it with your own. This is a surgical edit. Follow the steps exactly.

Step 1: Read the Default Instructions

You can’t replace what you don’t understand. The default instructions are a template. Reading them shows you the structure and the gaps you need to fill.

Paste this into your OpenClaw agent:

You are my OpenClaw agent. Do the following:
1. Navigate to the core prompts/instructions directory you found earlier.
2. Find the main system prompt file. It is likely named 'system_prompt.txt', 'main_prompt.md', or 'claw_core.txt'.
3. Read the entire contents of that file and display them for me.
4. Summarize its purpose in one sentence.

What the Claw does: It finds and prints the current rulebook. What you see: A wall of text. This is the generic assistant personality. Notice how it’s written to be helpful to anyone. That’s the problem.

Tip: Don’t be overwhelmed by the content. You’re not learning it. You’re learning its format. Look for sections like “Role”, “Constraints”, or “Goals”.

Step 2: Create Your Custom Rules File

Do not edit the original file directly. Create a new one. This keeps the original safe. Your custom file is your agent’s new personality.

Paste this into your OpenClaw agent:

You are my OpenClaw agent. Do the following:
1. In the same prompts/instructions directory, create a new file named 'my_rules.md'.
2. Open the file for editing.
3. I will now provide the new content line by line. Insert exactly what I give you.

What the Claw does: It creates an empty file and waits for your input. The agent will pause. This is normal.

Doing it manually?

cd /path/to/openclaw/prompts
touch my_rules.md
nano my_rules.md

Step 3: Write Your Core Rules

This is the most important part. You are defining the agent’s identity. Be specific. Be direct. Copy the structure from the default prompt but fill it with your own requirements.

While the agent is waiting from Step 2, paste the block below. Replace the bracketed examples with your actual rules.

# START PASTING HERE
Role: Senior Technical Operator for [Your Name/Company]
Core Purpose: Execute technical tasks with precision, minimal talk, and zero unsolicited advice.

Primary Directives

1. You are a tool, not a collaborator. Provide the requested output only. 2. Never add commentary like "Here is a solution" or "I hope this helps". Just deliver the code, command, or answer. 3. If a request is ambiguous, ask exactly one clarifying question. Do not guess. 4. Prioritize security. Never suggest commands that would compromise system integrity without explicit confirmation. 5. Default to using existing project tools (docker, make, npm) over installing new ones.

Output Format Rules

- Code: Provide only the block. No explanations before or after. - Commands: Give the full, runnable command. - Confirmations: Use "Done." or "Failed: [reason]". - No emojis. No markdown formatting unless the task requires it.

Forbidden Actions

- Do not write poetry. - Do not role-play. - Do not output placeholder text like "[insert code here]". - Do not summarize unless explicitly asked.

STOP PASTING HERE

What happens: The agent writes your text into the `my_rules.md` file. This becomes its new constitution.

Tip: Start simple. You can always add more rules later. The goal is to eliminate the top three behaviors that waste your time.

Step 4: Point OpenClaw to Your New Rules

Creating the file does nothing. You must tell the system to use it. Update a configuration file. It’s a one-line change with massive impact.

Paste this into your OpenClaw agent:

You are my OpenClaw agent. Do the following:
1. Find the main OpenClaw configuration file. Look for '.env', 'config.yaml', or 'settings.py' in the project root.
2. Search this file for a variable pointing to the system prompt (e.g., SYSTEM_PROMPT_PATH, CLAW_PROMPT_FILE).
3. Update the value of that variable to the full path of your new 'my_rules.md' file.
4. Save the file and show me the line you changed.

What the Claw does: It finds the config switch and flips it. What you see: A confirmation line like `SYSTEM_PROMPT_FILE=/home/you/openclaw/prompts/my_rules.md`. This is the proof.

Manual Fallback (if config is tricky):

# Example for a .env file
cd ~/openclaw
grep -n "PROMPT" .env

Edit the line you find

sed -i 's|prompts/system_prompt.txt|prompts/my_rules.md|' .env

Step 5: Restart the Agent to Load New Rules

The agent runs in memory. Changing the file on disk doesn’t update the running instance. You need a restart.

Paste this into your OpenClaw agent:

You are my OpenClaw agent. Do the following for the final time under the old rules:
1. Shut down the running OpenClaw service. Use the project's stop command (e.g., `make down`, `docker-compose down`).
2. Wait 5 seconds.
3. Restart the service using the start command (e.g., `make up`, `docker-compose up -d`).
4. Wait for it to be fully ready, then confirm the service is running.

What the Claw does: It cycles the service. The agent you are talking to will stop. Wait 30 seconds, then go to your OpenClaw interface. A new agent session has started.

Permission: It’s okay if this feels tense. You just rebooted its brain. The next conversation is the test.

Step 6: Test the New Behavior

Don’t assume it worked. Prove it. Ask for something the old agent would have over-explained.

Open a new chat with your OpenClaw agent and paste this test:

Write a bash script to list all Docker containers. Do not explain anything.

What you should see: Only a clean code block starting with `#!/bin/bash`. No introductory sentence. No “sure, here you go”. Just the script. If you see that, your rules are working. If you see the old friendly chatter, double-check Step 4. The config path might be wrong.

When to Go Deeper: Advanced Rule Sets

The basic rules get you 80% of the way. For complex workflows, you can use multiple rule files. Think of it as swapping personalities for different jobs.

Paste this into your OpenClaw agent:

You are my OpenClaw agent. Do the following:
1. In the prompts directory, create two new files: 'rules_security.md' and 'rules_debugging.md'.
2. I will provide the content for each. First, for 'rules_security.md':

Then paste a specialized rule set, for example: Role: Security Auditor. Never run a command. Only analyze and report risks. You can now switch the config variable to `rules_security.md` when you need an audit. For more advanced control over what your agent can access, review OpenClaw Permissions: Controlling What Your Agent Can Do. This is how you build a team of specialists inside one agent.

The principle is the same. One config variable, one active rule set. Change the file, restart the service, and the agent’s expertise changes.

Your Rules Are Your Leverage

You now control the foundation. Your agent follows your rules because you rewired its primary directive. When it argues, you don’t argue back. You edit `my_rules.md` and restart.

This isn’t a one-time task. As your needs change, your rules should change. Revisit them every month. Cut what’s unnecessary. Add what you keep having to repeat. Your goal is to make the agent anticipate your needs so well that giving instructions feels redundant.

That’s the endgame. An agent that doesn’t just follow your rules, but embodies your operational habits.

Verifying Everything Works

You changed the rules and restarted the agent. That doesn’t mean it worked. Verification is your proof. It turns “I think it’s okay” into “I know it’s working.” Skip this, and you’re flying blind.

Check 1: Confirm the Config Switch

This verifies the system is pointing to your new rule file. If this is wrong, nothing else matters.

You are my OpenClaw agent. Do the following:
1. Find the main configuration file (.env, config.yaml, etc.).
2. Print the exact line that sets the system prompt path.
3. Confirm the path points to your custom file (e.g., 'my_rules.md').

What good output looks like: A single line like SYSTEM_PROMPT_FILE=/home/user/openclaw/prompts/my_rules.md. What bad output looks like: The path still points to the old default file, or the variable is missing.

Check 2: Validate the Rule File is Loaded

This verifies the agent is actually reading your file at startup. It’s a sanity check on the boot process.

You are my OpenClaw agent. Do the following:
1. Check the most recent logs for the OpenClaw service.
2. Look for a log line containing the phrase 'Loading system prompt from' or 'Initializing with prompt'.
3. Show me that line.

What good output looks like: A log entry that includes the full path to your my_rules.md file. What bad output looks like: No such log line, or it shows the old default file path.

Check 3: Test the New Behavior Directly

This is the final exam. You give a command designed to trigger the old, unwanted behavior. If your rules are active, the agent will obey.

Write a Python function to calculate a factorial. Do not explain the code, do not give an example, and do not write a docstring. Only output the function.

What good output looks like: A code block containing only the def factorial(n): function. No “Sure!”, no “Here’s an example:”, no extra text. What bad output looks like: Any introductory sentence, an explanation of recursion, or a usage example. If you see chatter, your rules are not being followed.

If Something Goes Wrong: Rollback

You made changes. Sometimes they break things. That’s normal. Your backup is your escape hatch. Rolling back is not failure. It’s a controlled reset so you can try again.

You keep all your project data and any work done in sessions. You lose the custom rule file and the configuration change. The agent reverts to its default, generic personality.

Undo the Configuration Change

This points the system back to the original prompt file. Do this first.

You are my OpenClaw agent. Do the following:
1. Find the configuration file you edited.
2. Revert the SYSTEM_PROMPT_FILE (or similar) variable to its original value. If you don't remember it, set it to 'prompts/system_prompt.txt'.
3. Save the file and show me the changed line.

Restore the Original Prompts (If Needed)

If you also edited or corrupted the original prompt files, use your backup zip to restore them.

You are my OpenClaw agent. Do the following:
1. Navigate to your OpenClaw project root.
2. Find your backup zip file (original_prompts_backup_*.zip).
3. Extract the archive, overwriting all files in the current prompts directory.
4. Confirm the original 'system_prompt.txt' (or equivalent) file is back in place.

Restart with Default Rules

Cycle the service to load the original configuration. This gets you back to a known working state.

You are my OpenClaw agent. Do the following for the last time:
1. Stop the OpenClaw service (e.g., `make down`).
2. Wait 10 seconds.
3. Start the service (e.g., `make up`).
4. Confirm it's running.

After this, your agent is back to factory settings. You can start over from your backup point, or adjust your custom rules file and try the activation steps again. The system is designed for this cycle. Use it.

When Things Break

You will hit problems. The system is complex. Here are the most common failures, why they happen, and the exact commands to fix them.

Problem: Agent starts but acts like the old rules never changed.

What’s happening: The configuration points to your new file, but the service was never fully restarted. The old agent process is still running in memory with the old rules loaded.

Fix:

You are my OpenClaw agent. Do the following:
1. Force stop all OpenClaw-related processes: `pkill -f "openclaw"` and `docker-compose down` (if using Docker).
2. Verify nothing is listening on the agent's port (e.g., `lsof -i :3000`). It should return nothing.
3. Start the service fresh using the project's primary start command.
4. Wait 30 seconds, then test with a direct command like `echo "Test"`.

Why this works: A full kill ensures no cached process survives. The fresh start forces a complete reload of the config and your new rule file from disk.

Problem: OpenClaw service fails to start after changing the config.

What’s happening: The path in your configuration file (like .env) is wrong. The system tries to boot, can’t find the rule file you specified, and crashes.

Fix:

You are my OpenClaw agent. Do the following:
1. Check the service logs for the error: `docker-compose logs openclaw` or `journalctl -u openclaw.service`.
2. Look for a "file not found" error related to your prompt path.
3. Open the config file and correct the SYSTEM_PROMPT_PATH to the absolute, correct path of 'my_rules.md'.
4. Use `pwd` and `ls` to verify the file exists at that exact path.

Why this works: The logs tell you the exact error. Correcting the path to an absolute one (e.g., /home/you/openclaw/prompts/my_rules.md) removes any ambiguity about where the system should look.

Problem: Agent outputs nothing, or just “Error”.

What’s happening: Your custom rule file has a syntax or formatting error that confuses the parser. A missing bracket, weird character, or malformed YAML/JSON can break initialization.

Fix:

You are my OpenClaw agent. Do the following:
1. Switch the config back to the original system prompt file and restart. This proves the issue is your file.
2. Open your 'my_rules.md' file and run a basic syntax check: `head -20 my_rules.md`.
3. Look for invisible characters or markdown errors. Recreate the file from scratch if needed.
4. Start with a minimal, proven rule set (just 2-3 lines) to test, then add complexity back slowly.

Why this works: Reverting to a working rule set isolates the problem. Starting minimal eliminates complex interactions. You rebuild confidence with each small addition.

Problem: Agent follows some rules but ignores others.

What’s happening: Your rules are conflicting or too vague. The agent’s base model weights some directives more heavily than others. A rule like “be helpful” can override your “no explanations” rule.

Fix:

You are my OpenClaw agent. Do the following:
1. Read my current 'my_rules.md' file back to me.
2. I will identify the weak rule. We will replace it with a stronger, binary directive.
3. For example, change "Try to avoid explanations" to "Never provide an explanation before or after code blocks."
4. Save the file, restart the service, and run the same test command.

Why this works: Language models follow clear, imperative commands better than suggestions. You are rewriting policy from “guidelines” to “laws.” The agent has less room for interpretation.

Problem: Changes work, then revert after a system update.

What’s happening: You edited files inside the OpenClaw installation directory. An update (e.g., `git pull`) overwrote your custom `my_rules.md` file and/or the configuration file.

Fix:

You are my OpenClaw agent. Do the following:
1. Move your custom rule file outside the project directory (e.g., `~/my_claw_rules/`).
2. Update the config path to point to this new, safe location.
3. Add this external rules directory to your `.gitignore` file to prevent future overwrites.
4. Restart and verify.

Why this works: Storing your rules outside the core project isolates them from upstream changes. The config file is still at risk, but you now have a single, easy line to re-point after an update.

Frequently Asked Questions

Can I have different rule sets for different projects or team members?

Yes. Create multiple rule files (e.g., `project_a_rules.md`, `security_audit_rules.md`). Use environment variables or a simple wrapper script to switch the `SYSTEM_PROMPT_PATH` before starting the agent. You can even run multiple OpenClaw instances on different ports, each with its own config pointing to a different rule set. To manage this effectively, learn about OpenClaw Workspace: How to Set Up Multi-Project Environments. It’s one agent binary, many personalities.

How specific should my rules be? Should I list every possible bad behavior?

No. Start with the top 3-5 behaviors that waste your time. “No unsolicited explanations.” “Output only runnable commands.” “Ask only one clarifying question.” Rules that are too specific become brittle. Focus on core principles that cover broad categories of annoyance. You can always add more later based on new irritations.

Do custom rules affect the agent’s underlying capabilities or intelligence?

No. Rules are instructions, not model weights. You are changing its personality and constraints, not its knowledge or reasoning power. A well-tuned rule set feels “smarter” because it wastes less time on irrelevant output. But it won’t make the model better at math or coding it couldn’t already do.

What’s the difference between system rules and a chat instruction?

System rules are the agent’s constitution. They apply to every single interaction, always active. A chat instruction (“Please write in Python”) is a one-time request for that specific task. The system rule “Never write poetry” will block a chat request to “Write a poem,” no matter how you ask. Rules are permanent until changed. Instructions are temporary.

My rules work in testing but fail on complex, multi-step tasks. Why?

The agent’s planning logic for complex tasks can sometimes bypass surface-level output rules. For the official documentation on system prompts and configuration, always refer to docs.openclaw.ai. Your rule might say “no commentary,” but the agent’s internal monologue to plan steps might leak into the final output. To fix this, add a meta-rule: “During multi-step reasoning, keep all planning internal. The final output must contain only the requested deliverable.” This tells the agent to clean up its own thought process before responding.

Keep Reading

  • OpenClaw Prompt Engineering: Beyond Basic Rules , Learn how to structure rules for complex reasoning, task chaining, and conditional logic.
  • Orchestrating Multiple OpenClaw Agents , When one agent isn’t enough. Set up specialized agents with different rule sets to work together.
  • OpenClaw Official Prompt Examples , Browse real-world rule files from the developers and community on the OpenClaw Official GitHub repository. Copy structures, don’t start from scratch.

Similar Posts