สารบัญ

คู่มือตั้งค่า Claude Code สำหรับทีม

อัปเดตล่าสุด: 13 พ.ย. 2026

ภาพรวม#

Setup นี้มี 4 ส่วน ทั้งหมดเป็น global config ใน ~/.claude/ ตั้งครั้งเดียวใช้ได้ทุกโปรเจกต์:

  1. Workflow "Codex เขียน, Claude รีวิว" — กำหนดใน ~/.claude/CLAUDE.md แยกคนเขียนโค้ดกับคนตรวจ เพื่อไม่ให้ Claude ตรวจงานตัวเอง
  2. Memory ต่อโปรเจกต์ — Claude จดสิ่งที่เรียนรู้ (gotcha, feedback) ลง <project>/.claude/memory/ ทำให้ session ถัดไปไม่พลาดซ้ำ
  3. Skill packs 3 ชุด — mattpocock-skills, andrej-karpathy-skills, 9arm-skills ให้ skill รีวิว/debug มาตรฐานเดียวกันทั้งทีม
  4. SessionStart hooks 2 ตัว — โหลด Karpathy guidelines อัตโนมัติ และสร้าง memory directory ให้ทุกโปรเจกต์

ทำตามลำดับหัวข้อด้านล่าง ใช้เวลาประมาณ 15 นาที คู่มือนี้อ้างอิง Claude Code 2.1.323 และ Codex CLI 0.166.0

1. สิ่งที่ต้องมีก่อน#

เครื่องมือจำเป็นไหมติดตั้ง / เช็ค
Claude Codeจำเป็นclaude --version
jqจำเป็น (hooks ใช้)brew install jq
Codex CLIแนะนำ (คนเขียนโค้ด)npm i -g @openai/codex แล้ว codex login
gitจำเป็น (ดึง plugin จาก GitHub)git --version

ไม่มี Codex ก็ใช้ได้ ให้ใช้ CLAUDE.md เวอร์ชัน fallback ในหัวข้อถัดไป (Claude เขียนเอง แต่ต้องรีวิวตัวเองทุกครั้ง)

ก่อนแก้ config ใดๆ ให้ backup ก่อน:

bash
cp ~/.claude/settings.json ~/.claude/settings.json.bak 2>/dev/null
cp ~/.claude/CLAUDE.md ~/.claude/CLAUDE.md.bak 2>/dev/null

2. Global CLAUDE.md — workflow Codex เขียน, Claude รีวิว#

ไฟล์ ~/.claude/CLAUDE.md ถูกโหลดทุก session ทุกโปรเจกต์ สั่งให้ Claude ส่งงานเขียนโค้ดให้ Codex แล้วรีวิวด้วย skill code-review หรือ scrutinize ถ้ามีไฟล์อยู่แล้ว ให้ต่อท้ายแทนการเขียนทับ

คัดลอกทั้งก้อนนี้ไปวาง (เพิ่ม gotcha --skip-git-repo-check ที่เจอภายหลังไว้ในข้อ 1 แล้ว):

markdown
# Global workflow: Codex writes, Claude reviews

For every code-writing task in every project (new features, bug fixes,
refactors, edits to existing code) — Claude must NOT write or edit code
files directly. Instead:

1. **Delegate the writing to Codex.** Formulate a clear, complete prompt
   (task, relevant file paths, constraints, acceptance criteria) and run it
   via Bash:
   ```
   codex exec -s workspace-write -C <project-dir> "<prompt>" < /dev/null
   ```
   Always append `< /dev/null` — without it, `codex exec` hangs silently
   waiting for stdin EOF.
   If `<project-dir>` is not a git repo, add `--skip-git-repo-check` —
   otherwise codex prints a warning and exits 0 without writing anything.
   Always read Codex's stdout; don't trust the exit code.

2. **Review what Codex wrote.** After Codex finishes, run the `code-review`
   skill (Standards vs Spec) or the `scrutinize` skill (for judgment-heavy /
   architectural changes) against the resulting diff. Don't just skim —
   trace the actual code path, not only the diff.

3. **Decide: apply, send back, or fix.** Based on the review, either accept
   the change, send Codex a follow-up prompt to correct specific issues, or
   make the correction directly if it's a small, targeted fix arising from
   the review itself — not a substitute for step 1.

