Nói ngắn gọn trước

Slash /workflows trong Claude Code v2.1.150 không xuất hiện trong docs public hiện tại, nhưng binary local vẫn có dấu vết rất rõ. Nó được gate sau một feature flag: muốn thử, bạn set CLAUDE_CODE_WORKFLOWS=1 rồi restart session. Sau đó binary có thể register các bundled workflow chạy multi-agent, kết thúc bằng việc mở PR. Cảnh báo trước: phần này là binary-derived, chưa phải feature public documented, nên nên thử trên branch nhỏ và coi như experimental.

Workflow trong Claude Code là gì

Workflow trong Claude Code không phải prompt thường. Từ strings trong binary, nó giống một script JavaScript deterministic, orchestrate nhiều subagent theo phase. Mỗi phase có thể spawn agent song song, gom kết quả, vote, refine, rồi pass xuống phase sau. Một số bundled flow có mô tả rõ là mở PR ở cuối, nhưng vì docs public chưa ghi phần này, tôi không coi đây là API ổn định.

Điểm chắc nhất ở v2.1.150 là feature này đang bị gate sau env var. Tôi không khẳng định lifecycle trước đó như một public contract, vì phần này không có trong docs chính thức.

Tôi tìm thấy cơ chế gate ở đâu

Binary v2.1.150 ở máy tôi nằm tại ~/.local/share/claude/versions/2.1.150 (Mach-O 64-bit, ARM64). Grep strings ra đủ mảnh để reconstruct logic gate như sau:

function bp() {  // "are workflows enabled?"
  if (Dw_ !== undefined) return Dw_;            // cached
  if (!truthy(process.env.CLAUDE_CODE_WORKFLOWS)) {
    Dw_ = false;                                 // OFF unless env set
  } else {
    Dw_ = statsig("tengu_workflows_enabled", true);
  }
  return Dw_;
}

Đọc luồng: nếu CLAUDE_CODE_WORKFLOWS không set (hoặc set “0”, “false”, chuỗi rỗng), bp() trả về false. Toàn bộ workflow feature bị tắt. Slash /workflows không register, WorkflowTool không load vào tool list của model, các bundled command (/implement, /bugfix…) không xuất hiện.

Nếu env set truthy, gate chuyển qua statsig flag tengu_workflows_enabled (default true ở branch đó). Statsig cho phép Anthropic ramp dần theo cohort, hoặc kill switch khi cần.

Vì sao Anthropic làm vậy? Tôi chỉ suy đoán được vài lý do hợp lý.

  1. Workflow là long-running multi-agent. Mỗi flow nuốt nhiều subagent run, dễ vượt 5h và 7d limit nếu user chạy không kiểm soát.
  2. Có note trong binary: "Date.now() / new Date() are unavailable in workflow scripts (breaks resume)". Feature còn fragile, không phải default mong muốn cho người dùng bình thường.
  3. Statsig flag cho phép tinh chỉnh roll-out mà không cần ship binary mới.

Cách bật feature

Cách 1, export env trong shell:

export CLAUDE_CODE_WORKFLOWS=1

Bỏ vào ~/.zshenv hoặc ~/.zshrc để persist qua session. Restart claude để binary đọc lại env.

Cách 2, set qua ~/.claude/settings.json:

{
  "env": {
    "CLAUDE_CODE_WORKFLOWS": "1"
  }
}

Cách 2 chỉ áp dụng cho process claude, không leak ra shell khác. Đề xuất cách này nếu bạn không muốn env có mặt khắp nơi.

Sau khi bật, kiểm tra bằng cách gõ /workflows trong session. Nếu thấy UI tracker mở ra (chưa có workflow nào đang chạy thì list rỗng), feature đã active.

10 workflow thấy được trong binary

Mình rút từ strings binary. Mỗi flow có một tên, một mô tả ngắn, và một dòng “khi nào dùng”. Tên có vẻ map sang slash command sau khi feature bật, nhưng tôi vẫn xem đây là quan sát từ binary, không phải reference chính thức.

implement

End-to-end task runner. Plan với 5-angle adversarial critique, adjust plan, implement, chạy bughunt-lite review + feature completeness check, fix issue, mở PR.

