/agentsop-session-state-hygiene
Decision protocol for managing the context/session state of an AI coding tool: when to /clear, when to keep context, and how to detect "context bleed" — the failure mode where stale conversation history biases the model against the current task. Surfaces a discipline that Aider
$ npx -y skills add agentsope/SkillAlchemy --skill agentsop-session-state-hygiene --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/agentsop-session-state-hygiene
Context preview
The summary Claude sees to decide when to auto-load this skill.
Decision protocol for managing the context/session state of an AI coding tool: when to /clear, when to keep context, and how to detect "context bleed" — the failure mode where stale conversation history biases the model against the current task. Surfaces a discipline that Aider
SKILL.md
agentsop-session-state-hygiene.SKILL.mdname: agentsop-session-state-hygiene
version: 0.1.0
description: |
Decision protocol for managing the context/session state of an AI coding tool:
when to /clear, when to keep context, and how to detect "context bleed" — the
failure mode where stale conversation history biases the model against the
current task. Surfaces a discipline that Aider (/clear), Claude Code (/clear),
CrewAI (memory=False, re-instantiate), and LangGraph (new thread_id, subgraph
isolation) all encode separately but none name as a skill.
phase: D
tier: common
frequency: daily
audience: coder-agents and human engineers who run multi-turn LLM coding sessions
source: aider-sop, crewai-sop, langgraph-sop (local) + vendor docs
Session-State Hygiene · SOP
> One line: **context is signal; stale context is noise; clearing restores > signal.** A coding session is a sliding window of evidence. Early in a task > the window is pure signal. The longer it runs, the more dead ends, abandoned > plans, and superseded files accumulate — and at some point yesterday's good > context becomes today's bad bias. This skill is the discipline of noticing > that moment and acting on it with the smallest correct cut.
> Source posture: every framework-specific claim is cited inline as > `[tool/topic]`. Resolve tags against `references/R1-source-evidence.md` (full > URLs) and `references/R2-tool-commands.md` (copy-pastable commands).
---
1. 何时激活 (When to Activate)
Activate this skill the moment **any** of these fire — they are the symptoms of context bleed, not vague unease:
- **Topic shift inside a session.** You finish feature A and start unrelated
bug B in the same window/REPL/thread. The A-history is now pure noise for B.
- **Length / window warning.** The tool reports the context window is N% full,
or Aider's `/tokens` crosses **~25k** — the empirically observed point where "most models start to become distracted and become less likely to conform to their system prompt" `[aider/edit-errors]`.
- **Weird behavior** — the tell-tale signs of bleed:
- The model **repeats a mistake** you already corrected ("don't use
`requests`" → it uses `requests` again).
- It **references a file or decision you already removed / dropped**.
- It **obeys an older instruction over the newest one** (it conforms to turn
3 but ignores turn 30).
- Edit-format errors climb (Aider "SEARCH block not found" recurs)
`[aider/edit-errors]`.
> **The activation trap to avoid:** when behavior gets weird, the reflex is to > rephrase the prompt, retry, or swap the model. If the *history* is polluted, > none of those help — you are arguing with a model that is reading stale > evidence. Activate this skill **before** reaching for a prompt rewrite.
Do **not** activate for: a single LLM call, a one-shot RAG query, or a brand new session with <25k tokens that is behaving correctly. Hygiene on a clean window is just superstition — see §6.
---
2. 核心心智模型 (Core Mental Model)
**Context is signal; stale context is noise; clearing restores signal.**
Three load-bearing ideas ride this axiom:
2.1 The session window is evidence, and evidence decays
Every turn you add to a session is evidence the model reasons over. Good evidence (the current goal, the relevant files, the last working diff) raises signal. Stale evidence (a failed approach you abandoned, a 5k-token search dump you no longer need, a file you dropped) raises noise. The signal-to-noise ratio of the window — not its absolute size — is what governs output quality. A 10k window of pure noise is worse than a 30k window of pure signal.
2.2 There is a measured distraction threshold
Aider's tooling is built around a hard, published number: above **~25k tokens** "most models start to become distracted" `[aider/edit-errors]`. No other framework publishes a number, but the heuristic transfers: treat ~25k as the point where you should be *actively* shedding context, not passively letting it grow. This is why `/tokens` exists and why it is the first move in Aider's edit-error remediation, *before* swapping model or edit format `[aider/edit-errors]`.
2.3 Clearing is a cut, and cuts have a size
"Clear the context" is not one operation — it is a family ordered by blast radius. The skill is choosing the *smallest* cut that removes the noise:
smallest cut largest cut
┌───────────────┬────────────────┬───────────────┬──────────────────┐
│ drop one item │ trim history │ clear history │ fresh session / │
│ (a file, a │ (keep last N │ (keep files, │ new thread_id │
│ message) │ messages) │ drop history) │ (zero carry-over)│
└───────────────┴────────────────┴───────────────┴──────────────────┘
OP-004 partial OP-004 partial OP-002 save+clear OP-003 freshReaching for "fresh session" when a single `/drop` would do is as wrong as never clearing at all. Match the cut to the noise.
2.4 The window is not the only state
A subtle trap: "session state" is broader than the visible transcript. CrewAI's `memory=True` keeps a **separate persistent store** (LanceDB by default) that a `Crew()` re-instantiation does **not** wipe `[crewai/memory]`. LangGraph's state lives in a **checkpointer** keyed by `thread_id` — a new `thread_id` is clean, but reusing the old one resumes from the last checkpoint `[langgraph/persistence]`. "I cleared the chat but it still remembers" almost always means a persistent store you didn't clear (§6, AP-005).
---
3. SOP 工作流 (Standard Operating Procedure)
The flow is four steps: **recognize → save what's worth → clear → restart focused.** Walk it top-down; each step has a gate.
Step 1 — Recognize (don't act yet)
Gate: *name the symptom in one line* before touching anything. "The model is still using the JWT approach we abandoned." "Token count is 38k and edits are failing." Naming forces you to identify the **single offending source**
Read more
name: agentsop-session-state-hygiene version: 0.1.0 description: | Decision protocol for managing the context/session state of an AI coding tool: when to /clear, when to keep context, and how to detect "context bleed" — the failure mode where stale conversation history biases the model against the current task. Surfaces a discipline that Aider (/clear), Claude Code (/clear), CrewAI (memory=False, re-instantiate), and LangGraph (new thread_id, subgraph isolation) all encode separately but none name as a skill. phase: D tier: common frequency: daily audience: coder-agents and human engineers who run multi-turn LLM coding sessions source: aider-sop, crewai-sop, langgraph-sop (local) + vendor docs
Session-State Hygiene · SOP
> One line: **context is signal; stale context is noise; clearing restores > signal.** A coding session is a sliding window of evidence. Early in a task > the window is pure signal. The longer it runs, the more dead ends, abandoned > plans, and superseded files accumulate — and at some point yesterday's good > context becomes today's bad bias. This skill is the discipline of noticing > that moment and acting on it with the smallest correct cut.
> Source posture: every framework-specific claim is cited inline as > `[tool/topic]`. Resolve tags against `references/R1-source-evidence.md` (full > URLs) and `references/R2-tool-commands.md` (copy-pastable commands).
---
1. 何时激活 (When to Activate)
Activate this skill the moment **any** of these fire — they are the symptoms of context bleed, not vague unease:
- **Topic shift inside a session.** You finish feature A and start unrelated
bug B in the same window/REPL/thread. The A-history is now pure noise for B.
- **Length / window warning.** The tool reports the context window is N% full,
or Aider's `/tokens` crosses **~25k** — the empirically observed point where "most models start to become distracted and become less likely to conform to their system prompt" `[aider/edit-errors]`.
- **Weird behavior** — the tell-tale signs of bleed:
- The model **repeats a mistake** you already corrected ("don't use
`requests`" → it uses `requests` again).
- It **references a file or decision you already removed / dropped**.
- It **obeys an older instruction over the newest one** (it conforms to turn
3 but ignores turn 30).
- Edit-format errors climb (Aider "SEARCH block not found" recurs)
`[aider/edit-errors]`.
> **The activation trap to avoid:** when behavior gets weird, the reflex is to > rephrase the prompt, retry, or swap the model. If the *history* is polluted, > none of those help — you are arguing with a model that is reading stale > evidence. Activate this skill **before** reaching for a prompt rewrite.
Do **not** activate for: a single LLM call, a one-shot RAG query, or a brand new session with <25k tokens that is behaving correctly. Hygiene on a clean window is just superstition — see §6.
---
2. 核心心智模型 (Core Mental Model)
**Context is signal; stale context is noise; clearing restores signal.**
Three load-bearing ideas ride this axiom:
2.1 The session window is evidence, and evidence decays
Every turn you add to a session is evidence the model reasons over. Good evidence (the current goal, the relevant files, the last working diff) raises signal. Stale evidence (a failed approach you abandoned, a 5k-token search dump you no longer need, a file you dropped) raises noise. The signal-to-noise ratio of the window — not its absolute size — is what governs output quality. A 10k window of pure noise is worse than a 30k window of pure signal.
2.2 There is a measured distraction threshold
Aider's tooling is built around a hard, published number: above **~25k tokens** "most models start to become distracted" `[aider/edit-errors]`. No other framework publishes a number, but the heuristic transfers: treat ~25k as the point where you should be *actively* shedding context, not passively letting it grow. This is why `/tokens` exists and why it is the first move in Aider's edit-error remediation, *before* swapping model or edit format `[aider/edit-errors]`.
2.3 Clearing is a cut, and cuts have a size
"Clear the context" is not one operation — it is a family ordered by blast radius. The skill is choosing the *smallest* cut that removes the noise:
smallest cut largest cut
┌───────────────┬────────────────┬───────────────┬──────────────────┐
│ drop one item │ trim history │ clear history │ fresh session / │
│ (a file, a │ (keep last N │ (keep files, │ new thread_id │
│ message) │ messages) │ drop history) │ (zero carry-over)│
└───────────────┴────────────────┴───────────────┴──────────────────┘
OP-004 partial OP-004 partial OP-002 save+clear OP-003 freshReaching for "fresh session" when a single `/drop` would do is as wrong as never clearing at all. Match the cut to the noise.
2.4 The window is not the only state
A subtle trap: "session state" is broader than the visible transcript. CrewAI's `memory=True` keeps a **separate persistent store** (LanceDB by default) that a `Crew()` re-instantiation does **not** wipe `[crewai/memory]`. LangGraph's state lives in a **checkpointer** keyed by `thread_id` — a new `thread_id` is clean, but reusing the old one resumes from the last checkpoint `[langgraph/persistence]`. "I cleared the chat but it still remembers" almost always means a persistent store you didn't clear (§6, AP-005).
---
3. SOP 工作流 (Standard Operating Procedure)
The flow is four steps: **recognize → save what's worth → clear → restart focused.** Walk it top-down; each step has a gate.
Step 1 — Recognize (don't act yet)
Gate: *name the symptom in one line* before touching anything. "The model is still using the JWT approach we abandoned." "Token count is 38k and edits are failing." Naming forces you to identify the **single offending source**
Other skills on skillalchemy.
- /LEAP
LEAP — 落地执行引擎。内含两条管线:A 分支蒸馏(从 raw data 提取 skill)、 B 分支融合(多 skill 编织为一个)。被 SkillAlchemy 编排器调用。 Use when 编排器判断需要蒸馏或融合时。
Open skill - /Lens
Lens — 给你的问题加一层认知镜片。输入任意任务描述,输出增强版 description, 发现「你不知道自己不知道」的隐性维度、前置条件和认知路线。 Use when 用户说「帮我想想」「分析一下」「生成 skill」「蒸馏」「融合」 或输入看起来太简单需要展开。
Open skill - /agentsop-agent-topology-selection
Cross-framework enhancement overlay for choosing a multi-agent topology BEFORE writing any agent. A binary-question rubric — is single-agent + tools enough? do agents need to know about each other? does the output need one voice? — maps the answer to single-agent / supervisor /
Open skill - /agentsop-aider
SOP for terminal-based, git-native AI pair programming with Aider (git work-tree + tree-sitter repo-map + edit-format + human-in-loop REPL). Use when editing code in an existing git repo via an LLM, when you need to converge a change to 2-5 files, pick an edit format that fits
Open skill - /agentsop-bio-fraud-forensics
Screens biomedical / life-science papers for signs of data fabrication, image manipulation, and statistical anomalies, using the detection techniques distilled from the field's canonical exposure platforms (PubPeer, Data Colada, Science Integrity Digest, For Better Science) and
Open skill - /agentsop-bounded-loop
Universal discipline for any LM-driven loop — agent retries, plan-act-observe, multi-agent handoffs, optimiser passes, test-fix cycles. Encodes the one rule every framework documents quietly and every team relearns expensively: the LM in the loop is NEVER a reliable terminator.
Open skill

