AI Workflow
Choose the right AI workflow for the task at hand.
AI Workflow
Choose the right workflow for the task you are about to do. All flows assume the AI can use the kn-* skills family when available.
Skills are not MCP tools. They are agent workflow commands synced to the agent's skills directory. MCP tools appear in codex mcp as domain tools such as tasks, docs, memory, search, and code.
| Platform | Skill syntax |
|---|---|
| Claude Code | /kn-spec, /kn-flow, /kn-review |
| Codex | $kn-spec, $kn-flow, $kn-review |
The examples below use Claude Code's /kn-* syntax. In Codex, replace / with $.
Use this guide when you need to decide whether work should go through full spec-driven development, a normal task flow, or a quick-fix path.
Choose your flow
| Flow | When to use | Typical sequence |
|---|---|---|
| Full SDD | large features, new systems, cross-cutting work | init -> research -> spec -> flow -> extract |
| Normal | small features, enhancements, well-understood tasks | init -> plan -> implement |
| Quick Fix | bug fixes, hotfixes, small repairs | init -> implement |
Why research comes before spec
Before writing a spec, the AI often needs enough context to avoid drafting the wrong requirements.
Use research first when:
- the codebase area is unfamiliar
- the feature touches existing patterns or constraints
- you need to see how similar functionality already works
This is why the full SDD path below starts with research before spec.
What kn-research searches
kn-research starts with project-owned context before going outside the repo:
- Knowns
searchandretrievefor docs, tasks, memory, and decisions - Knowns
codetools for symbols, definitions, references, diagnostics, and safe code navigation - specialized external MCP providers, when available, for upstream or library facts such as Context7/library docs, GitHub/source MCP, or official docs MCP
- general web search only when a specialized MCP provider is unavailable, insufficient, or the user explicitly asks for internet research
For large research scopes, the skill may split the work into independent tracks and use sub-agents when the runtime exposes sub-agent tools. External findings should support local source-of-truth docs, tasks, and source files, not replace them silently.
Full SDD flow
Use this for large features or changes that deserve a spec first.
1. Initialize session
/kn-init
Reads project context, guidance, docs, and current working state.
2. Research first
/kn-research
Use this step to gather enough project and upstream context before writing a spec.
3. Create spec
/kn-spec user-auth
The AI creates a spec document that typically includes:
- overview and requirements
- acceptance criteria
- scenarios and edge cases
4. Run the approved spec flow
After reviewing and approving the spec, use kn-flow for the normal end-to-end SDD path:
/kn-flow @doc/specs/user-auth
kn-flow discovers or generates linked tasks, schedules safe execution, plans, implements, runs review, fixes blocking findings, and verifies the spec/task set.
In Codex, $kn-flow may spawn sub-agents automatically after it reports the schedule, but only for parallel-safe task waves. Use --sequential when you want to force all work through the main context.
Manual task-only path
If you only want to generate tasks and execute them manually, use:
/kn-plan --from @doc/specs/user-auth
The AI breaks the spec into tasks and maps them back to spec acceptance criteria.
Then run individual tasks yourself:
/kn-implement 42
5. Verify
/kn-verify
Typical checks include:
- acceptance criteria coverage
- reference integrity
- spec/task consistency
6. Extract reusable knowledge
/kn-extract
Use this when the implementation produced a reusable pattern, decision, or lesson worth keeping.
Normal flow
Use this for smaller features where the task already exists and the problem is well understood.
/kn-init/kn-plan 42/kn-implement 42
Quick Fix flow
Use this for bug fixes, hotfixes, or small repairs.
/kn-init/kn-implement 42
When to use kn-flow
Use kn-flow when you have an approved spec or a task wave and want the normal orchestrated workflow:
- task discovery or generation
- planning
- implementation
- code review via
kn-review - integration and verification
Typical approved-spec path:
/kn-spec user-auth
(approve the spec)
/kn-flow @doc/specs/user-auth
In Codex, use $kn-spec and $kn-flow instead. $kn-flow can delegate parallel-safe waves to sub-agents; add --sequential to opt out.
When to use kn-go
kn-go is the legacy no-review-gates pipeline for approved specs.
Use kn-go when:
- the spec is already approved
- you want task generation, planning, implementation, verification, and commit preparation to move as one continuous flow
- you do not need to review each task individually before implementation
Prefer /kn-flow for normal approved-spec execution. Prefer /kn-plan + /kn-implement when:
- you want to inspect or adjust each task before coding
- the spec is still evolving
- you want tighter review checkpoints between phases
When to use kn-debug
Use kn-debug when implementation is blocked by an actual failure rather than missing planning.
Typical cases:
- build or type errors
- failing tests
- runtime crashes or exceptions
- integration failures
- a task is blocked and the root cause is still unclear
Use kn-debug instead of continuing normal implementation when the next useful action is to reproduce, diagnose, and fix the failure systematically.
When to use kn-extract
Use kn-extract when the work you just completed produced something reusable that should not remain buried in a single task or chat session.
Typical cases:
- you discovered a repeatable implementation pattern
- you made a project-level decision that future work should follow
- you found a failure mode and its fix should be remembered
- you want to turn ad-hoc implementation knowledge into docs, memory, or templates
Use kn-extract near the end of a task or after verification, once you know the result is worth preserving for future humans and agents.
Skill reference
| Skill | Purpose |
|---|---|
/kn-init | Load project context |
/kn-research | Explore project context, code, and relevant external MCP/web sources |
/kn-spec | Create a spec document |
/kn-flow | Orchestrate an approved spec or task wave |
/kn-plan | Create an implementation plan |
/kn-implement | Execute the work |
/kn-verify | Check ACs, refs, and consistency |
/kn-review | Review implemented work |
/kn-extract | Capture reusable knowledge |
/kn-doc | Work with docs |
/kn-template | Run templates |
/kn-debug | Debug blocked or failing work |
CLI fallback
If skills are not available in the runtime, use the CLI directly.
# Initialize context manually
knowns doc list --plain
knowns doc "readme" --plain --smart
# Take a task
knowns task edit 42 -s in-progress -a @me
knowns time start 42
# Add plan
knowns task edit 42 --plan $'1. Research\n2. Implement\n3. Test'
# Mark ACs and add notes
knowns task edit 42 --check-ac 1
knowns task edit 42 --append-notes "Completed feature X"
# Finish
knowns time stop
knowns task edit 42 -s done
Use separate sessions when useful
For larger work, it is often better to keep separate AI sessions per task or per phase.
Examples:
- one session for research
- one session for spec and planning
- one session for implementation
This reduces the chance of context compaction and makes each session easier to reason about.
Definition of done
As a rule of thumb, a task is done when:
- acceptance criteria are checked
- notes or implementation details are recorded
- any active timer for the task has been stopped
- relevant validation or tests pass
- task status is updated appropriately
Related
AI workflow
Chọn đúng flow cho loại việc sắp làm. Tất cả flow dưới đây giả định AI có thể dùng nhóm skill kn-* khi runtime hỗ trợ.
Skills không phải MCP tools. Skills là agent workflow commands được sync vào skills directory của từng agent. MCP tools sẽ hiện trong codex mcp dưới dạng domain tools như tasks, docs, memory, search, và code.
| Platform | Skill syntax |
|---|---|
| Claude Code | /kn-spec, /kn-flow, /kn-review |
| Codex | $kn-spec, $kn-flow, $kn-review |
Ví dụ bên dưới dùng syntax /kn-* của Claude Code. Với Codex, đổi / thành $.
Dùng tài liệu này khi cần quyết định: đi full spec-driven, task flow thường, hay quick fix.
Chọn flow
| Flow | Khi nào | Trình tự |
|---|---|---|
| Full SDD | feature lớn, hệ thống mới, thay đổi cross-cutting | init → research → spec → flow → extract |
| Normal | feature nhỏ, cải tiến, task đã rõ | init → plan → implement |
| Quick Fix | bug fix, hotfix, sửa nhỏ | init → implement |
Tại sao research trước spec?
AI cần đủ context trước khi viết spec để tránh draft sai yêu cầu.
Research trước khi:
- khu vực codebase còn lạ
- thay đổi liên quan tới pattern hoặc constraint sẵn có
- cần xem chức năng tương tự đang được làm thế nào
kn-research tìm gì?
kn-research bắt đầu từ context do project sở hữu trước khi đi ra ngoài repo:
- Knowns
searchvàretrievecho docs, tasks, memory, và decisions - Knowns
codetools cho symbols, definitions, references, diagnostics, và code navigation an toàn - specialized external MCP providers, nếu runtime có, cho upstream/library facts như Context7/library docs, GitHub/source MCP, hoặc official docs MCP
- general web search chỉ khi specialized MCP provider không có, không đủ, hoặc user yêu cầu internet research rõ ràng
Với research scope lớn, skill có thể tách thành các track độc lập và dùng sub-agents khi runtime expose sub-agent tools. External findings dùng để bổ trợ source-of-truth local như docs, tasks, và source files, không silently override chúng.
Full SDD flow
Dùng cho feature lớn hoặc thay đổi đáng có spec riêng.
1. Init session
/kn-init
Đọc project context, guidance, docs, trạng thái hiện tại.
2. Research
/kn-research
Gom đủ context từ project và upstream sources trước khi viết spec.
3. Tạo spec
/kn-spec user-auth
AI tạo spec document, thường gồm:
- overview và requirements
- acceptance criteria
- scenarios và edge cases
4. Chạy approved spec flow
Sau khi review và approve spec, dùng kn-flow cho SDD path end-to-end thông thường:
/kn-flow @doc/specs/user-auth
kn-flow discover hoặc generate linked tasks, schedule phần việc an toàn, plan, implement, chạy review, fix blocking findings, rồi verify spec/task set.
Trong Codex, $kn-flow có thể tự spawn sub-agents sau khi report schedule, nhưng chỉ với parallel-safe task waves. Dùng --sequential khi muốn ép mọi work chạy trong main context.
Manual task-only path
Nếu chỉ muốn generate tasks và tự chạy từng task, dùng:
/kn-plan --from @doc/specs/user-auth
AI tách spec thành tasks, map ngược về spec AC.
Sau đó chạy từng task:
/kn-implement 42
5. Verify
/kn-verify
Check:
- AC coverage
- reference integrity
- spec/task consistency
6. Extract
/kn-extract
Dùng khi implementation tạo ra pattern, decision, hoặc lesson đáng giữ lại.
Normal flow
Feature nhỏ, task đã có, vấn đề đã rõ.
/kn-init/kn-plan 42/kn-implement 42
Quick Fix flow
Bug fix, hotfix, sửa nhỏ.
/kn-init/kn-implement 42
Khi nào dùng kn-flow
Dùng kn-flow khi đã có approved spec hoặc một task wave và muốn workflow được orchestrate đầy đủ:
- task discovery hoặc generation
- planning
- implementation
- code review qua
kn-review - integration và verification
Approved-spec path điển hình:
/kn-spec user-auth
(approve spec)
/kn-flow @doc/specs/user-auth
Trong Codex, dùng $kn-spec và $kn-flow. $kn-flow có thể delegate parallel-safe waves cho sub-agents; thêm --sequential để opt out.
Khi nào dùng kn-go
kn-go là legacy no-review-gates pipeline cho approved specs.
Dùng khi:
- spec đã approved
- muốn task generation → planning → implementation → verification → commit prep chạy liền một mạch
- không cần review từng task trước khi code
Ưu tiên /kn-flow cho normal approved-spec execution. Ưu tiên /kn-plan + /kn-implement khi:
- muốn xem kỹ từng task trước khi code
- spec vẫn đang thay đổi
- cần review checkpoints rõ ràng giữa các pha
Khi nào dùng kn-debug
Dùng khi bị block bởi lỗi thật sự, không phải thiếu plan.
Các case điển hình:
- build error, type error
- test fail
- runtime crash
- integration failure
- task bị block mà chưa rõ root cause
Nói ngắn: nếu bước tiếp theo hợp lý nhất là reproduce → diagnose → fix có hệ thống, thì chuyển sang kn-debug thay vì cứ tiếp tục implement.
Khi nào dùng kn-extract
Dùng khi vừa hoàn thành phần việc tạo ra thứ gì đó reusable, không nên để chôn trong một task hay chat session.
Các case điển hình:
- tìm ra implementation pattern lặp lại được
- chốt project-level decision mà các phần việc sau cần follow
- gặp failure mode mà cách nhận biết và fix nên được nhớ lại
- muốn chuyển ad-hoc knowledge thành docs, memory, hoặc template
Nên dùng gần cuối task hoặc sau verify, khi đã biết chắc kết quả đáng lưu.
Skill reference
| Skill | Mục đích |
|---|---|
/kn-init | Load project context |
/kn-research | Explore project context, code, và external MCP/web sources liên quan |
/kn-spec | Tạo spec document |
/kn-flow | Orchestrate approved spec hoặc task wave |
/kn-plan | Tạo implementation plan |
/kn-implement | Thực hiện công việc |
/kn-verify | Check AC, refs, consistency |
/kn-review | Review implemented work |
/kn-extract | Lưu reusable knowledge |
/kn-doc | Làm việc với docs |
/kn-template | Chạy templates |
/kn-debug | Debug khi bị block hoặc fail |
CLI fallback
Nếu runtime không có skills, dùng CLI trực tiếp.
# Load context
knowns doc list --plain
knowns doc "readme" --plain --smart
# Nhận task
knowns task edit 42 -s in-progress -a @me
knowns time start 42
# Thêm plan
knowns task edit 42 --plan '1. Research\n2. Implement\n3. Test'
# Check AC và thêm notes
knowns task edit 42 --check-ac 1
knowns task edit 42 --append-notes "Completed feature X"
# Xong
knowns time stop
knowns task edit 42 -s done
Tách session khi cần
Với công việc lớn, nên tách session riêng theo task hoặc pha.
Ví dụ:
- một session cho research
- một session cho spec + planning
- một session cho implementation
Giảm nguy cơ context bị compact, mỗi session dễ kiểm soát hơn.
Khi nào coi là "xong"
Một task coi là done khi:
- AC đã check
- notes/implementation details đã ghi lại
- timer đã stop (nếu đang track time)
- validation/test đã pass
- task status đã update đúng