Khi user đưa task coding tự khép kín cần làm end-to-end không cần giám sát. Tốt cho task dài hơi cần plan và verification kỹ. Workflow scope vấn đề, harden plan với 5 critic, implement, sweep bug, check completeness, fix, rồi mở PR.

Cú pháp:

/implement Add /admin/audit-log page showing last 100 user actions with filter by user and date range

bugfix

Reproduce-first bug fixer. Viết failing repro, root-cause fault, apply fix tối thiểu, convert repro thành regression test, mở PR.

Khi user báo bug cụ thể có thể reproduce. Workflow viết failing repro trước, trace root cause, apply fix nhỏ nhất để repro pass, lock vào làm regression test, rồi mở PR.

/bugfix Login flow throws 500 when email contains plus sign

bughunt

Multi-agent bug sweep trên branch hiện tại. Self-respawning finder pool (3 rapid + deep-until-dry-streak) stream vào 5-vote adversarial verification với pigeonhole early-exit, rồi synthesis.

Khi user muốn hunt bug, audit code quality, hoặc chạy high-precision sweep trên branch. Tốn quota nhất trong nhóm bundled vì pool tự respawn.

/bughunt

bughunt-lite

Phiên bản gọn hơn của bughunt. Finder pool cố định kích thước, không tự respawn. Dùng cho diff nhỏ và vừa.

Khi user muốn sweep nhanh có chặn budget. Prefer trên bughunt nếu diff không quá lớn.

dashboard

Dashboard generator. Discover data source và dashboard convention có sẵn trong repo, design panel layout, implement, dry-run query và render-check, mở PR.

Khi user muốn dashboard, monitoring view, hoặc metrics page. Workflow tìm data có sẵn và pattern dashboard hiện có, spec panel + layout, implement, verify query và rendering, mở PR.

/dashboard Build a panel showing API latency p50/p95/p99 grouped by endpoint over last 24h

docs

Documentation generator. Discover feature surface và doc convention, outline cho audience cụ thể, viết hoặc update docs, verify code example và link, mở PR.

Khi user muốn docs cho feature, API, hoặc module. Workflow tìm code liên quan và pattern doc, draft outline, write, check example chạy được + link resolve, mở PR.

/docs Write docs for the new /api/v2/orders endpoint

investigate

Root-cause investigation. Gather evidence, generate hypothesis song song, adversarially refute từng cái, produce written root-cause report kèm suggested fix.

Khác bugfix ở chỗ không apply fix tự động, không mở PR. Output là report. Dùng khi root cause chưa rõ, hoặc khi fix nằm ngoài codebase (config, infra).

/investigate Orders API intermittently returns 502 between 02:00 and 04:00 UTC

plan-hunter

Exhaustive planning harness. Generate 4 independent draft plan (MVP-first, risk-first, dependency-first, user-first), score bằng 4 judge song song, pick winner bằng vote, rồi synthesize final plan ghép tinh hoa từ runner-up.

Lưu ý từ binary: “BEFORE invoking this workflow, ask 2-3 clarifying questions if the idea is underspecified”. Tức nếu idea còn mơ hồ, hỏi rõ scope/timeline, constraint/non-goal, success criteria trước khi gọi, sau đó pass idea đã rõ làm args.

/plan-hunter Migrate auth from sessions to JWT, supporting both flows during transition for 30 days

review-branch

Thorough review branch hiện tại: bugs, simplicity, architecture, dead code, best practices, pattern consistency. Mỗi finding được adversarial verify trước khi report.

Khi user muốn code review, audit branch trước khi ship, hoặc check PR quality. Output là list finding có verify, không tự fix.

/review-branch

deep-research

Research workflow ít nổi bật hơn. Binary có name nhưng description tôi thấy không đủ rõ, nên không nên viết prompt production dựa trên suy đoán. Nếu muốn thử, chạy trên repo nhỏ trước và đọc trace/log kỹ.

Cú pháp gọi thử

Trong session, gõ trực tiếp slash command:

/implement Add dark mode toggle to settings page, persist preference in localStorage

Hoặc qua CLI từ terminal:

claude -p '/implement add dark mode toggle to settings page'

Phần UX chính xác có thể thay đổi theo flag/cohort. Nếu /workflows mở được UI progress thì theo dõi ở đó; nếu không, coi như feature chưa bật cho setup của bạn.

