You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: agents/claude-code/rules/context-server-integration.md
+15-19Lines changed: 15 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,9 @@
4
4
5
5
When MCP Context Server tools are available (any `mcp__context-server__*` tool in your tools list), you MUST follow this rule. If no context-server tools are present, this rule is inactive.
6
6
7
-
## Mandatory Skill Delegation
7
+
## Core Operating Principles
8
8
9
-
For ALL context-server operations (retrieval, search, storage, metadata, update/revision, scoped retrieval, references navigation, continuity, pre-compaction patterns), you MUST follow these skills as the authoritative source of truth:
10
-
11
-
-**Retrieval:**`context-retrieval-protocol` skill -- thread ID acquisition, project name derivation, retrieval sequences, hybrid/semantic/FTS search, scoped retrieval (`context_scope`), references navigation, revision context detection, worktree-aware queries, and continuity patterns.
12
-
-**Preservation:**`context-preservation-protocol` skill -- storage patterns, metadata schema (including the "task subject vs execution tools" distinction for the `technologies` field), `store_context` vs `update_context` strategy, handoff reports, and continuity patterns.
13
-
14
-
If these skills are already loaded in your context (via your agent frontmatter `skills:` field or a slash-command invocation), treat them as active. If not, invoke them explicitly via the Skill tool before performing any context-server operation. **Rule vs skill precedence:** if this rule appears to contradict a skill, the SKILL WINS.
9
+
For ALL context-server operations (retrieval, search, storage, metadata, update/revision, scoped retrieval, references navigation, continuity, pre-compaction patterns), apply these principles directly. Where your environment provides skills, tutorials, or other operational guidance, treat that guidance as the practical embodiment of these principles; this rule supplies the invariants those guides must respect.
15
10
16
11
## Environment-Specific Facts
17
12
@@ -20,35 +15,36 @@ If these skills are already loaded in your context (via your agent frontmatter `
20
15
21
16
## User Message Authority
22
17
23
-
User messages are the authoritative source of truth and override orchestrator summaries, agent reports, and your own memory when conflicts arise. User messages are IMMUTABLE -- never update, rewrite, or delete them, even when they contain errors. For discrepancy-handling details, see the retrieval skill's orchestrator-verification section.
18
+
User messages are the authoritative source of truth and override orchestrator summaries, agent reports, and your own memory when conflicts arise. User messages are IMMUTABLE -- never update, rewrite, or delete them, even when they contain errors. When you detect a discrepancy between an orchestrator's task and the user's stated requirements (retrieved verbatim from the context server), the user-message wording wins; the orchestrator's framing is corrected, not the user's words.
24
19
25
-
## User Message Relay Protocol (ID-First)
20
+
## User Message Relay Protocol
26
21
27
-
When launching subagents (via the Task or Agent tool) whose work depends on the user request, you MUST relay the user message using one of two modes, chosen by a deterministic predicate on `context_id` availability. Message SIZE is IRRELEVANT to mode selection.
22
+
When launching subagents (via the Task or Agent tool) whose work depends on the user request, you MUST pass the user message in one of two modes:
28
23
29
-
-**Default Mode -- REFERENCE (context_id only):**This is the ALWAYS-PREFERRED mode regardless of message size. Use it whenever the UserPromptSubmit hook has emitted a `context_id` for the current user message. The Reference Block contains EXACTLY this one line and nothing else (no retrieval instructions, no CRITICAL reminders, no size annotations, no format descriptors):
24
+
-**Mode 1 -- INLINE (default):**For moderate messages (guidance: under approximately 2000 tokens / 40 lines), include the full verbatim text under a `USER REQUEST:` marker:
30
25
31
26
```text
32
-
USER REQUEST CONTEXT ID: [context_id from hook]
27
+
USER REQUEST: [verbatim user message]
33
28
```
34
29
35
-
-**Fallback Mode -- INLINE (verbatim text):** Use ONLY when the `context_id` is unavailable -- the UserPromptSubmit hook did not emit one (hook failure or upstream error), or the context-server is unreachable at message-store time. Include the full verbatim text under a `USER REQUEST:` marker:
30
+
-**Mode 2 -- REFERENCE (large messages):** Use a reference block with explicit retrieval instructions, passing the `context_id` emitted by the hook:
36
31
37
32
```text
38
-
USER REQUEST: [verbatim user message text]
33
+
USER REQUEST (large message -- retrieve from context-server):
34
+
Context ID: [context_id from hook additionalContext]
35
+
Retrieve the FULL user message using: get_context_by_ids([<context_id>])
36
+
CRITICAL: You MUST retrieve and read the COMPLETE user message before starting work.
39
37
```
40
38
41
-
**Prohibitions (both modes):** MUST NOT summarize, paraphrase, condense, compress, or select "relevant" portions; MUST NOT extract quotes, evidence, or excerpts; MUST NOT describe intent or problem in your own words; MUST NOT add domain, technology, or problem qualifiers. Relay the complete message (REFERENCE) or its complete verbatim text (INLINE). When a subagent receives a Reference Block, it resolves the pointer per the retrieval skill's Pattern 6 (User Request Resolution) before starting work.
42
-
43
-
**Image Path Relay (extension to BOTH modes):** Images attached via the terminal are NOT stored in the context-server; subagents can only analyze them by reading the absolute paths directly with the `Read` tool. Whenever the task involves visual analysis, the orchestrator MUST forward image paths verbatim: in Fallback (INLINE) mode the paths flow naturally with the verbatim text; in Default (REFERENCE) mode the orchestrator MUST append an explicit `IMAGE PATHS` block after the Reference Block, because image paths cannot be retrieved from the context-server. The orchestrator MUST NOT summarize, describe, interpret, or redact image contents or paths.
39
+
**Prohibitions (both modes):** MUST NOT summarize, paraphrase, condense, compress, or select "relevant" portions; MUST NOT extract quotes, evidence, or excerpts; MUST NOT describe intent or problem in your own words; MUST NOT add domain, technology, or problem qualifiers. Pass the complete message. **Fallback:** if the context server is unavailable, use Mode 1 INLINE regardless of size. When a subagent receives a Mode 2 reference block, it MUST resolve the pointer FIRST -- retrieve the full verbatim user message via `get_context_by_ids([<context_id>])`, read it in full, and only then begin work. Acting on the reference pointer without retrieving the underlying message is a PROTOCOL VIOLATION.
44
40
45
41
## Subagent Context Requirements
46
42
47
43
When launching subagents via the Task or Agent tool, the task description MUST include:
48
44
49
45
1.**Thread ID** -- enforced by a PreToolUse blocker
50
46
2.**Timezone / date context** -- enforced by a PreToolUse blocker
51
-
3.**User original request** -- per the Relay Protocol above (Default REFERENCE pointer, or INLINE fallback when no `context_id`)
47
+
3.**User original request** -- per the Relay Protocol above (Mode 1 or Mode 2)
52
48
4.**Relevant context IDs** -- so the subagent can retrieve prior work via `get_context_by_ids`
53
49
54
50
Items 1 and 2 are hook-enforced: if missing, the tool call is blocked with guidance via stderr -- revise the task description and retry. Items 3 and 4 are your responsibility.
@@ -62,4 +58,4 @@ Before context compaction, preserve (priority-ordered):
62
58
-**Current task state** -- what is active and what remains
63
59
-**User decisions** -- explicit choices made during this session
64
60
65
-
Do NOT attempt to preserve full content already stored in the context server -- use context IDs for retrieval after compaction. For detailed continuity patterns, follow the continuity sections of both skills.
61
+
Do NOT attempt to preserve full content already stored in the context server -- use context IDs for retrieval after compaction. After any context window reset or compaction event, re-retrieve the highest-priority items above via `get_context_by_ids` before continuing work.
0 commit comments