Claude Code

Session 2 - Prompt to Command + Session Save

202604 | PM | 30 min

S1 Recap

CLAUDE.md 之於 脈絡  |  /指令 之於 效率  |  /clear 之於 精力

CLAUDE.md:兩層脈絡

Global   ~/.claude/CLAUDE.md

個人偏好,跨專案通用

## 偏好
- 繁體中文
- 回覆不超過 300 字
- 整理類用表格

## 工具
- 常用 /kickoff /session
- push 前先跑 test

Local   <repo>/CLAUDE.md

這個 repo 的專屬脈絡

## 專案結構
- src/ 投影片原始碼
- theme/ 設計 tokens
- site/ build 產出(勿編輯)

## 慣例
- commit 用 conventional 格式
- 部署走 --public build

啟動時合併讀取。Local 可覆寫 Global。複雜專案的 repo 各自有 CLAUDE.md → 每個子系統的脈絡留在原地。

CC 快捷鍵

快捷鍵 / 指令作用
Esc Esc撤銷,還原 Claude 的修改
Shift+Tab切換權限模式(default → plan → auto)
Tab接受建議的下一步
Ctrl+R搜尋歷史對話
/btw側邊問題,不影響主對話
! + 指令直接跑 terminal 指令
/context顯示當前 context 使用量(tokens / %)與分類明細
Ctrl+G開外部文字編輯器寫長 prompt

Meta-Prompting

Anthropic Prompt Generator  |  OpenAI Prompt Optimizer

Read @.claude/commands/kickoff.md,

rewrite it as a structured AGI instruction.

Preserve the original question-collection flow.

請 CC 打開顯示 kickoff.md 看結果。

Claude 失憶

Context window 會滿  |  換一台 Mac 就斷線  |  /clear 之後回不去

需要一個 結構化存放對話脈絡 的方法。

YD 客製化指令 /session

指令作用
/session save [topic]把當前對話寫成結構化 markdown
/session list列出所有 session,按時間排
/session resume [topic|#]讀檔,回到中斷點
/session close [topic|#]工作完成,刪檔

每個 topic 一個檔,覆寫不累積。
close = 直接刪檔,重要內容先 /kb 入庫再收。

檔案長這樣

kb/session/
├── ch-monday-sync.md
├── openclaw-training-v3.md
└── s2-live-demo-session.md

每個 .md 包含:
  ├── frontmatter
  ├── Goal
  ├── Key Files
  ├── Progress
  ├── Findings
  ├── Handoff (stopped/next)
  └── Notes

Live Demo:完整週期

# 1. 把本堂課的對話存下來
/session save s2-live-demo
→ 寫出 kb/session/s2-live-demo-session.md

# 2. 確認有存到
/session list
→ 最上面那一行就是

# 3. 模擬中斷:開新 Claude Code chat
(Cmd+N)

# 4. 恢復
/session resume s2-live-demo
→ Claude 讀檔 + 報 handoff

# 5. 證明 context 真的回來了
繼續剛剛的 P9 內容

# 6. 工作中有新進展 → 覆寫
/session save
→ 更新 last_saved + progress

# 7. 完成了 → 收尾
/session close s2-live-demo
→ 檔案刪除

把 /session 帶回家

Skill 格式.claude/skills/)屬於輕量版的 Skill,還未接入外部 API、MCP |  建立 ~/.claude/skills/session/SKILL.md,貼下面整段

---
name: session
description: "Save and restore working context across devices and conversations."
status: active
---

# /session: Cross-Session Context Bridge

Save working context so a future Claude Code conversation can resume seamlessly.

## Sub-commands

| Command | Action |
|---------|--------|
| `/session save [topic]` | Capture current context → write to `kb/session/` |
| `/session list` | Show all sessions with last-saved time |
| `/session resume [topic|#]` | Load a session |
| `/session close [topic|#]` | Delete session file |

## Procedure

### save
1. Determine topic from argument or infer. Ask if ambiguous.
2. Run `date '+%Y-%m-%d %H:%M'` and use as last_saved. Never guess time.
3. Extract: handoff (next + stopped at), goal, key files, progress, findings.
4. Write to `kb/session/{topic}-session.md` using template.
5. Print path + one-line summary.

### resume
1. Read `kb/session/{topic}-session.md`.
2. Skim each key file to verify it still exists.
3. Report (conclusion-first): Next → Stopped at → Resuming meta.
4. Continue from handoff.

### list
List `kb/session/*.md`, read frontmatter, sort desc, print with # column.

### close
Delete `kb/session/{topic}-session.md`.

## Session File Template

```markdown
---
tags: [session]
project: {name}
last_saved: {YYYY-MM-DD HH:MM}
---

# {Topic}: Session Context

## Handoff (Next / Stopped at)   ← conclusion first
## Goal | ## Key Files | ## Progress
## Findings | ## Notes for Next Session
```

Conclusion First, Reasoning After

一條 rule(.claude/rules/interaction-style.md

先給判斷,再給推理。有立場時不要把選項平鋪。寫一次規則,每次對話都這樣行動。

/session resume 就是這條 rule 在運作

# /session resume s2-live-demo 的回報
Next: 部署到 ccc.y6huan9.site
Stopped at: P10 改完 build 完
Resuming: s2-live-demo · 2026-04-15 14:30

(完整 Goal / Findings / Notes 在檔案裡,要看時再看)

判斷放最前 → 接續工作 5 秒進入狀態  |  細節在檔案 → 要的時候才展開

Key Takeaway

Session 的生命週期管理

課後

未來目標:session/ 放進 iCloud 同步的 Obsidian vault,跨裝置備份 + 閱讀

參考