Custom workflow thì sao

Có dấu hiệu binary hỗ trợ workflow script local, ví dụ các path:

.claude/workflows/<name>.js          # project-scoped
~/.claude/workflows/<name>.js        # global cho user

Tôi chưa thấy schema chính thức trong docs public, nên phần custom workflow hiện chưa nên dùng cho việc quan trọng. Có thể chờ Anthropic ship doc, hoặc reverse từ bundled flow nếu chỉ nghiên cứu.

Mấy gotcha không nên bỏ qua

Đọc kỹ ba điều sau trước khi xài nặng.

Date.now() và Math.random() không dùng được

Strings trong binary nói rõ:

Date.now() / new Date() are unavailable in workflow scripts (breaks resume). Stamp results after the workflow returns, or pass timestamps via args. Math.random() is unavailable in workflow scripts (breaks resume). For N independent samples, include the index in the agent label or prompt.

Lý do: workflow phải resume được sau crash hoặc network drop. Nếu script gọi Date.now(), mỗi lần resume sẽ ra giá trị khác, làm phase cache mất tác dụng. Tương tự cho Math.random(). Nếu cần timestamp, stamp ở caller hoặc pass qua args. Nếu cần N sample độc lập, include i vào prompt cho mỗi agent thay vì random.

Workflow chạy trên fresh clone của branch đã push

Một số strings và mô tả flow cho thấy workflow làm việc trên branch/PR workflow riêng, không nên giả định nó thấy working dir hiện tại. Cách an toàn là:

  1. Commit và push branch trước khi gọi workflow.
  2. Untracked file, staged change, work-in-progress diff không vào được workflow run.
  3. Branch local-only không chạy được.

Nếu workflow open PR, kiểm tra target branch trước khi merge. Đây là nơi tôi sẽ cẩn thận nhất vì feature chưa documented public.

Tốn quota khá nhanh

Mỗi workflow spawn nhiều subagent song song. Ví dụ bughunt có pool tự respawn + 5 verifier vote cho mỗi finding. Plan-hunter draft 4 plan + 4 judge. Một lần chạy có thể nuốt 20-50 agent run dễ dàng. Quota 5h và 7d sẽ tụt nhanh hơn nhiều so với gõ prompt thường.

Đề xuất: dùng /review-branch hoặc /bughunt-lite trước để thử cảm giác, đo quota tiêu trên một flow nhỏ, rồi mới dồn budget vào /implement hoặc /bughunt cho task dài.

Mở PR cần gh CLI đúng account

Workflow gọi gh pr create ở phase cuối. Nếu bạn có nhiều GitHub account (cá nhân, công ty), gh auth status phải đang ở account đúng với remote của repo. Nếu sai, PR bị tạo dưới account khác, hoặc fail với 403.

Tôi sẽ bắt đầu thế nào

Lần đầu bật CLAUDE_CODE_WORKFLOWS=1, thử /review-branch trên một feature branch nhỏ. Không edit gì, không mở PR mới, chỉ tốn budget cho một sweep, để xem flow cảm giác thế nào và quota tiêu bao nhiêu.

Sau đó thử /bugfix trên một bug đã có repro rõ. Workflow này predictable nhất, output dễ verify (failing test thành passing test).

Đợi quen với cách workflow open PR và phase progress, mới dùng /implement hoặc /bughunt cho task dài hơi. Đừng chạy 3 workflow song song trong cùng phiên 5h trừ khi quota của bạn dư.

Kết

Workflow là một bước tách khỏi mô hình “model chat với tool” của Claude Code, hướng tới orchestration đa phase deterministic. Việc nó bị gate sau env var ở v2.1.150 là tín hiệu nên đọc thận trọng: có capability trong binary, nhưng chưa phải thứ tôi sẽ đưa vào workflow production ngay. Set env, thử bundled trên branch nhỏ, đo quota, rồi mới quyết định có đáng đưa vào workflow nội bộ không.

Bài liên quan trên blog này nếu bạn muốn đào sâu thêm vào internals Claude Code: anatomy session, multi-agent coordination, subagent pattern, tool use loop. Tất cả nằm dưới tag claude-code.