What a C Code Example Teaches About Agent Handoffs
Key takeaways
- A ~100-line ring buffer in C is an ideal test task for parallel agent sessions because it compiles in seconds and has unambiguous pass/fail tests.
- Give each agent session its own git worktree and branch so three sessions can edit one repo without touching each other's files.
- A handoff note on the task card, not chat history, is the system of record: what compiles, what is stubbed, and what the next session should check first.
- Merge branches in dependency order (implement, then fuzz, then demo) to avoid rebase conflicts across sessions.
- For C work, your CLAUDE.md must state who frees each allocation, the exact build command, and which files are off-limits to other sessions.
A good way to test how well your parallel agent sessions coordinate is to give every session the same small C code example, a ring buffer, and see whether they step on each other. The C is almost incidental: what matters is who claimed what, what changed, and what each agent leaves behind for the next one. This piece walks through that exact setup with three sessions, the git diff you wake up to, and the handoff note that makes the morning review survivable.
What is a good c code example for testing agent workflows?
A good c code example for testing agent workflows is one small, self-contained file with a clear spec, a fixed API, and tests that fail or pass in seconds. A ring buffer in C hits that mark. It is roughly 100 lines, it has real edge cases (wraparound, full vs. empty), and any agent session can claim it, build it, and prove its work without needing your database, your API keys, or your frontend.
The point is not the C. The point is that three parallel sessions can each own a slice of one task, and you can see who did what in a single git diff in the morning.
The ring buffer spec in 10 lines
Write the spec as a header file before any agent touches code: a fixed-capacity buffer of uint8_t values (cppreference documents the <stdint.h> types), with rb_init, rb_push, rb_pop, and rb_full/rb_empty predicates. Ten lines of comments define the contract. Each session claims a card for one function, writes the implementation plus its test, and leaves a handoff note for whoever picks up the next card.
Why C beats a web app for this
A web app pulls in a framework, a build pipeline, and a dozen files an agent can wander through. C gives you one translation unit, a compiler exit code, and a test binary. Failure is unambiguous: it compiles or it does not, the test passes or it does not. That makes handoffs between sessions cheap to verify, whether your agents run through Claude Code, Codex, or a setup like KanbanMCP's qwen-code flow.
The c code example: a ring buffer you can compile in 5 seconds
A ring buffer is the right c code example for parallel agent work because it is small enough to hold in your head but has real seams: capacity, wraparound, full-versus-empty, and off-by-one bugs in the index math. Three agents can split it without trampling each other.
ringbuf.h and ringbuf.c
// ringbuf.h
#ifndef RINGBUF_H
#define RINGBUF_H
#include <stddef.h>
#include <stdbool.h>
typedef struct {
unsigned char *buf;
size_t cap, head, tail;
bool full;
} ringbuf;
ringbuf *rb_new(size_t cap);
void rb_free(ringbuf *rb);
bool rb_push(ringbuf *rb, unsigned char b);
bool rb_pop(ringbuf *rb, unsigned char *out);
size_t rb_len(const ringbuf *rb);
#endif
// ringbuf.c
#include "ringbuf.h"
#include <stdlib.h>
ringbuf *rb_new(size_t cap) {
ringbuf *rb = malloc(sizeof *rb);
rb->buf = malloc(cap);
rb->cap = cap; rb->head = rb->tail = 0; rb->full = false;
return rb;
}
void rb_free(ringbuf *rb) { free(rb->buf); free(rb); }
bool rb_push(ringbuf *rb, unsigned char b) {
if (rb->full) return false;
rb->buf[rb->head] = b;
rb->head = (rb->head + 1) % rb->cap;
if (rb->head == rb->tail) rb->full = true;
return true;
}
bool rb_pop(ringbuf *rb, unsigned char *out) {
if (rb->tail == rb->head && !rb->full) return false;
*out = rb->buf[rb->tail];
rb->tail = (rb->tail + 1) % rb->cap;
rb->full = false;
return true;
}
size_t rb_len(const ringbuf *rb) {
if (rb->full) return rb->cap;
if (rb->head >= rb->tail) return rb->head - rb->tail;
return rb->cap - (rb->tail - rb->head);
}
A test that fails first
// test_ringbuf.c
#include "ringbuf.h"
#include <assert.h>
#include <stdio.h>
int main(void) {
ringbuf *rb = rb_new(4);
for (int i = 0; i < 6; i++) rb_push(rb, (unsigned char)i);
assert(rb_len(rb) == 4); // full, not 6
unsigned char b;
assert(rb_pop(rb, &b) && b == 2); // oldest survives
assert(rb_push(rb, 6)); // space after pop
rb_free(rb);
puts("ok");
return 0;
}
The test deliberately exercises the two bugs agents produce most: pushing past capacity and wraparound order after a pop. Run it before any agent touches the code, commit it, and every session has the same definition of done. That shared failing test is what makes a handoff note meaningful; without it, "wraparound works now" from one Claude Code session is just a claim the next session has to re-verify from scratch (see https://kanbanmcp.com/agents/claude-code for how cards and notes attach to this loop).
Compile and run
cc -Wall -Wextra -fsanitize=address test_ringbuf.c ringbuf.c -o test && ./test
One line, under five seconds, sanitizer included. Any agent session can run it and report the same green (or the same crash).
How do you split one C task across three agent sessions?
The ring buffer splits into three claimable cards: implement the buffer, write fuzz tests, wire up a CLI demo. Each card is small enough for one session to finish in one sitting, and none of them blocks another the way "do everything" does. On a board like KanbanMCP, each running session claims a card, works, and leaves a note for whoever picks up the next one.
One card, one worktree, one branch
Each session gets its own git worktree and branch, so three agents can edit the same repo without touching each other's files. Git supports this natively: multiple working trees checked out from one repository, each on its own branch. The C code example stays identical across all three; only the branch differs.
What goes on each card
Keep each card to what the next agent needs: the claim (what to build), the branch name, the done criteria (compiles clean, tests pass), and a pointer to CLAUDE.md. The fuzz-test card, for instance, says "assume ring_buffer.c and ring_buffer.h exist on main; write fuzz tests against the public API only." That one line prevents a session from rewriting the implementation while another is testing it.
What does a useful handoff note look like?
The note from session 1
When the first session finishes the ringbuf.c card, the note it leaves on the card reads something like this:
Claimed: session-1 (Claude Code, worktree
wt/ringbuf-init) Done:ringbuf_init,ringbuf_push,ringbuf_popin ringbuf.c. Compiles with-Wall -Wextra, 9/12 tests pass. Stubbed:ringbuf_peekreturns -1, overwrite-on-full not implemented. Next session: checkpushwhencount == capacitybefore touching overwrite logic; I suspect the tail index wraps one slot early. Tests 10-12 fail intest_ringbuf.c, lines 40-58.
That is the whole artifact: what compiles, what is stubbed, and the first thing to check. The next agent claims the card, reads the note, and starts at the failing tests instead of re-reading the whole file. On a board like KanbanMCP (the opencode setup shows the same flow), the note stays attached to the card, not buried in a terminal.
Why chat history is not a handoff
Chat sessions are disposable, and that is fine. The problem shows up a week later when the fix for ringbuf_peek lives in a Cursor session you closed and cannot search. If a project only exists across agent chats, recovering context means re-reading the git diff in the morning and guessing. A handoff note on the card is the system of record; the chat is working memory. Keep them separate and any session, in any tool, can pick up where the last one left off.
Where does the task board live when every agent needs it?
Files vs a board agents can write to
Your ring buffer task now lives in three places: a CLAUDE.md note, a backlog.md card, and whatever each session remembers. Files work, but nothing stops two agents claiming "fix the wraparound bug" at the same time. A board the agents read and write directly fixes that: a session claims a card, the claim is visible to the other two, and the handoff note lands on the card, not in a chat that dies.
| Tool | Where the board lives | Agents claim cards directly | Fits the ring buffer task |
|---|---|---|---|
| CLAUDE.md / backlog.md files | Repo files | No, you edit them | Works until two sessions collide |
| Taskmaster | Task file in repo | Via CLI | Good for a single session's queue |
| Vibe Kanban | Local board app | Yes, it manages parallel coding agents | Built for exactly this split |
| KanbanMCP | Hosted board | Yes, via MCP claim-and-note | Same, plus notes for the next agent |
Running the same criteria on KanbanMCP
KanbanMCP passes the same test: each session claims a card over MCP, does the work in its worktree, and leaves a note. The honest trade-off: it's a hosted board, so your task state lives outside the repo the way a backlog.md file wouldn't. If you'd rather keep everything in git, files win. If you're running three sessions across Claude Code and Cursor and want to see who claimed what without opening a chat, a board wins. The same claim-and-note flow works whether the agent runs in a terminal or an editor like VS Code (https://kanbanmcp.com/agents/copilot-vscode).
How do you review three agents' C changes in one git diff?
Your morning routine: one terminal, three worktrees. For each, run git diff main and read the diff on the ring buffer before anything else. Then run the test suite in that worktree. If an agent claimed a card, did the work and left a handoff note, the diff plus the note should tell you what changed and why in under two minutes.
Merge order matters
Merge implement first, then fuzz, then demo. The fuzz branch's tests assume the buffer API the implement branch landed, and the demo builds on both. Merging out of order means rebase conflicts in ring_buffer.c that three agents now have to resolve across sessions. Merge, pull each worktree, and let the next agent claim its card with a clean base.
When to reject a card
Reject when the diff touches files outside the card's scope, when tests fail, or when the handoff note contradicts what the diff shows. Push back with a note on the card and reassign it. Human review of the git diff is the one step you should not delegate.
Does the language change how agents coordinate?
Yes. C has no package manager and manual memory rules, so a handoff note carries more weight than in Go, where a module path and go.mod tell the next session most of what it needs. In C, the next agent has to be told which allocation owns a buffer, which files were touched, and whether tests were run at all. Taskmaster's README describes breaking projects into tasks with dependencies for agents (Taskmaster on GitHub); C work makes those dependency notes non-optional.
C-specific rules for your CLAUDE.md
Add three things for C work: who frees each allocation, the exact build and test command, and which files are off-limits to other sessions. State that agents claim a card before editing and leave a handoff note on completion. Without a compiler-enforced contract, the note is the contract.
What should you build first: the code or the coordination?
The ring buffer takes one agent twenty minutes. The coordination is what breaks first when you run three sessions, so build the board before you write the code.
Start with three cards: implement the ring buffer, add the overflow tests, write the usage note for the next session. Any board works, including a text file or backlog.md. What matters is that each card records who claimed it and what the next agent needs to know.
The payback is immediate. With a handoff note per card, your morning git diff tells you what changed and why, and no session edits a worktree another one already claimed. The C code is disposable; the handoff format is the part you keep.
FAQ
Can I use this c code example with free AI coding tools?
Yes. The ring buffer needs nothing exotic: a compiler, git, and an agent that can run shell commands. Free tiers of terminal-based agents can claim a card, edit ringbuf.c, and run the one-line test command. The constraint is not the tool, it is whether the free tier lets a session run long enough to finish one card and leave a note.
How many agent sessions can work on one C project before they conflict?
Three works comfortably when each session owns a separate card and its own worktree. Beyond that, the bottleneck shifts to merge order: the more branches touching ringbuf.c, the more rebase conflicts pile up. Four or five sessions can work if the cards stay scoped to different files, but one small C file realistically supports three parallel claims.
Is a kanban board overkill for a single C file?
Not when three sessions run at once. Even one C file produces multiple claimable tasks, and a text file cannot stop two agents from claiming the same fix. The board does not need features; it needs a visible claim per card and a place for the handoff note. A backlog.md file is fine until two sessions collide.
What is the best AI for programming in C specifically?
Any capable coding agent works, because the C example enforces its own quality: it compiles or it does not, and the test passes or it does not. Claude Code, Codex, and Cursor sessions all handled the ring buffer split in this setup. Pick based on how the tool claims cards and leaves notes, not on C-specific benchmarks, since the compiler does the grading.
How do I stop two agents editing the same C file at once?
Give each session its own git worktree and branch, and require a card claim before any edit. The card states which files are in scope and which are off-limits, so the fuzz-test session knows to test the public API only, not rewrite ringbuf.c. A board the agents write to makes claims visible to the other sessions, which a shared text file cannot do.