Generate a copy-paste cheat sheet from the current session — commands used, traps hit, shortcuts discovered. Style: icon sections, code blocks, quick-ref tables, trap warnings. Use when user says 'cheatsheet', 'cheat sheet', 'สูตรโกง', 'รวมคำสั่ง', 'command reference', or wants a reusable command summary from what just happened.
env/config section — รวม env vars + config ที่ต้องตั้งไว้ที่เดียว
ปิดด้วย 🤖 signature ตาม Rule 6
Procedure
1. Mine session for commands
ORACLE_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
ENCODED_PWD=$(echo "$ORACLE_ROOT" | sed 's|^/|-|; s|[/.]|-|g')
PROJECT_DIR="$HOME/.claude/projects/${ENCODED_PWD}"
LATEST_JSONL=$(ls -t "$PROJECT_DIR"/*.jsonl 2>/dev/null | head -1)
Spawn a Haiku subagent (model: "haiku") with the session JSONL:
python3 - <<'PYEOF'
import json, os
jsonl = os.environ.get('LATEST_JSONL', '')
if not jsonl or not os.path.exists(jsonl): exit(0)
cmds = set()
with open(jsonl) as f:
for line in f:
try:
m = json.loads(line)
if m.get('type') != 'assistant': continue
for block in (m.get('message', {}).get('content', []) or []):
if isinstance(block, dict) and block.get('type') == 'tool_use':
if block.get('name') == 'Bash':
cmd = block.get('input', {}).get('command', '')
if cmd:
# extract first meaningful command
first = cmd.split('&&')[0].split('|')[0].strip()
if first and not first.startswith('#') and not first.startswith('echo'):
cmds.add(first[:80])
except: pass
for c in sorted(cmds):
print(c)
PYEOF
Pass the output to the subagent with this prompt:
"Here are shell commands actually used in a Claude Code session. Group them by purpose (team management, search/query, git/PR, fleet communication, server, etc.). For each group, pick the most useful 3-5 commands. Return as markdown sections with code blocks. No prose — just heading + code + 1-line note."
2. Mine traps from conversation memory
Scan the conversation for:
Error messages that led to a different approach
Commands that were retried with different arguments
Explicit "trap" or "gotcha" or "bug" mentions
⚠️ warnings given during the session
Format each as a row: | trap description | workaround |
3. Build the cheat sheet
Path: ψ/writing/cheatsheets/YYYY-MM-DD_<topic>.md
Use this exact structure (fill from session data):