-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Description
- I have verified this feature I'm about to request hasn't been suggested before
The Problem
When working on long sessions or complex plans, I often set specific rules or constraints at the beginning — things like "don't modify files outside this module" or "always run tests after changes." But as the conversation grows longer, the agent tends to drift away from these initial instructions, even before compaction happens.
I know #8932 addresses pinning messages through compaction, and #3099 describes the similar problem of agents not following rules after compaction. But I think the issue is broader than just compaction — it's about having a structured way to define and enforce task-specific rules throughout a session or plan's entire lifecycle.
Why Not Use Global Rules?
Global rules in opencode.json or AGENTS.md work great for team-wide conventions. But they're not ideal for:
- Temporary constraints: "Focus only on the auth module for this session"
- Task-specific rules: "Don't delete any tests during this refactor"
- Conflicting requirements: Rules that make sense for one task but would break another
Putting every task's rules into global config creates noise and can cause unexpected behavior elsewhere.
What I'm Proposing
Session-level Rules
A way to define rules that persist for the current session only:
/session-rules add "Always explain changes before making them"
/session-rules add "Never touch files outside src/auth/"
/session-rules list
/session-rules clear
Or via configuration that's scoped to the session.
Plan-level Rules
When working with a plan, it would be useful to attach rules that stay active throughout the plan's execution:
{
"plan": {
"rules": [
"Maintain backward compatibility for public APIs",
"All changes must pass the existing test suite"
]
}
}Key Requirements
- Rules should survive compaction — they need to be re-injected after compaction (similar to [FEATURE]: Allow pinning important instructions/messages per session to keep them after compaction. #8932's pinning)
- Rules should be visible — users should be able to see what rules are currently active
- Priority should be clear — plan rules > session rules > global rules when there are conflicts
Relationship to Other Issues
- [FEATURE]: Allow pinning important instructions/messages per session to keep them after compaction. #8932: Proposes pinning messages through compaction. This complements that by providing explicit rule management rather than implicit preservation.
- Agent no follow rules after compact session #3099: Describes agents not following rules after compaction. This addresses a broader case where rules get "forgotten" even without compaction.
- [FEATURE]: Advanced Dual-Scope Memory System for OpenCode #9211: Proposes a dual-scope memory system. There's overlap in the goal of scoped context management, but this focuses specifically on user-defined rules/instructions.
Use Cases
Some examples where this would help:
- Refactoring tasks: Set rules like "preserve all public API signatures" and trust they'll be followed throughout a multi-file change
- Code review sessions: "Only focus on security issues, don't make any changes"
- Feature implementation: "Every new function needs a docstring and tests"
- Long-running plans: Ensure the plan agent doesn't expand scope without asking
Summary
The goal is to make AI agent behavior more predictable and reliable in complex tasks. Right now, users have to constantly re-state their requirements as conversations grow. Having explicit, scoped rules that persist would reduce that friction and improve trust in the agent's behavior.