4. **Verify before declaring done.** Run the project's build/lint/tests if
   available and report results.

**Exceptions (Claude may write directly):** memory files, scratch/temp files,
this CLAUDE.md itself, and non-code project-management artifacts (e.g. plan
docs, commit messages) — anything that isn't application/infra code.
When in doubt, route through Codex.

This is a strict, standing instruction. If the user explicitly says
"skip Codex" or "just write it yourself" for a specific task, that
overrides this file for that task only.

ไม่มี Codex: แก้ข้อ 1 เป็น "Claude writes the code directly" แต่คงข้อ 2–4 ไว้ เพราะหัวใจคือการรีวิวด้วย skill มาตรฐานเดียวกัน

Skip เฉพาะงาน: พิมพ์บอก Claude ว่า "skip Codex" ใน prompt ได้เลย

3. Memory — ให้ Claude จำสิ่งที่เรียนรู้ต่อโปรเจกต์#

ค่าเริ่มต้น Claude Code เก็บ auto memory ไว้ที่ ~/.claude/projects/<path>/memory/ ซึ่งหายากและแชร์ไม่ได้ เราย้ายมาไว้ในโปรเจกต์เองด้วย setting autoMemoryDirectory ใน <project>/.claude/settings.local.json:

json
{
  "autoMemoryDirectory": "/absolute/path/to/project/.claude/memory"
}

ไม่ต้องตั้งเองทีละโปรเจกต์ hook ensure-project-memory-session-start.sh (หัวข้อ 5) จะทำให้อัตโนมัติทุกครั้งที่เปิด session:

  • เพิ่ม autoMemoryDirectory ใน settings.local.json ถ้ายังไม่มี (ไม่ทับ key อื่น)
  • คัดลอก memory เก่าจาก ~/.claude/projects/.../memory/ มาไว้ในโปรเจกต์ (ไม่ทับไฟล์ที่มีอยู่)
  • ข้ามถ้าเปิด Claude ที่ $HOME ตรงๆ

โครงสร้างที่ได้: หนึ่งไฟล์ต่อหนึ่งเรื่อง + ไฟล์ MEMORY.md เป็น index ที่ถูกโหลดทุก session

text
<project>/.claude/memory/
├── MEMORY.md                    # index: บรรทัดละ 1 memory
└── codex-exec-non-git-dir.md    # 1 เรื่องต่อไฟล์

ตัวอย่างไฟล์ memory จริง (type มี user / feedback / project / reference):

markdown
---
name: codex-exec-non-git-dir
description: "codex exec needs --skip-git-repo-check when the target dir is not a git repo, or it silently no-ops with exit 0"
metadata:
  type: feedback
---

`codex exec` refuses to run outside a git repo and exits 0, so it looks like success.

**Why:** exit code 0 hides the failure.
**How to apply:** check if the dir is a git repo first; if not, add the flag.

การแยก memory: ปัจจุบันแยก 2 แบบนี้ก็พอ ไม่ต้องแตกโฟลเดอร์ย่อยตามหัวข้อ

  • แยกตามโปรเจกต์: แต่ละโปรเจกต์มี .claude/memory/ ของตัวเอง ผ่าน hook ที่ตั้งไว้
  • แยกตามประเภทในไฟล์: ทุกไฟล์มี type เป็น user, feedback, project หรือ reference ระบุไว้ในส่วนหัวของไฟล์

วิธีใช้: บอก Claude ตรงๆ ว่า "จำไว้ว่า …" หรือปล่อยให้มันจดเองเมื่อเจอ gotcha ดูหรือแก้ได้ด้วยคำสั่ง /memory

Git: settings.local.json เป็นค่าส่วนตัว (absolute path ต่างกันทุกเครื่อง) อย่า commit ส่วน .claude/memory/ ตัดสินใจเองต่อ repo: commit ถ้าอยากแชร์ gotcha กับทีม, ใส่ .gitignore ถ้ามีเรื่องส่วนตัว

4. Plugins และ Skill set#

