What you will be able to do
- Choose between /compact with a focus, /clear and subagent delegation for a drifting or bloated session
- Predict what survives compaction and what is lost
- Explain what a Claude Code plugin bundles, what it costs in context and trust, which scopes it installs at, and how the Agent SDK loads one
1.Compact, clear or delegate: the session hygiene rule
Long Claude Code sessions get worse in a predictable way. Old conversation pushes out the files you need next, and you pay for it in tokens on every message. Session hygiene means choosing one of three moves at each turning point in the work. [Compaction](lesson:6.1) replaces the conversation with a structured summary. [Context isolation with subagents](lesson:6.1) gives a piece of work its own context window. /clear starts the conversation over.
The choice depends on whether the next piece of work is related to the last. If you are continuing the same task with a bloated context, run /compact with a focus, such as /compact focus on the auth bug fix, before a long new phase. The summary then keeps what you named, instead of what the automatic pass guesses is important. If the next task is unrelated, use /clear. If what comes next is a lot of reading, such as research across a large codebase, send it to a subagent. The file contents stay in the subagent's window, and only a summary and a small metadata trailer come back. If only part of the conversation is noise, /rewind lets you summarize from a chosen message onward, or up to it.
| Move | Use it when | What the session keeps |
|---|---|---|
| /compact focus on … | The same task continues but context is bloated | A structured summary steered by your focus |
| /clear | You are switching to unrelated work | A fresh conversation; nothing from the old one |
| Delegate to a subagent | Large reads or research are next | Only the summary and a small metadata trailer |
| /rewind → Summarize from here / up to here | Only part of the conversation is noise | That part summarized, the rest intact |
Most startup content comes back after compaction, so check which parts do not before you rely on it. The system prompt and output style still apply. Project-root CLAUDE.md, unscoped rules and auto memory are re-injected from disk, as is the plan from plan mode. Path-scoped rules and nested CLAUDE.md files return when Claude next reads a matching file. Claude Code re-reads up to five of the files Claude read or edited, most recently modified first, and invoked skill bodies return within a token cap. Anything else, including a standing instruction you typed into chat an hour ago, survives only if the summary keeps it. If an instruction has to outlast compaction, put it in CLAUDE.md. Resuming an old session raises the same choice. Resume from summary runs /compact immediately, while Resume full session as-is reprocesses the whole history.
Checkpoint 1 of 5· Check yourself
Two hours ago you told Claude in chat, "never touch the migrations folder". The same rule is also in the project-root CLAUDE.md. After /compact, which copy is guaranteed to be back in context?
The project-root CLAUDE.md is re-read from disk after compaction. A chat instruction survives only if the summary happens to keep it.
“Project-root CLAUDE.md and unscoped rules | Re-injected from disk”Source: code.claude.com
Checkpoint 2 of 5· Exam question
A multi-tenant SaaS product runs one Agent SDK session per end-user conversation and must reliably return to a specific user's conversation later, even when it isn't the most recently active session on the server and even after the process restarts. Which session-handling approach fits this requirement?
Correct answer: A — Capture each session's ID from the result message and store it per user, then pass that specific ID to `resume` when the user returns, rather than relying on `continue`
- A. Correct. `resume` takes a specific session ID and is required when there are multiple sessions (for example, one per user) or when returning to a session that isn't the most recent; capturing and storing the ID per user is exactly the documented use case for this option.
- B. Incorrect. `continue` finds only the most recent session in the current directory with no ID tracking; in a multi-tenant server handling many users concurrently, that will resume the wrong user's session whenever another session is more recent.
- C. Incorrect. Fork creates a new, independent session copied from an original at a point in time; it is for branching to explore alternatives, not for repeatedly returning to and continuing a specific user's ongoing session.
- D. Incorrect. The SDK explicitly supports resuming a specific past session by ID; re-sending the full transcript as prompt text is unnecessary and discards the SDK's built-in session persistence and context accumulation.
Applications built on the Agent SDK manage sessions through options rather than a picker. Each result message carries a session_id; capture it per user or per job and pass it as resume to return to exactly that conversation. The continue option instead reopens the most recent conversation. That suits a single-user script, but in a service handling many users the most recent session may belong to someone else, so use resume with a stored ID there. To branch without disturbing the original, set forkSession while resuming: the SDK starts a new session ID and leaves the original session as it was. Setting persistSession to false stops sessions being saved to disk, which means they cannot be resumed later.
Checkpoint 3 of 5· Exam question
An agent has already analyzed a codebase's authentication module in an existing session and produced a JWT-based migration plan. The team now wants to explore an alternative OAuth2-based approach in a separate line of investigation without losing the ability to continue the original JWT-focused thread later. Which approach satisfies both goals?
Correct answer: A — Resume the original session with `fork_session=True` (or `forkSession: true`) and the OAuth2 prompt, which creates a new session with a copy of the original's history while leaving the original session's ID and history unchanged
- A. Correct. Forking with `resume` plus `fork_session: true` creates a new session that starts as a copy of the original's history and diverges from that point, while the original session's ID and history remain untouched, letting the team explore OAuth2 in the fork and still resume the original JWT thread separately.
- B. Incorrect. A plain `resume` call continues and appends to the original session's own history in place; it does not create a separate branch or preserve an untouched copy under a different ID the way fork does.
- C. Incorrect. Manually pasting analysis into a fresh prompt does not give the agent the same accumulated context (file reads, tool results) as a real session history, and it does not preserve a resumable original thread as cleanly as forking does.
- D. Incorrect. `continue` finds and continues the most recent session in the current directory; it does not automatically detect topic changes and branch into a new session, so it would not create the isolated exploration the team wants.
2.What a plugin bundles and what it costs
A Claude Code plugin packages several extensions into one installable unit: commands, agents, skills, hooks, and MCP and LSP servers. Each part affects a session in a different way, so installing a plugin is two decisions at once, one about context and one about trust.
| Component | What it does |
|---|---|
| Hooks | Run as shell commands at lifecycle points, with your full user permissions, outside the sandbox |
| MCP and LSP servers | Claude Code connects to the MCP servers and gives Claude their tools; a stdio server runs as a process Claude Code starts, and Claude Code also starts the declared language servers |
| bin/ directory | Added to the PATH of the Bash tool's shell |
| Skills, commands, agents | Enter Claude's context as instructions |
The context cost starts before you type anything. Skill descriptions and MCP tool names load at the start of every session. For plugins in Anthropic's official marketplace, the install screen shows two estimates: Every turn, what the plugin adds to each message, and When invoked, what its skills and agents add once Claude loads them. Timing also matters. If activating a plugin mid-session would invalidate the prompt cache, /reload-plugins warns you and leaves the plugin pending.
Trust lasts beyond the moment you install. Your permission rules still apply to a call to a plugin's MCP tool or to an executable in its bin/, but hooks run unprompted with your full permissions. If auto-update is on for a marketplace, the files you reviewed can change on disk in the background.
Where a plugin comes from sets how much review it needs. Marketplaces with Anthropic's official names are official, ones with its community names are community, and every other marketplace, including one your coworker or organization publishes, is third-party. Before installing, read the install summary of what the plugin will add. Afterwards, claude plugin uninstall removes it, and --keep-data preserves its data directory under ~/.claude/plugins/data/. In claude -p runs /plugin does not work, but plugins you already installed still load, and you manage them from the shell with claude plugin commands.
Checkpoint 4 of 5· Check yourself
Claude runs an executable from an enabled plugin's bin/ directory through the Bash tool. Which statement is accurate?
Running a plugin's bin/ executable is an ordinary Bash tool call, so permission rules govern it. Hooks are different: they run outside the sandbox with full user permissions.
“a Bash command that runs an executable from the plugin’s bin/, are tool calls, so your permission rules apply to them.”Source: code.claude.com
3.Plugin scopes and the surfaces that load them
The install scope decides who gets the plugin. User scope, the default, enables it in every project on your machine. Project scope enables it for everyone who works in the repository. Local scope enables it for you in this repository only. A scope that takes precedence over the declaring one can override it: claude plugin disable formatter --scope local turns off a project-enabled plugin for you alone. In Claude Code, plugins install from the terminal, the desktop app, VS Code and cloud sessions. claude.ai chat and Cowork handle plugins through their own path.
The Agent SDK has no install step. You list plugin directories in the plugins option, and only type: "local" is supported. Relative paths resolve against the cwd option. Check the init message to confirm what loaded: it lists the plugins, and plugin skills appear with the plugin name as a prefix, such as my-plugin:greet. That prefixed name is also how you invoke them. If your application manages the plugin's MCP connections itself, set skipMcpDiscovery (TypeScript). The SDK then loads the plugin's skills, hooks, agents and commands but skips its MCP servers.
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Hello",
options: {
plugins: [
{ type: "local", path: "./my-plugin" },
{ type: "local", path: "/absolute/path/to/another-plugin" }
]
}
})) {
// Plugin commands, agents, and other features are now available
}Checkpoint 5 of 5· Check yourself
A team lead runs claude plugin install formatter@my-marketplace and wants every collaborator on the repository to get the plugin. Without a scope flag, what happens?
Install defaults to user scope. To enable the plugin for everyone in the repository, pass project scope.
“Installation scope: user, project, or local. Defaults to user”Source: code.claude.com
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.Before switching to unrelated work, run /compact so Claude keeps a compressed memory of the earlier task.Why is that wrong?
Unrelated work calls for /clear. Carrying old conversation forward, even as a summary, crowds out the next task's files and costs tokens on every message.
Covered in Compact, clear or delegate: the session hygiene rule
2.A plugin's hooks and MCP servers run inside Claude Code's sandbox, so installing a plugin is low-risk.Why is that wrong?
Claude Code runs both outside the sandbox, and command hooks run with your full user permissions.
Covered in What a plugin bundles and what it costs
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://code.claude.com/docs/en/context-windowOfficial docs
“Compact with a focus: run /compact with instructions, like /compact focus on the auth bug fix, before starting a long new task.”
↩︎ Compact, clear or delegate: the session hygiene rule“Delegate large reads: send research to a subagent so the file contents stay in its context window, not yours.”
↩︎ Compact, clear or delegate: the session hygiene rule“Only the summary and a small metadata trailer come back.”
↩︎ Compact, clear or delegate: the session hygiene rule“Files Claude read or edited | Claude Code re-reads up to five, most recently modified first”
↩︎ Compact, clear or delegate: the session hygiene rule“Most startup content reloads automatically”
↩︎ Compact, clear or delegate: the session hygiene rule“Old conversation crowds out the files you need next and costs tokens on every message.”
↩︎ Exam trap 1“Clear between tasks: run /clear when switching to unrelated work.”
↩︎ Prediction“Project-root CLAUDE.md and unscoped rules | Re-injected from disk”
↩︎ Checkpoint - 2.https://code.claude.com/docs/en/sessionsOfficial docs
“Resume from summary: runs /compact immediately.”
↩︎ Compact, clear or delegate: the session hygiene rule - 3.https://code.claude.com/docs/en/agent-sdk/typescriptOfficial docs
“When resuming with resume, fork to a new session ID instead of continuing the original session”
↩︎ Compact, clear or delegate: the session hygiene rule“Continue the most recent conversation”
↩︎ Compact, clear or delegate: the session hygiene rule“When false, disables session persistence to disk. Sessions cannot be resumed later”
↩︎ Compact, clear or delegate: the session hygiene rule“Session ID to resume”
↩︎ Compact, clear or delegate: the session hygiene rule“Must be 'local' (only local plugins currently supported)”
↩︎ Plugin scopes and the surfaces that load them - 4.https://code.claude.com/docs/en/agent-sdk/pythonOfficial docs
“ID of the session this message belongs to”
↩︎ Compact, clear or delegate: the session hygiene rule - 5.https://code.claude.com/docs/en/plugins/installOfficial docs
“Will install: the commands, agents, skills, hooks, and MCP and LSP servers the plugin adds.”
↩︎ What a plugin bundles and what it costs“Every turn is what the plugin adds to each message you send”
↩︎ What a plugin bundles and what it costs“Plugins you already installed do load.”
↩︎ What a plugin bundles and what it costs“Install for all collaborators on this repository (project scope): it’s enabled for everyone who works in this repository”
↩︎ Plugin scopes and the surfaces that load them - 6.https://code.claude.com/docs/en/plugins/securityOfficial docs
“command hooks execute shell commands with your full user permissions”
↩︎ What a plugin bundles and what it costs“A stdio MCP server runs as a process that Claude Code starts on your machine.”
↩︎ What a plugin bundles and what it costs“Claude Code runs hooks and MCP servers outside the sandbox.”
↩︎ Exam trap 2“a Bash command that runs an executable from the plugin’s bin/, are tool calls, so your permission rules apply to them.”
↩︎ Checkpoint - 7.https://code.claude.com/docs/en/plugins/overviewOfficial docs
“Third-party: every other marketplace.”
↩︎ What a plugin bundles and what it costs - 8.
“--keep-data | Preserve the plugin’s persistent data directory”
↩︎ What a plugin bundles and what it costs“claude plugin disable formatter --scope local turns off a project-enabled plugin for you alone”
↩︎ Plugin scopes and the surfaces that load them“Installation scope: user, project, or local. Defaults to user”
↩︎ Checkpoint - 9.https://code.claude.com/docs/en/agent-sdk/pluginsOfficial docs
“Relative paths: resolved relative to the cwd option”
↩︎ Plugin scopes and the surfaces that load them