Claude Code Agentic Workflow Tutorial: Repo to PR
Key takeaways
- An agentic workflow needs four files: a CLAUDE.md process contract, slash commands for /plan and /build, a PreToolUse hook, and a subagent config.
- Treat chat sessions as disposable and use card handoff notes as your working memory so the next session can resume work exactly where the last one stopped.
- Use PreToolUse hooks to block tool calls like git commit so agents physically cannot skip steps such as leaving a handoff note.
- Commit the .claude/ directory to your repo so the entire team and other AI agents inherit the same enforced workflow loop.
A working claude code agentic workflow tutorial needs four files: a CLAUDE.md process contract, two slash commands for /plan and /build, a PreToolUse hook that blocks skipped steps, and a subagent config for review. This walkthrough includes every file verbatim so you can reproduce the entire loop exactly.
What does an agentic workflow in Claude Code actually consist of?
Four building blocks: a CLAUDE.md file that states the process, custom slash commands that trigger steps, hooks that enforce them, and subagents for isolated work. Everything else is glue.
The four files that define your workflow
CLAUDE.md is your process contract: what the agent must do before touching code. Slash commands like /plan and /build turn each step into a repeatable entry point. Hooks run programmatically at tool-call time, so skipped steps fail loudly. Subagents give a step its own clean context. Anthropic documents the memory file and its loading rules here: project memory and CLAUDE.md.
System of record vs working memory vs disposable sessions
Split your state into three layers. The system of record is the board: which card is claimed, what's done, what's blocked. Working memory is the note an agent leaves on a card for the next one. Chat sessions stay disposable — a session that dies costs nothing because the card carries the context forward. We use this split in our own Claude Code workflow, where the board is the record and each session reads only what the card holds. The honest limitation: file-based CLAUDE.md rules drift unless hooks enforce them, which later sections fix.
How do you structure CLAUDE.md so the agent follows your process reliably?
CLAUDE.md works as a process contract, not a context dump. Keep it under roughly 50 lines, state the loop as imperative rules, and the agent follows it; fill it with background prose and it gets skimmed. The three things worth specifying are the plan-build-review sequence, card claiming, and the handoff note format.
The full CLAUDE.md for this tutorial
Process
Every task follows three phases, in order, one phase per session:
1. /plan — read the card, write a plan, post it as a comment.
2. /build — implement the plan, commit in small steps.
3. /review — diff against the plan, fix gaps, open the PR.
Card rules
- Claim a card before working: set assignee to your session id.
- Never work on a card someone else holds.
- On stopping, leave a handoff note (format below) and release or keep the claim.
Handoff note (post to the card, not the chat)
- Done: what actually shipped, commit refs.
- Open: what remains, with the exact next command to run.
- Gotchas: anything that broke and why.
Chat sessions are disposable. The card is the system of record.
Why process rules beat context dumps
The agent re-reads CLAUDE.md every session, so anything in it is enforced; anything in a chat log dies with the session. That is the fix for losing a project's context weeks later. Rules like "claim before working" and the fixed note format are what let one agent pick up where another stopped, which is the same mechanic KanbanMCP is built around. The honest limit: CLAUDE.md is a prompt, not a gate. A drifting agent can still skip /review, which is why hooks exist — covered later in this tutorial.
When should you use custom slash commands versus subagents versus hooks?
The three mechanisms do different jobs: slash commands are repeatable entry points, subagents are isolated roles, and hooks are enforcement. Use a slash command when you want the same prompt run the same way every time, like /plan or /build. Use a subagent when a step needs its own context window so it doesn't pollute the main session. Use a hook when the agent must not be able to skip a step, because hooks run in code and can block a tool call outright.
| Mechanism | Best for | Failure mode it prevents |
|---|---|---|
| Slash command | Repeatable entry points like /plan | Re-typing prompts slightly differently each session |
| Subagent | Isolated roles (planner, reviewer) | Context bleed between steps |
| Hook | Enforcement, e.g. blocking edits without a plan | The agent quietly skipping steps |
Slash commands are markdown files Claude Code picks up from .claude/commands/, per the Claude Code documentation. One honest gap in our own setup: on KanbanMCP the board is the system of record, but the slash commands and hooks still live in your repo, so a fresh clone needs the .claude/ directory committed or the workflow is gone.
How do you wire a plan-build-review loop across multiple Claude Code sessions?
The loop splits work into three session types: one session plans, one or more build, and a final one reviews. Each session reads its instructions from the board, does one job, and leaves a note for the next. Context stays disposable because everything the next session needs lives in the handoff note, not in chat history.
The /plan command definition
Create .claude/commands/plan.md so any session can turn a card into an executable plan:
Read the card assigned to this session via the Kanban board MCP.
Produce a plan with: (1) files to change, (2) steps in order,
(3) acceptance criteria copied from the card.
Write the plan to plans/<card-id>.md, then move the card to
"Ready to build" and stop. Do not write application code.
The "do not write application code" line matters. It stops the planning session from half-building something and dying with the reasoning trapped in a dead chat.
The /build command definition
.claude/commands/build.md is the mirror image:
Read the card and the plan at plans/<card-id>.md.
Implement the steps in order. After each step, append a line
to the card's note: what you did, what you skipped, anything
the next session must know.
When all steps pass the acceptance criteria, move the card to
"Ready for review" and stop. Do not review your own work.
This is the paragraph worth quoting: the handoff note is the whole trick. A build session that runs out of context, crashes, or gets killed mid-task leaves a trail on the card, so the next session reads the last note and continues from that exact step instead of re-deriving the plan or repeating logic that used to work. That is what keeps hundreds of disposable chat sessions from becoming an unrecoverable project: the system of record is the card, working memory is the note, and no session ever needs to remember anything. The same note format works whether the next session is Claude Code or a different agent entirely, which is why we built KanbanMCP's Meta Muse Code integration around cards any agent can claim and annotate. Be honest about the limit: notes can drift from reality if an agent lies in one, so the review session must diff claims against the actual commits.
The handoff note format
Keep it to four lines so agents actually write it:
DONE: step 2 of 5, auth middleware compiles
SKIPPED: rate limiting, needs a decision on the store
NEXT: wire routes in src/api.ts, see plan step 3
GOTCHA: tests use the fake clock helper, not vi.useFakeTimers
A fresh session's first prompt is one line: Read the oldest card in "Ready to build" and run /build. It picks up the note, the plan, and the acceptance criteria, and continues exactly where the last session stopped.
How do you constrain the agent with hooks so it can't skip steps?
Slash commands ask; hooks enforce. A PreToolUse hook runs before a tool call and can block it with a non-zero exit code, so the agent physically cannot commit without leaving a handoff note for the next session.
The hook script
Save this as .claude/hooks/block-commit.sh:
#!/bin/bash
input=$(cat)
cmd=$(echo "$input" | jq -r '.tool_input.command // empty')
if echo "$cmd" | grep -qE '^git commit'; then
if ! git diff --cached --name-only | grep -q 'HANDOFF.md'; then
echo "Blocked: update HANDOFF.md with the handoff note before committing." >&2
exit 2
fi
fi
The agent must stage a HANDOFF.md change describing what it did and what the next agent needs. This is the same handoff pattern KanbanMCP builds around cards, as in our Qwen Code integration, where the note lives on the board instead of a file.
Registering it in settings.json
Add to .claude/settings.json:
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{"type": "command", "command": ".claude/hooks/block-commit.sh"}]
}]
}
}
Commit the script and settings file so every clone of the repo runs the same gate.
How do you test and debug an agentic workflow when it drifts from the intended process?
Drift shows up in the files before you notice it in the output. Three symptoms cover most cases, and each one is diagnosable from the board and the notes the agent left behind.
Symptom: the agent repeats work a previous session finished
Open the card notes on your board and check timestamps against commits. If a note says "auth middleware done" and the next session writes the same middleware again, the second agent never read the card, or the note was too vague to act on. Fix the note format: state what changed, which files, and what remains. If repeats cluster on one project, your cards are carrying too little state and the agents are rebuilding context from the diff instead.
Symptom: the review step gets skipped
Grep your session logs for the review command. If /review never runs but cards move to done anyway, your hook isn't blocking the transition, or the agent is editing around it. Tighten the hook so a card can't change column without a review note attached. Also check whether the reviewer is reading stale code: a review note that references files the build step renamed means the sessions are racing each other on the same repo.
Symptom: context bleed between projects
When an agent working on project A cites conventions from project B, the shared memory is too broad. Check whether CLAUDE.md or card notes reference paths outside the repo root. Scope every note and rule to the project directory, and keep cross-project patterns in one place you copy in deliberately, not something the agent can reach on its own.
Where does a file-based workflow break down, and how do you share the fix with a team?
File-based boards rot when three agents touch the same markdown file and clobber each other's edits. Handoff notes drift out of sync with actual card state. Cross-project work means jumping between repos with no shared view.
KanbanMCP replaces the file with a board agents claim cards on. One agent picks up a card, does the work, leaves a note, and the next agent resumes from that note. You watch and steer from the same board instead of digging through chat sessions.
Running the same criteria against KanbanMCP
KanbanMCP keeps the system of record separate from working memory, which matches the pattern that works. Cards stay simple, notes stay short, and chat sessions stay disposable.
Where it falls short: if you already live in Linear or Trello, adding another board creates a second place to check. KanbanMCP does not replace those tools for roadmap planning. It replaces the markdown board that was never meant to handle concurrent agents in the first place.
Sharing the workflow with a team
Commit the .claude/ directory to the repo. Slash commands, hooks, and settings.json are project config; anything personal like API keys or machine paths goes in user-level config outside the repo. A teammate clones, runs Claude Code, and inherits the same /plan and /build loop with the same hooks blocking skipped steps.
Subagents defined in .claude/agents/ are also shareable, so your reviewer agent ships with the repo. Anthropic's Claude Code docs cover the settings hierarchy and agent definitions in detail.
For a second agent rather than a second human, the same rules apply: the repo is the system of record, and any agent that reads .claude/ picks up the loop. The board note from the previous session replaces chat history as handoff context.
FAQ
Do I need subagents for an agentic workflow, or is CLAUDE.md enough?
CLAUDE.md alone describes the process, and slash commands make steps repeatable. Add subagents only when a step needs its own context window, like a reviewer avoiding the builder's reasoning. Hooks matter more than subagents: without them, a drifting agent can skip the review phase entirely.
How do I stop Claude Code from losing context between sessions?
Treat chat sessions as disposable and put state on the card. Each session ends by writing a handoff note: what shipped, what remains, the exact next command, and gotchas. The next session reads the card and continues from that step, so nothing important dies with the chat log.
Can Claude Code hooks block a git commit?
Yes. A PreToolUse hook runs before the Bash tool executes and can exit with a non-zero code to block the call. The tutorial's script checks whether HANDOFF.md is staged and refuses any commit without it, so the agent physically cannot commit without leaving a handoff note.
How do I run multiple Claude Code agents on the same project without conflicts?
Use card claiming: an agent sets itself as assignee before working, and no agent touches a card someone else holds. Each session does one phase, leaves a handoff note, and moves the card forward. The review session then diffs claims against actual commits, catching notes that drifted.
Is CLAUDE.md the same as a system prompt?
It functions like one but loads per project and gets re-read every session, so rules persist across chats. The difference that matters: CLAUDE.md is a prompt, not a gate. An agent can still ignore it, which is why hooks exist to enforce the steps the file merely asks for.