ติดตั้ง 3 plugin นี้เอง ส่วน skill อื่นๆ ที่เห็นในเครื่อง (engineering:*, datadog:*, anthropic-skills:* เช่น sre-datadog, performance-testing-th) sync มาจาก organization อัตโนมัติเมื่อ login ด้วยบัญชีบริษัท ไม่ต้องติดตั้งเอง

PluginRepoSkill หลักที่ใช้
mattpocock-skillsmattpocock/skillscode-review (ใช้ใน workflow), tdd, diagnosing-bugs, grilling, writing-for-agents
andrej-karpathy-skillsmultica-ai/andrej-karpathy-skillskarpathy-guidelines (โหลดอัตโนมัติผ่าน hook) — ใช้ fork นี้เท่านั้น
9arm-skillsthananon/9arm-skillsscrutinize (ใช้ใน workflow), debug-mantra, post-mortem, management-talk

วิธีติดตั้ง: merge 2 key นี้เข้า ~/.claude/settings.json (merge อย่าทับ key เดิม) แล้วเปิด Claude Code ใหม่ มันจะถามให้ trust marketplace และติดตั้งให้

json
{
  "extraKnownMarketplaces": {
    "mattpocock": {
      "source": { "source": "github", "repo": "mattpocock/skills" }
    },
    "karpathy-skills": {
      "source": { "source": "github", "repo": "multica-ai/andrej-karpathy-skills" }
    },
    "nine-arm-skills": {
      "source": {
        "source": "settings",
        "name": "nine-arm-skills",
        "plugins": [
          { "name": "9arm-skills", "source": { "source": "github", "repo": "thananon/9arm-skills" } }
        ]
      }
    }
  },
  "enabledPlugins": {
    "mattpocock-skills@mattpocock": true,
    "andrej-karpathy-skills@karpathy-skills": true,
    "9arm-skills@nine-arm-skills": true
  }
}

ชื่อหลัง @ ใน enabledPlugins ต้องตรงกับ key ใน extraKnownMarketplaces เสมอ ไม่งั้น plugin ไม่โหลด

ตรวจไฟล์หลังแก้: jq empty ~/.claude/settings.json ไม่มี output = JSON ถูกต้อง จากนั้นพิมพ์ /plugin ใน Claude Code เพื่อดูว่า 3 plugin ขึ้น enabled

qwen-agent ใน 9arm-skills ต้องมี claude-9arm ตั้งไว้ก่อน ถ้าไม่มีก็ข้ามได้ skill อื่นใน pack ยังใช้ได้ปกติ

5. SessionStart hooks#

มี 2 script วางไว้ใน ~/.claude/hooks/ ทั้งคู่รันทุกครั้งที่เปิด session และต้องมี jq

5.1 สร้าง ~/.claude/hooks/karpathy-guidelines-session-start.sh — อ่าน SKILL.md จาก plugin karpathy แล้วฉีดเป็น context ให้ทุก session (ต้องติดตั้ง plugin ในหัวข้อ 4 ก่อน ไม่งั้น script จะข้ามเงียบๆ)

bash
#!/bin/bash
BASE_DIR="${CLAUDE_CONFIG_DIR:-$HOME/.claude}"
PLUGIN_DIR="$BASE_DIR/plugins/cache/karpathy-skills/andrej-karpathy-skills"
SKILL_FILE=$(find "$PLUGIN_DIR" -name "SKILL.md" -path "*karpathy-guidelines*" \
  2>/dev/null | head -1)

if [ -z "$SKILL_FILE" ]; then
  exit 0
fi

BODY=$(awk '/^---$/{c++; next} c>=2' "$SKILL_FILE")
INTRO="The following behavioral guidelines are already loaded for this session"
INTRO="$INTRO — apply them to all work without needing to invoke any skill:"

jq -n --arg intro "$INTRO" --arg body "$BODY" '{
  hookSpecificOutput: {
    hookEventName: "SessionStart",
    additionalContext: ($intro + "\n\n" + $body)
  }
}'

5.2 สร้าง ~/.claude/hooks/ensure-project-memory-session-start.sh — ตั้ง autoMemoryDirectory และย้าย memory เก่า (หัวข้อ 3)

bash
#!/usr/bin/env bash

PROJECT_DIR=$(pwd)

if [[ "$PROJECT_DIR" == "$HOME" ]]; then
  exit 0
fi

