0Pricing
Claude Architect · 课时

会话管理

使用 --resume 恢复命名会话,并使用 fork_session 创建分支。

会话管理 是 CoddyKit 上的免费 Claude Architect 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Claude Architect 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Claude Architect 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Why Session Management Matters

The Claude API keeps no server-side state — every request sends the FULL message history. So "a session" is really a saved conversation transcript you can persist, reopen, and branch.

In Claude Code, session tooling lets you resume a named line of work later and fork a shared starting point into parallel explorations. Mastering this is core to D5 (Context Management) and D3 (Claude Code Workflows) on the architect exam.

Resume vs Fork at a Glance

Two primitives solve two different problems:

  • --resume <name> — continue a single, named session linearly. Same thread, picked up where you left off.
  • fork_session — branch from a shared point into multiple independent lines that don't interfere with each other.

Resume = one timeline continued. Fork = one timeline split into parallel timelines.

Resuming a Named Session

Use --resume <name> to reopen the exact conversation you left, with its full accumulated context. This is ideal for multi-day work on a single task: a long refactor, an incremental investigation, or a feature you're building across sessions.

The name is your handle — give sessions meaningful names so you can find them later.

# Continue a named, persisted session
claude --resume payment-refactor

# Pick up an investigation from yesterday
claude --resume auth-bug-triage

Forking from a Shared Point

fork_session branches from a common starting state — for example, after you've loaded the codebase context and agreed on an approach. Each fork explores a different option without polluting the others' history.

This is the session-level analogue of "try three solutions in parallel": shared setup, independent outcomes.

# Establish shared context, then branch
claude --resume api-redesign

# Fork two independent approaches from that point
claude --fork-session api-redesign --name approach-rest
claude --fork-session api-redesign --name approach-graphql

When to Resume

Reach for --resume when the work is genuinely continuous and the prior context still holds:

  • A linear task spanning multiple work sessions.
  • Incremental investigation where earlier findings remain valid.
  • You want the full reasoning trail intact, not summarized.

Resuming preserves nuance that a summary would flatten — but only if that context is still accurate.

The Stale Context Trap

Here's the architect-grade caveat: resumed tool results can be STALE if the codebase changed. If files moved, tests were rewritten, or a dependency was upgraded since you last ran, the old Read and Grep outputs in history now describe a world that no longer exists.

Claude will reason over outdated facts unless you correct them. Resume is not free — it carries whatever was true at capture time.

Fresh Session + Structured Summary

When context has drifted, a fresh session seeded with a structured summary is often better than resuming. You discard stale tool output and re-ground the model on current reality.

Keep transactional facts — file paths, decisions, open questions — verbatim in a "case facts" block so progressive summarization doesn't make them vague.

# Fresh session, hand it a curated summary instead of stale history
claude --name payment-refactor-v2

# Paste a structured brief:
# DECISIONS: use Stripe PaymentIntents; keep idempotency keys
# DONE: extracted billing/ module; tests green
# OPEN: webhook retry policy undecided
# NOTE: re-read files — repo changed since last session

Fork for Parallel Exploration

Forking shines when you want to compare alternatives fairly. Branch from identical context so the only variable is the approach itself, then evaluate the outcomes side by side.

  • Two refactor strategies from the same baseline.
  • Different prompt phrasings tested against the same loaded context.
  • A risky experiment isolated from your main line.

Because forks don't share ongoing history, one branch's mistakes never contaminate another.

Sessions and Decomposition

Session strategy mirrors task decomposition. For known sequential steps, a single resumed session acts like a fixed pipeline carrying state forward. For open-ended investigation with multiple viable directions, forking supports adaptive exploration.

Don't force a branch where a line suffices — and don't cram divergent experiments into one ever-growing linear session.

Sessions Are Not Subagents

Don't confuse sessions with multi-agent context. Forking branches your own conversation. By contrast, subagents do NOT inherit the coordinator's history — each subagent must be handed its context explicitly in its prompt.

Use sessions to manage your continuity across time; use the hub-and-spoke coordinator pattern to fan work out to fresh agents. They solve different problems.

A Practical Workflow

Putting it together for a multi-day feature:

  • Start named, do the shared setup (load context, agree on plan).
  • Fork when you need to trial competing approaches.
  • --resume the winner across days as you build it out.
  • When the repo shifts under you, abandon the stale session and re-seed a fresh one with a verbatim case-facts summary.

Continuity by default, branch when exploring, refresh when reality moves.

# Day 1: set up + branch
claude --name search-feature
claude --fork-session search-feature --name try-elastic
claude --fork-session search-feature --name try-postgres-fts

# Day 3: continue the chosen path
claude --resume search-feature

# Day 5: repo changed a lot -> fresh + summary
claude --name search-feature-v2

Quick Check

Apply the stale-context principle to a real decision.

Recap: Resume, Fork, Refresh

Key takeaways:

  • --resume <name> continues one named session linearly — great for continuous, multi-session work.
  • fork_session branches from a shared point into independent parallel lines that don't interfere.
  • Resumed tool results can be stale if the code changed — sometimes a fresh session with a structured summary is the better call.
  • Keep transactional facts verbatim outside summaries; sessions manage YOUR continuity, while subagents need context passed explicitly.

Continuity by default, branch to explore, refresh when reality moves.

常见问题解答

「会话管理」课时是免费的吗?

是的 — 「会话管理」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Claude Architect 课程的其余内容,请升级到 CoddyKit PRO。 Claude Architect 课程共包含 4 节课。

「会话管理」这节课中我会学到什么?

使用 --resume 恢复命名会话,并使用 fork_session 创建分支。 你通过在浏览器中直接运行的动手代码来练习 Claude Architect,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Claude Architect 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Claude Architect 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「会话管理」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Claude Architect 课中编写并运行代码吗?

能。每节 Claude Architect 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 固定流程与自适应分解
  2. 多轮分解
  3. 会话管理
  4. 过时的上下文与重新开始
← 返回 Claude Architect