บริบทเก่าและการเริ่มต้นใหม่
เมื่อผลลัพธ์จากเครื่องมือที่เรียกคืนมาเก่าเกินไป ให้สรุปใหม่
บริบทเก่าและการเริ่มต้นใหม่ เป็นบทเรียน Claude Architect ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Claude Architect และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Claude Architect มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Resuming a Session
Claude Code lets you continue work across days. --resume <name> reopens a named session with its full message history intact: the prompts, the model's reasoning, and crucially the tool results that were captured the first time.
That replay is powerful. But it hides a sharp edge: those tool results are a snapshot of the past, not a live view of your system. This lesson is about recognizing when that snapshot has gone stale and what to do instead.
claude --resume refactor-authWhy the History Is Frozen
Remember how the API works: the model keeps no state of its own. Every turn you send the full messages history — including prior tool_result blocks. The model reasons over whatever those blocks say.
A resumed session simply reloads that saved history. If a Read captured a file's contents last Tuesday, the model still believes Tuesday's version today — even if the file changed ten times since.
messages = [
{"role": "user", "content": "Refactor the auth module"},
{"role": "assistant", "content": [tool_use_read_authpy]},
# tool_result below is a FROZEN snapshot from the prior session
{"role": "user", "content": [tool_result_authpy_old]},
]
client.messages.create(model="claude-opus-4-1", max_tokens=2048, messages=messages, tools=tools)What 'Stale Context' Looks Like
Stale context is when the resumed tool results no longer match reality. Common triggers:
- A teammate edited the same files between sessions.
- A migration changed the database schema the model had cached.
- A dependency bump altered an API the model read earlier.
- A build artifact or test output captured earlier is now obsolete.
The danger: the model proceeds confidently on outdated facts, producing edits that conflict with the current codebase.
Resume vs. Fresh Session
You have two recovery levers when a session ages:
--resume <name>continues the named session, replaying its full saved history.fork_sessionbranches from a shared point — useful for exploring an alternative without disturbing the original.
Both inherit the old tool results. When the codebase has drifted substantially, neither is ideal. Sometimes a fresh session seeded with a structured summary beats resuming, because it forces every fact to be re-fetched against current reality.
claude --resume refactor-auth # replays old tool results
claude # fresh session, no stale snapshotsThe Core Decision
Ask one question: has the ground truth changed since the session was captured?
- Little or no drift (you paused for an hour, no one else touched the repo) →
--resumeis fine and cheap. - Significant drift (days passed, merges landed, schema migrated) → start fresh and re-summarize the goal, then let the model re-fetch live tool results.
This is a context-management reliability call — domain D5 on the exam.
Summarize Anew, Don't Replay
"Summarize anew" means: carry forward the intent and decisions, but drop the frozen tool outputs so they get re-acquired. You write a compact, structured summary of where the task stands, then open a clean session with that summary as the opening prompt.
The model then runs Read, Grep, and Bash against the current codebase — no stale snapshot to mislead it.
summary = """
GOAL: Finish refactoring auth to use the new TokenService.
DONE: Extracted TokenService; updated login() and logout().
TODO: Migrate refresh() and the 3 middleware call sites.
NOTE: schema migrated since last session — re-read current files before editing.
"""
messages = [{"role": "user", "content": summary + "\nRe-read the current files, then continue."}]Keep Hard Facts Verbatim
Progressive summarization is lossy: it makes numbers, percentages, and dates vague. When your summary must preserve exact values — a version pin, a row count, a deadline, an order ID — don't fold them into prose.
Pull them into a separate "case facts" block kept verbatim, outside the narrative summary. The summary can compress the story; the facts block stays exact.
case_facts = {
"target_version": "TokenService 2.4.0",
"affected_call_sites": 3,
"migration_applied": "2026-06-09",
}
prompt = SUMMARY_PROSE + "\n\nCASE FACTS (verbatim, do not paraphrase):\n" + str(case_facts)Re-Fetch Before You Edit
In a fresh session the discipline is simple: investigate before mutating. Use the incremental pattern — Grep entry points, Read the files, Grep usages, Read consumers — so every edit is grounded in current contents.
This is also why Edit uses a unique-match contract: if the file drifted and your expected text no longer matches uniquely, the edit fails loudly rather than corrupting the file. Re-Read and retry.
# Fresh-session re-grounding before any change
# 1) Grep for the symbol
# 2) Read the current file
# 3) Edit with a unique match (fails loudly if the file drifted)Don't Confuse This with /compact
/compact compresses the current conversation to free context space. It is useful, but it carries the same lossiness risk: numbers and dates can become vague. It does not solve staleness — the compacted facts are still from the original captures.
Starting fresh is different: you discard the old tool results entirely and re-derive them live. Use /compact for a long but still-accurate session; start fresh when the underlying system has moved on.
Subagents Never Inherit History
This staleness lesson rhymes with multi-agent design. Subagents do not inherit the coordinator's conversation history — all context must be passed explicitly in each subagent prompt.
The same hygiene helps you: when you hand a fresh session (or a subagent) a structured summary plus a verbatim facts block, you are doing deliberately what resume does accidentally — except you control exactly which facts survive and you force live re-fetching of the rest.
# Coordinator passes explicit, current context to each subagent
subagent_prompt = (
"You are refactoring auth. Context summary:\n" + summary +
"\nCASE FACTS:\n" + str(case_facts) +
"\nRe-read the current files yourself; do not assume prior state."
)A Practical Checklist
Before resuming a stale session, run this gate:
- Drift? Did the repo/schema/deps change since capture? If yes → lean fresh.
- Summarize goal, decisions made, and remaining TODOs.
- Preserve exact numbers/dates/IDs in a verbatim facts block.
- Re-fetch live: Grep → Read before any Edit.
- Verify against current state, not the remembered one.
Cheap to resume when nothing moved; cheap insurance to start fresh when it did.
Quick Check
Test your judgment on the resume-vs-fresh decision.
Recap
Key takeaways:
- Resumed sessions replay frozen tool results because the model holds no state and reasons over the full saved history.
- When the system has drifted (merges, migrations, dependency bumps), those results are stale and can drive confident-but-wrong edits.
- When drift is significant, start fresh and summarize anew rather than
--resumeorfork_session, which both inherit the old snapshots. - Keep exact numbers, dates, and IDs in a verbatim case-facts block; summarization makes those vague.
- Re-fetch live (Grep → Read) before any Edit;
/compactsaves space but does not cure staleness.
คำถามที่พบบ่อย
บทเรียน “บริบทเก่าและการเริ่มต้นใหม่” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “บริบทเก่าและการเริ่มต้นใหม่” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Claude Architect ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Claude Architect มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “บริบทเก่าและการเริ่มต้นใหม่”
เมื่อผลลัพธ์จากเครื่องมือที่เรียกคืนมาเก่าเกินไป ให้สรุปใหม่ คุณปฏิบัติ Claude Architect ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Claude Architect หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Claude Architect บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “บริบทเก่าและการเริ่มต้นใหม่” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Claude Architect นี้ได้ไหม
ได้ บทเรียน Claude Architect ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- กระบวนการทำงานแบบตายตัวเทียบกับการแยกย่อยแบบปรับตัว
- การแยกย่อยหลายรอบ
- การจัดการเซสชัน
- บริบทเก่าและการเริ่มต้นใหม่