{
  CLAUDE_DIR="$PROJECT_DIR/.claude"
  SETTINGS_FILE="$CLAUDE_DIR/settings.local.json"
  MEMORY_DIR="$CLAUDE_DIR/memory"

  if [[ -f "$SETTINGS_FILE" ]]; then
    if jq -e . "$SETTINGS_FILE" >/dev/null; then
      if ! jq -e 'has("autoMemoryDirectory") and .autoMemoryDirectory != null' \
        "$SETTINGS_FILE" >/dev/null; then
        TEMP_FILE=$(mktemp "$CLAUDE_DIR/settings.local.json.XXXXXX")
        if jq --arg memory_dir "$MEMORY_DIR" \
          '. + {autoMemoryDirectory: $memory_dir}' \
          "$SETTINGS_FILE" >"$TEMP_FILE"; then
          mv "$TEMP_FILE" "$SETTINGS_FILE"
        else
          rm -f "$TEMP_FILE"
        fi
      fi
    fi
  elif mkdir -p "$CLAUDE_DIR"; then
    TEMP_FILE=$(mktemp "$CLAUDE_DIR/settings.local.json.XXXXXX")
    if jq -n --arg memory_dir "$MEMORY_DIR" \
      '{autoMemoryDirectory: $memory_dir}' >"$TEMP_FILE"; then
      mv "$TEMP_FILE" "$SETTINGS_FILE"
    else
      rm -f "$TEMP_FILE"
    fi
  fi

  CONFIG_DIR=${CLAUDE_CONFIG_DIR:-"$HOME/.claude"}
  SANITIZED_PROJECT=$(printf '%s' "$PROJECT_DIR" | sed 's/[^A-Za-z0-9]/-/g')
  OLD_MEMORY_DIR="$CONFIG_DIR/projects/$SANITIZED_PROJECT/memory"

  if [[ -d "$OLD_MEMORY_DIR" ]] && \
    find "$OLD_MEMORY_DIR" -type f -print -quit | grep -q .; then
    mkdir -p "$MEMORY_DIR"
    shopt -s nullglob
    OLD_MARKDOWN_FILES=("$OLD_MEMORY_DIR"/*.md)
    if ((${#OLD_MARKDOWN_FILES[@]})); then
      cp -n "${OLD_MARKDOWN_FILES[@]}" "$MEMORY_DIR/"
    fi
  fi
} >/dev/null 2>&1 || true

exit 0

5.3 ให้สิทธิ์รัน:

bash
chmod +x ~/.claude/hooks/*.sh

5.4 ลงทะเบียน hook — merge key hooks เข้า ~/.claude/settings.json:

json
{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/karpathy-guidelines-session-start.sh",
            "statusMessage": "Loading Karpathy guidelines..."
          },
          {
            "type": "command",
            "command": "~/.claude/hooks/ensure-project-memory-session-start.sh"
          }
        ]
      }
    ]
  }
}

ค่าอื่นใน settings.json (เลือกใช้): ตั้งตามความชอบได้ เช่น "model": "opus" และ "permissions": { "defaultMode": "auto" } ส่วน permission อื่นๆ ให้แต่ละคนตั้งเองตามงานของตัวเอง

6. Connectors (เลือกใช้)#

Connector อย่าง Atlassian, Slack, Datadog, Google Drive, Linear มาจาก claude.ai ของ organization ไม่ต้องตั้งใน settings.json เปิดใช้ได้ด้วยคำสั่ง /mcp ใน Claude Code แล้วเลือก authenticate เฉพาะตัวที่ใช้งานจริง ส่วน Datadog plugin ต้องรัน /datadog:ddsetup ครั้งแรก

7. ตัวอย่าง: เริ่มโปรเจกต์ใหม่แล้วเช็คว่า setting ทำงานครบ#

ทุกขั้นด้านล่างทดสอบรันจริงแล้วบน Claude Code 2.1.323 จุดสำคัญคือ memory จะย้ายมาอยู่ในโปรเจกต์ตั้งแต่ session ที่ 2 เพราะ session แรกโหลด settings เสร็จก่อน hook จะเขียนไฟล์

ขั้นที่ 1 — สร้างโปรเจกต์ใหม่แล้วเปิด Claude ครั้งแรก

bash
mkdir -p ~/work/demo-project && cd ~/work/demo-project
git init
claude

ตอนเปิดจะเห็นสถานะ Loading Karpathy guidelines... แวบขึ้นมา พิมพ์ /exit ออกได้เลย

ขั้นที่ 2 — ดูไฟล์ที่ได้

bash
find . -path ./.git -prune -o -print
cat .claude/settings.local.json

ผลที่ควรได้:

text
.
./.claude
./.claude/settings.local.json

{
  "autoMemoryDirectory": "/Users/<you>/work/demo-project/.claude/memory"
}

โฟลเดอร์ .claude/memory/ ยังไม่มีเป็นเรื่องปกติ จะถูกสร้างตอน Claude เขียน memory ครั้งแรก

ขั้นที่ 3 — ให้ Claude ตรวจตัวเอง (รันในโฟลเดอร์เดิม นี่คือ session ที่ 2)

bash
claude -p "Answer briefly as a checklist, no tools:
(1) Is the Karpathy guidelines text in your context from a SessionStart hook?
(2) Do you have the skills code-review (mattpocock-skills) and scrutinize (9arm-skills)?
(3) What is your auto memory directory path?
(4) Does your global CLAUDE.md tell you to delegate code writing to Codex?"

ผลที่ควรได้ (จากการทดสอบจริง):

text
- [x] (1) Karpathy guidelines from a SessionStart hook: Yes.
- [x] (2) Skills: Yes, mattpocock-skills:code-review and 9arm-skills:scrutinize.
- [x] (3) Auto memory directory: /Users/<you>/work/demo-project/.claude/memory/
- [x] (4) Global CLAUDE.md delegates code writing to Codex: Yes.

ถ้าข้อ 3 ตอบเป็น ~/.claude/projects/.../memory/ แปลว่านี่เป็น session แรก ให้รันอีกรอบ

ขั้นที่ 4 — เช็คใน Claude Code แบบ interactive

คำสั่งสิ่งที่ต้องเห็น
/pluginmattpocock-skills, andrej-karpathy-skills, 9arm-skills เป็น enabled
/hooksSessionStart มี 2 command: karpathy-guidelines และ ensure-project-memory
/memoryมี user memory ~/.claude/CLAUDE.md และ auto memory ชี้ไป <project>/.claude/memory

ขั้นที่ 5 — ทดสอบ memory เขียนจริง

ใน Claude Code พิมพ์: จำไว้ว่าโปรเจกต์นี้ใช้ pnpm ไม่ใช้ npm แล้วเช็ค:

bash
ls .claude/memory/
cat .claude/memory/MEMORY.md

ต้องเห็นไฟล์ memory ใหม่ 1 ไฟล์ และบรรทัดใหม่ใน MEMORY.md เปิด session ใหม่แล้วถาม "โปรเจกต์นี้ใช้ package manager อะไร" ต้องตอบ pnpm

ขั้นที่ 6 — ทดสอบ workflow Codex

พิมพ์: สร้างไฟล์ hello.py ที่ print hello ต้องเห็น Claude เรียก codex exec -s workspace-write -C ... < /dev/null แทนการเขียนไฟล์เอง แล้วตามด้วยการรีวิว ถ้า Claude เขียนไฟล์เองเลย แปลว่า ~/.claude/CLAUDE.md ไม่ถูกโหลด

เก็บกวาด: rm -rf ~/work/demo-project

8. ใช้ผ่าน Claude Desktop#

ใช้ setup นี้ได้เฉพาะแท็บ Code ใน Claude Desktop ส่วนแชทปกติไม่ใช้ไฟล์ใน ~/.claude เลย

แท็บ Codeแชทปกติ
อ่าน ~/.claude/settings.json, plugin, skillใช่ (ชุดเดียวกับ CLI)ไม่
CLAUDE.md, SessionStart hook, auto memoryน่าจะใช่ (เอกสารไม่ได้บอกตรงๆ ต้องเช็คด้านล่าง)ไม่
Workflow Codex เขียน / Claude รีวิวใช้ได้ ถ้าหา codex เจอไม่ได้ (รันคำสั่งในเครื่องไม่ได้)
Skillจาก plugin ตามหัวข้อ 4อัปโหลด ZIP ที่ Customize > Skills (ต้องเปิด Code execution)
Memory<project>/.claude/memory/Memory ของแชท เปิดที่ Settings แยกกับ Claude Code

ไม่ต้องติดตั้ง CLI แยก: แอปมี Claude Code มาในตัว แต่ยังต้องทำหัวข้อ 1–5 ให้ครบ เพราะทั้งแอปและ CLI อ่านไฟล์ชุดเดียวกันใน ~/.claude

จุดที่ต้องระวังที่สุดคือ PATH: แอปอ่านเฉพาะค่าที่ login shell ส่งออกมา อาจหา codex หรือ jq ไม่เจอทั้งที่ใน terminal ใช้ได้ ถ้าเจอปัญหา ให้ปิดแล้วเปิดแอปใหม่ หรือใส่ PATH ผ่าน key env ใน ~/.claude/settings.json เช่น:

json
{
  "env": {
    "PATH": "/Users/<you>/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
  }
}

ใช้ which codex jq ใน terminal เพื่อดู path จริงของเครื่องตัวเอง

เรื่องอื่นที่ต่างจาก CLI: กด Shift+Tab สลับโหมด permission ไม่ได้ ต้องเลือกใน UI แทน และ session แบบ WSL ใช้ plugin ไม่ได้

เช็คว่าแท็บ Code ใช้ setup ครบ — เปิด session ในโฟลเดอร์โปรเจกต์ 2 ครั้ง (เหตุผลเดียวกับหัวข้อ 7) แล้วพิมพ์:

  • รัน which codex jq ให้ดูหน่อย — ต้องเจอทั้ง 2 คำสั่ง
  • Karpathy guidelines ถูกโหลดมาจาก SessionStart hook ไหม — ต้องตอบว่าใช่
  • auto memory เก็บไว้ที่ไหน — ต้องตอบ <project>/.claude/memory/
  • global CLAUDE.md บอกให้ส่งงานเขียนโค้ดให้ Codex ไหม — ต้องตอบว่าใช่

ข้อไหนไม่ผ่าน ให้รายงานในทีม เพราะส่วนนี้ยังไม่มีใครทดสอบบน Desktop

ที่มา: Claude Code on desktop · Desktop quickstart · Use skills · Chat memory

9. Checklist ตรวจหลังติดตั้ง#

  • jq empty ~/.claude/settings.json ไม่มี error
  • /plugin แสดง mattpocock-skills, andrej-karpathy-skills, 9arm-skills เป็น enabled
  • เปิด session ใหม่ในโปรเจกต์ใดก็ได้ เห็นสถานะ "Loading Karpathy guidelines..."
  • หลังเปิด session มีไฟล์ <project>/.claude/settings.local.json ที่มี autoMemoryDirectory
  • ถาม Claude ว่า "ตอนนี้มี skill อะไรบ้าง" ต้องเห็น code-review และ scrutinize
  • สั่งแก้โค้ดเล็กๆ หนึ่งงาน Claude ต้องเรียก codex exec … แทนการแก้เอง

ปัญหาที่เจอบ่อย

อาการสาเหตุวิธีแก้
codex exec ค้างนานหลายนาที CPU 0%รอ stdinต่อท้าย < /dev/null เสมอ
Codex exit 0 แต่ไม่มีไฟล์เปลี่ยนdir ไม่ใช่ git repoเพิ่ม --skip-git-repo-check
Karpathy guidelines ไม่ถูกโหลดplugin ยังไม่ติดตั้ง หรือ script ไม่มีสิทธิ์รันทำหัวข้อ 4 และ chmod +x
Plugin ไม่ขึ้นชื่อหลัง @ ไม่ตรงกับ key marketplaceแก้ให้ตรงกัน
Memory ไม่ถูกสร้างไม่มี jq หรือเปิดที่ $HOMEbrew install jq แล้วเปิดในโฟลเดอร์โปรเจกต์

ทางลัด: ส่งลิงก์คู่มือนี้ให้ Claude Code แล้วบอกว่า "setup ตามคู่มือนี้ให้ อ่าน settings.json เดิมก่อน merge ห้ามทับ" ให้ Claude ทำให้ได้