320 File Changes, 11 Attributed: Naming the Agent Behind a Write with eBPF
A coding agent on my machine ran go build, go test and gofmt. That caused 320 recorded file changes. Looking at the writing process, its parent and its command line, we attributed 11 of them to the agent. The other 309 looked like an ordinary build.
Why one hop is not enough
The agent did not write those files. compile wrote 110, link 77, vet 57 and asm 32, and none of them is a child of the agent. The chain is claude > bash > go > compile.
The 11 that matched were luck. An output path under /tmp/claude-1000/ put the string "claude" in a command line. Rename the directory and the count is zero.
Recording the grandparent as well would have found 44 of 320. Any fixed number of hops loses to a build system: make, cc and ld already go deeper, and so do npm, node and esbuild.
Walk the ancestry at the moment of the write
So the eBPF program walks real_parent from the writing task and stores the name of each ancestor's executable. Userspace reverses it into one string:
systemd>dash>node>node>claude>bash
- The walk cannot stop at the agent. The kernel side does not know which names are agents, and it should not: that list changes every week. So every chain also carries the levels above the agent, four or five of them on my machine.
- The walk is capped at 24 levels, and a chain that was cut off says so with a leading
…. - It runs per event, not once at exec. A process that was already running when the daemon started has no exec record, but its ancestry is still there to read.
- PID 1 is not its own parent. Its
real_parentis the idle task, so an early version marked complete chains as cut off. The walk now stops at PID 1.
Agents that are called node
Executable names are not enough either. An agent written in JavaScript or Python shows up as node or python3, and setting process.title does not change that. Everything such an agent ran was attributed to nobody.
The walk now also stores the process ID of each ancestor, in the same loop iteration as its name. Userspace uses it to name an interpreter by the script it runs, so node becomes node:pi.
What the verifier made of it
The verifier does not count what runs. It explores the states a program can reach, so costs multiply where you expect them to add:
- Our
notify_changeprogram inlined one large handler behind three conditions and took 829,297 of the 1,000,000 instructions allowed. Collapsing the three calls into one took it to 446,740. Splitting it into tail-called programs, each verified on its own, removed the shared limit. - Keeping path components in a stack array at a variable index added 520,000 instructions.
- Raising one loop bound from 16 to 24 took a program from 51,666 to about 377,000.
The same object that loaded on kernels 5.14 to 7.0 was rejected on 7.2.4, at 1,000,001 instructions. The cause was our own bug: a length the verifier treats as possibly negative, stored as unsigned. Nothing in the kernel had broken, our margin was just gone. A rename was simpler: do_filp_open became do_file_open in 7.0, so we ship both programs and load the one whose symbol exists.
Dropped records
A full ring buffer drops records, and nothing in the output shows it. Creating 30,000 files and removing them lost 34% of the creates and 89% of the deletes on my machine, because the userspace loop read about 11,000 records a second. Now one goroutine only copies records into a queue and another processes them. The same test then lost nothing, up to 300,000 files. That is a measurement on one machine, not a guarantee.
What this does not see
- Detached processes. When a parent exits, the kernel hands its children to PID 1 and the link to the agent is gone. A command the agent starts with
setsidand leaves behind is recorded, but not attributed to the agent. In one capture of all activity, 4.1% of events came from such processes. - Agents that save through the editor. Their writes come from the editor's process, so ancestry alone cannot tell them from yours. That needs a different method.
- Memory-mapped writes are recorded when the file is released, not as they happen.
- Blocking. kaimon observes and never blocks.
kaimon is an Agent Integrity Monitor (AIM) for VS Code on Linux, kernel 5.14 or later with BTF. The extension is open source under Apache-2.0. The eBPF daemon is proprietary. Always free, 100% local, no signup.