context-policy
Skill1 starsChanged 5 months agoMITView on GitHub
Control what context enters and leaves the agent's working window through policy-based rules that define allowed, blocked, and flagged file patterns, directory rules, and sensitive content patterns. This brings data-loss-prevention (DLP) discipline to agent context management by treating context as a scoped resource that must be intentionally granted, not implicitly inherited. Use before loading context for any task involving sensitive data, cross-repository boundaries, or when the agent's working context could inadvertently include files or directories that should not be read,…
- Reads credentials
In this repository117 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- advanced-orchestrationSkill
- architect-agentSkill
- implementer-agentSkill
- quality-councilSkill
- reviewer-agentSkill
- tester-agentSkill
- writer-critic-pairSkill
- authoring-skillsSkill
- api-endpoint-qualitySkill
- async-job-qualitySkill
- auth-qualitySkill
- db-migration-qualitySkill
- frontend-state-qualitySkill
- acceptance-criteriaSkill
- adaptive-flowSkill
- adaptive-prompt-selectionSkill
- adversarial-code-reviewSkill
- architecture-decision-recordsSkill
- brainstormingSkill
- brownfield-spec-enhancementSkill
- bug-fix-lifecycleSkill
- checkpoint-validationSkill
- cicd-integrationSkill
- clarify-before-codeSkill
- claude-code-hooks-packSkill
- code-context-packSkill
- code-intelligence-reviewSkill
- context-rich-implementationSkill
- crash-proof-planningSkill
- critique-pass-protocolSkill
- dependency-aware-task-orderingSkill
- deprecation-migrationSkill
- disciplined-diagnosisSkill
- docs-authorSkill
- executing-plansSkill
- external-skillSkill
- finishing-a-development-branchSkill
- git-guardrailsSkill
- goal-driven-executionSkill
- grill-user-before-buildingSkill
- guard-bypass-protocolSkill
- improve-codebase-architectureSkill
- incremental-reviewSkill
- issue-slicingSkill
- lessons-learned-dbSkill
- loop-engineeringSkill
- model-aware-configSkill
- model-weakness-memorySkill
- multi-repo-learningSkill
- orchestration-workflowsSkill
- plan-driven-executionSkill
- plan-from-specSkill
- prd-from-contextSkill
- project-constitutionSkill
- prompt-architectureSkill
- prototype-before-commitmentSkill
- quality-engineSkill
- quality-execution-contractSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 6 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Use before loading context for any task involving sensitive data, cross-repository boundaries, or when the agent's working context could …
- Very specific: line 76
If a path matches multiple rules, the most restrictive action wins: block > flag > allow.
- Distinctive: line 77
If a path matches no rule, the default depends on the scope:
- Very specific: line 81
Default mode is restrictive for privacy-sensitive scopes, permissive for general project scopes.
- Distinctive: line 131
Before loading any file into context, check it against the active policy.
- Distinctive: line 139
After a session or task, generate a context-access report:
- Distinctive: line 144
Update policy rules based on audit findings.
- Distinctive: line 223
Not applied: runtime policy daemon, inotify watcher, network-level DLP, real-time content inspection engine, or any external runtime …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Context-Policy Skill
Purpose
Control what context enters and leaves the agent's working window through policy-based rules that define allowed, blocked, and flagged file patterns, directory rules, and sensitive content patterns. This brings data-loss-prevention (DLP) discipline to agent context management by treating context as a scoped resource that must be intentionally granted, not implicitly inherited.
When to use
Use before loading context for any task involving sensitive data, cross-repository boundaries, or when the agent's working context could inadvertently include files or directories that should not be read, analyzed, or transmitted. Use proactively during project setup and reactively when a task involves privacy-sensitive or organization-restricted code.
Inputs
- A context policy file following
templates/context-policy-template.md. - The current working directory and file tree.
- Optional: a list of task-relevant files or patterns.
Policy Rule Types
A context policy defines three types of rules, each scoped to a policy section:
1. Scope
Defines what the policy applies to. Scopes can be:
project— applies to the entire repository.directory:<path>— applies to a specific directory subtree.task:<task-id>— applies only during a specific task.session— applies for the current agent session only.
2. Rules
Each rule has a pattern (glob or regex), an action, and an optional reason:
| Action | Meaning | Behavior |
allow | Permit access | File/directory is included in context |
block | Deny access | File/directory is excluded; reason recorded |
flag | Warn and permit | Access is allowed but logged for review |
3. Severity
Each rule carries a severity that determines the response when violated:
| Severity | Allow violation | Block violation | Flag violation |
error | Not applicable | Stops processing | Not applicable |
warn | Not applicable | Logs warning | Logs warning |
info | Not applicable | Logs quietly | Logs quietly |
Policy Evaluation Order
Rules are evaluated in this order:
- Block rules checked first (deny-based security: anything not explicitly allowed is suspect).
- Allow rules checked second (explicit opt-in for sensitive directories).
- Flag rules checked last (advisory warnings for patterns of interest).
If a path matches multiple rules, the most restrictive action wins: block > flag > allow.
If a path matches no rule, the default depends on the scope:
restrictivedefault: block all paths not explicitly allowed.permissivedefault: allow all paths not explicitly blocked.- Default mode is
restrictivefor privacy-sensitive scopes,permissivefor general project scopes. The policy file declares which default applies.
Sensitive Content Patterns
Patterns can match on file name, directory path, or file content. Built-in pattern categories:
File path patterns
*.env # Environment files with secrets
*.key # Private keys
*.pem # Certificates
*credentials* # Credential files
*secret* # Any file with 'secret' in the name
*.log # Log files (may contain sensitive data)Directory patterns
node_modules/ # Typically excluded from context
.vendor/ # Vendored dependencies
.git/ # Git internals
.env/ # Environment directories
secrets/ # Secret storageContent patterns (scanned when loading files)
api[_-]?key # API key declarations
password # Password assignments
secret[_-]?key # Secret key declarations
token[_-]? # Token assignments
-----BEGIN.*KEY----- # PEM-encoded keysWorkflow
Setup Phase
- Define the policy scope: project-wide, directory-specific, or task-specific.
- Choose the default mode:
restrictiveorpermissive. - List allow, block, and flag rules with patterns, actions, and severities.
- Save the policy file (convention:
context-policy.yamlor.context-policy.yamlin the scope root).
Ingress Filtering (before loading context)
- Before loading any file into context, check it against the active policy.
- Blocked files are excluded entirely; a placeholder note is inserted:
[Blocked by context-policy: <rule-id> — <reason>] - Flagged files are loaded but logged for post-session review.
- Allowed files are loaded normally.
Audit Phase (reviewing what was loaded)
- After a session or task, generate a context-access report:
- Files allowed: count
- Files blocked: list + reasons
- Files flagged: list + reasons
- Review flagged files for any sensitive data that may have leaked.
- Update policy rules based on audit findings.
Example Rules
scope: project
default: permissive
rules:
# Block sensitive directories
- id: block-secrets-dir
pattern: secrets/**
action: block
severity: error
reason: "Secrets directory must never enter agent context"
# Block credential files
- id: block-credentials
pattern: "**/*credentials*"
action: block
severity: error
reason: "Credential files contain sensitive access data"
# Allow specific config dir for this task
- id: allow-config
pattern: config/deploy/**/*.yaml
action: allow
severity: info
reason: "Deployment config needed for infrastructure task"
# Flag log files for review
- id: flag-logs
pattern: "**/*.log"
action: flag
severity: warn
reason: "Log files may contain request/response data"Integration with Privacy Filter
The context-policy skill works upstream of the privacy filter
(skills/memory/project-memory/SKILL.md). Policy-based context control determines what
files are loaded into context; the privacy filter then sanitizes the loaded content before
it enters memory or is transmitted. Together they form a defense-in-depth pipeline:
File system → Context Policy (allow/block/flag) → Privacy Filter (redact) → Context WindowOutputs
- A policy file defining allowed, blocked, and flagged paths and patterns.
- A context-access log recording what was loaded, blocked, or flagged during a session.
- A post-session audit report for review.
Failure modes
- Overly restrictive policy blocks legitimate context, causing rework. Mitigation: start
with
permissivedefault, tighten iteratively based on audit reports. - Policy file is missing or malformed. Mitigation: fall back to no policy (allow all) and log a warning; do not block work.
- Glob patterns are too broad and unintentionally block needed files. Mitigation: use specific
patterns; test with
policy check <path>before applying. - Content pattern scanning is slow on large repositories. Mitigation: prefer file/directory patterns over content scanning; content scan only on flagged paths.
Verification checklist
- Policy file is valid and all rules have
id,pattern,action,severity,reason. - Block rules catch known-sensitive paths (
.env,secrets/, credential files). - Allow rules correctly permit task-necessary paths.
- Default mode is correctly set for the scope.
- Flag rules do not create excessive noise.
- Context-access log records blocked paths with correct rule IDs.
Applied / Not Applied
- Applied: policy-based file access control with allow/block/flag actions, scope declaration, severity levels, restrictive vs permissive defaults, ingress filtering workflow, post-session audit, integration with privacy-filter pipeline.
- Not applied: runtime policy daemon, inotify watcher, network-level DLP, real-time content inspection engine, or any external runtime dependency.
Ghi chú tiếng Việt
Kiểm soát ngữ cảnh dựa trên chính sách: ba loại luật (allow/block/flag), ba mức độ nghiêm
trọng (error/warn/info), hai chế độ mặc định (restrictive/permissive). Luật block được kiểm
tra trước, sau đó allow, cuối cùng flag. Tích hợp với privacy filter: policy quyết định file
nào được nạp, privacy filter làm sạch nội dung trước khi vào memory. Lấy cảm hứng từ
yvgude/lean-ctx, viết lại hoàn toàn nguyên bản.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

