This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
FlowTrace Debugger — a runtime instrumentation toolkit. Each supported runtime
ships a capture layer that emits a unified JSONL trace (flowtrace.jsonl,
schema v2) consumable by a CLI, a dashboard, and an MCP server. The traces are
designed to be read by AI tools: the point is to give an agent evidence of what
the program actually did, rather than have it infer behaviour from source.
Supported runtimes: Java (OpenTelemetry javaagent extension), Node /
TypeScript (CJS hook + ESM loader + SWC transform), Python (import hook +
AST transform), Go (source rewrite before compilation via
go build -overlay) and Rust (a rustc wrapper that splices spans into a
shadow copy of each workspace crate). Each layer has its own README with the
knobs and the caveats that layer alone has. .NET was a v1 experiment and has
been removed; Go and Rust were too, and came back in a different shape — do not
"restore" the v1 agents, capture/go/ and capture/rust/ are v2 layers
emitting schema v2.
The authoritative capability list is mcp-server/src/runtimes.ts, served as
the flowtrace://runtimes MCP resource. When support changes, change it there
first — every prose statement of what is supported (both READMEs,
plugin/commands/trace.md, the skill) is a restatement, and this file has
already gone stale against it once.
capture/browser/ is a fourth, deliberately narrower layer: with no
AsyncLocalStorage in a browser there is no ambient async context, so it does
not instrument every function. It records HTTP, navigation and errors, and
ships them to the dashboard collector (POST /api/trace) rather than to a
file.
| Path | Role | Build system |
|---|---|---|
capture/java/flowtrace-otel-extension/ |
OTel javaagent extension: ByteBuddy advice + JSONL emitter | Maven (bytecode target 11) |
capture/node/ |
CJS Module._load hook, ESM loader, SWC transform, runtime |
pnpm |
capture/python/ |
sitecustomize bootstrap, import hook, AST transformer, runtime |
setuptools |
capture/go/ |
cmd/flowtrace-go driver, transform/ (AST byte-splice), flowtracert/ runtime |
go build |
capture/rust/ |
Rust: flowtrace runtime crate (std only), flowtrace-tracing layer, flowtrace-rust driver + rustc wrapper |
cargo |
capture/browser/ |
Browser capture (HTTP / router / errors) + Angular bindings | pnpm |
schema/flowtrace-v2.json |
The contract. JSON Schema for every emitted event | — |
examples/golden/ |
Golden fixtures: real capture output, committed and diffed in CI | — |
scripts/ |
Golden runners/normalizer, schema validation, plugin checks | pnpm |
flowtrace-cli/ |
Cross-language installer (flowtrace binary) |
pnpm |
flowtrace-dashboard/ |
Express server + static perf UI | pnpm |
mcp-server/ |
MCP server exposing log_* and trace_* tools |
pnpm + tsc |
plugin/ |
The distributable Claude Code plugin (see below) | — |
docs/ |
English (docs/en) + Spanish (docs/es) docs |
Everything is driven from the root Makefile — there is no per-subproject
install script. make test is the source of truth.
make build # build-java + build-python + build-node + build-go + build-mcp
make test # schema + golden + java + python + node + go + browser + mcp + dashboard + cli + docs + plugin bundle
make test-java # JUnit 5 (capture/java)
make test-go # go test ./... (capture/go)
make test-rust # cargo test --workspace (capture/rust); needs python3 for the cross-process test
make build-rust # builds flowtrace-rust, which the Rust golden fixtures and the CLI run
make test-python # pytest (capture/python)
make test-node # node:test (capture/node)
make test-browser # capture/browser + collector e2e
make test-mcp # MCP server tests
make validate-schema # every expected.jsonl against schema/flowtrace-v2.json
make check-golden # re-run every capture and diff against its committed fixture
make gen-golden # regenerate the fixtures (review the diff!)
make bundle-mcp # rebuild plugin/mcp/server.bundle.js after touching mcp-server/src
make check-bundle # verify that bundle is current and boots standaloneSingle tests:
cd capture/java/flowtrace-otel-extension && mvn test -Dtest=FlowtraceEmitterTest#method
cd capture/python && python -m pytest tests/test_x.py::test_y
cd capture/node && node --test test/test-traceparent.mjsschema/flowtrace-v2.json is authoritative — read it before changing anything
that emits. Two event variants, enter and exit, with
additionalProperties: false:
{"ts":<epoch seconds, float>,"trace_id":"<32 hex>","span_id":"<16 hex>","parent_id":"<16 hex>|null",
"event":"enter|exit","thread":"<name>","lang":"java|node|python|ts|go|rust","module":"<m>","class":"<C>",
"method":"<m>","visibility":"public|private|internal|unknown","args":{...},"depth":<n>}enter may also carry file and line: where the function is declared.
Both are optional, and they are the one part of the contract meant for a
consumer outside this repository — a static index (livespec ingest_traces)
joins a span to its symbol through them, because module means a package in
Java, a dotted module in Python, a crate in Rust and a file's basename in Node,
and none of those is a path. file is POSIX and relative to the project root
(FLOWTRACE_ROOT, else the cwd for Python and Node, the module root for Go,
the workspace root for Rust; Java can only know the source root, so it emits
package path + SourceFile). line is the declaration line where the layer
rewrites source and the first body line in Java; never the call site. A layer
that cannot know them omits them — it never guesses, and it never puts them on
exit.
exit additionally carries result (required, {} when there is no
value), duration_ns, and an optional error of {type, msg, stack}.
Two rules that have each already been broken once:
- A failed call is an
exitwitherrorset. There is noevent: "error"variant; the schema rejects it.resultis still required on that branch — emit{}. - Do not rename fields without changing every capture layer, the schema,
the golden fixtures and every consumer (
mcp-server,flowtrace-dashboard) in the same commit.
The ids are W3C Trace Context compatible, so a trace survives a process hop:
traceparent is parsed on the way in and rendered on the way out.
FLOWTRACE_TRACEPARENT is honoured by every runtime (Rust reads it once, at its first span). For an inbound HTTP
header, Java (OTel), Node/TS (propagate.js patches
http.Server.prototype.emit) and Go (the transformer seeds every
func(http.ResponseWriter, *http.Request)) are automatic; Python is not —
its header path is a manual remote_context call. Outbound is automatic in
Node/TS and in Java within what OTel instruments; Python and Go are manual, and
Go has no seam at all because net/http resolves at compile time.
Two rules that follow, both already broken once:
- Do not describe Python or Rust inbound-over-HTTP, or Go/Python/Rust outbound,
as automatic. Rust has no ambient context across threads or
.await: a span on a new thread is a root with a newtrace_id. A wrong claim here is worse than no claim: a split trace looks exactly like a working trace until someone compares ids across processes. - Never tell a user to call
flowtracertfrom their own Go source. It is injected as<module>/internal/flowtracertand exists only during an instrumented build, so importing it breaks their plaingo build. Anything Go needs on the request path has to be done by the transformer.
examples/golden/<id>/expected.jsonl is real capture output, normalized
and committed. make check-golden re-runs each fixture and diffs. The registry
is scripts/golden/runners.mjs — add a fixture there and CI picks it up
automatically.
scripts/golden/normalize.mjs replaces what is genuinely non-deterministic:
trace/span ids (renumbered in first-appearance order, so tree shape is still
asserted), ts, duration_ns, Java identity hashes, and error stack frames.
Anything else is compared verbatim.
A consequence worth remembering: because every trace_id is rewritten to one
constant, a golden fixture cannot assert cross-process correlation. That
property lives in capture/node/test/test-cross-process.mjs, which spawns two
real processes.
Without a prefix each capture layer instruments frameworks and stdlib and the
trace explodes. Every layer honours a package/module prefix
(-Dflowtrace.package-prefix, FLOWTRACE_PACKAGE_PREFIX), and the CLI
auto-detects one on flowtrace init. When investigating "the log is huge" or a
perf complaint, check prefix wiring first.
What the prefix is matched against differs by layer, and getting it wrong produces an empty trace rather than an error:
| Layer | Matched against |
|---|---|
| Java | the class's package (com.acme) |
| Python | the module name (myapp, matching myapp and myapp.*) |
| Go | the package import path (exact, or prefix/...) |
| Node / TS | the file path — filename.includes(prefix), so it is a directory, not a package name |
flowtrace init writes it to .flowtrace/config.json and flowtrace run
honours it: flag > config > auto-detection.
Every file-writing layer replaces a value whose argument name — or nested key —
matches the shared list (password, secret, token, authorization, api_key, url, dsn, connection_string, email) with <redacted>, in args and result,
before truncation. FLOWTRACE_REDACT_KEYS extends the list, never replaces it.
The reason is in SECURITY.md: a trace exists to be pasted into a model
conversation, which is the last place a credential belongs.
TRUNCATION_SYSTEM.md documents the shared rules for truncating args /
result. Each layer takes a max-arg-length knob (0 = no truncation), the
marker is <truncated:{first N chars of the JSON}...> measured on the JSON
form, and it applies to args and result independently.
examples/golden/truncation/{java,node,python,go} pin each layer against
itself. They cannot catch two layers disagreeing with each other — each is
diffed against its own previous output — and that is exactly how Java came to
emit a different marker, measured on toString(), with results never
truncated at all. When the rule changes, read the four layers together.
- Java — an OpenTelemetry javaagent extension, not a standalone premain
agent. Virtual threads propagate context; tasks on a platform-thread pool do
NOT — they inherit whatever span was current when the pool thread started.
Say so rather than implying pools work.
FlowtraceInstrumentationModule/FlowtraceTypeInstrumentationselect methods;FlowtraceAdviceweaves enter/exit and derives ids fromSpan.fromContext(Context.current()), which is why incomingtraceparentworks with no code of ours. The OTel agent version therefore decides which JDKs can be instrumented — its bundled ByteBuddy must know the class file version. Bytecode target stays at 11 deliberately: it is the floor of what can be instrumented, not the JDK we build on. CI runs 17, 21 and 25. - Node —
src/cjs/hook.jspatchesModule._load;src/esm/loader.mjsis the ESM loader;src/transform/swc.jsrewrites matched functions to call the__ft_enter/__ft_exit/__ft_exit_errorhelpers. Context propagation isAsyncLocalStorage; workers get it throughFLOWTRACE_TRACEPARENTin their env and reportthread: worker-<id>.langistsfor.ts/.tsx/.mts/.ctssources — same layer, different label. Nested functions are deliberately not instrumented (an Express trace would be unreadable); Python's transformer does instrument them, so the same program yields different tree shapes. - Browser — no module rewriting and no ambient context.
api.jsholds all the logic as plain functions;angular.jsis wiring only, so the part that needs a framework to test is the part least likely to be wrong. Browser work maps onto the existing schema fields (module= http|router|error) rather than extending the schema. - Rust —
flowtrace-rustsetsRUSTC_WORKSPACE_WRAPPERto itself, so cargo runs it instead ofrustcfor workspace members only. It mirrors each package'ssrc/into a shadow tree under<target>/flowtrace-<hash>/shadow, byte-splices a span guard into each function body (rewrite.rs: the body is wrapped in anFnOnceclosure with the function's return type, so?andreturnreach the trace; line numbers are unchanged), and compiles the shadow with the runtime linked via--extern. Two things break silently if touched: the wrapper rewrites cargo's dep-info back to original paths (else edits to the user's sources are never noticed), and a crate rustc rejects is rebuilt uninstrumented with a warning (sotests/corpusmust keep failing on that warning). Theflowtraceruntime must stay dependency-free and its hot path (enter/finish) non-generic: generic code is compiled in the user's crate at the user's opt level.flowtrace-tracingis the other entry point, for programs that already usetracing. - Python —
stub/sitecustomize.pybootstraps,finder.py/loader.pyinstall an import hook,transformer.pyrewrites the AST to call the same helper trio. Context propagation iscontextvars. Note the deliberate divergence from Node:current_depthholds the depth of the span about to start, soremote_contextseeds 0 where Node seeds -1. - Go — no runtime hook exists, so the rewrite happens before the
compiler:
cmd/flowtrace-goenumerates packages withgo list -json,transform/byte-splices matching files at AST offsets, and the result reaches the compiler throughgo build -overlay. The user's tree is never written to. Context propagation is the goroutine'sruntime/pproflabel slot reached by//go:linkname— the only mechanism that inherits across a baregostatement for free, which is whyflowtracert.Spanmust keeplistas its first field (see the comment there before touching that struct).flowtracert/is copied byte-for-byte into the target module, so it must stay stdlib-only and compile under the target'sgodirective, not this repo's.
bin/flowtrace.js is the entry point; commands live in lib/commands/.
lib/detect.js detects project type (java / python / node / ts) and the
package prefix, then writes .flowtrace/config.json into the target project and
updates its .gitignore. When adding a runtime, add a detector + command here —
do not modify the capture layers.
A local tool with no authentication, so it is built like one: binds
127.0.0.1 (FLOWTRACE_DASHBOARD_HOST widens it, with a warning), reads trace
paths only inside allowed roots (its cwd plus FLOWTRACE_DASHBOARD_ROOTS,
resolved through realpath), stores uploads under server-chosen random names,
and sends a strict CSP with Chart.js vendored rather than pulled from a CDN.
POST /api/analyze-file answers 403 {code: "OUTSIDE_ROOTS"} outside those
roots and flowtrace analyze then uploads instead. The analyzer reports both
inclusive duration_ns and exclusive self_ns; rank by self time, because
summing inclusive time counts every nanosecond once per ancestor.
TypeScript, @modelcontextprotocol/sdk, entry src/server.ts. Sessions are an
in-memory Map; a log is loaded once per log_open and queried through
log_search / log_aggregate / log_schema. src/trace-tools.ts implements
trace_tree / trace_find_error / trace_private_calls / trace_diff.
Transport is stdio — never write to stdout outside the MCP protocol.
The distributable Claude Code plugin: skill, subagent, commands, and the MCP
server as a committed single-file esbuild bundle at plugin/mcp/server.bundle.js.
A plugin install copies a directory and runs no build, so anything the plugin
references must be inside CLAUDE_PLUGIN_ROOT, tracked by git, and runnable
with no node_modules. scripts/check-plugin.mjs enforces exactly that and
boots the bundle in an empty directory. Run make bundle-mcp after touching
mcp-server/src.
.claude-plugin/marketplace.json at the root makes this repo installable as the
Rixmerz marketplace.
- User-facing CLI text is Spanish (matches README.md); English mirror in README.en.md.
- Code, comments and commit messages are English.
flowtrace.jsonlis the default log name everywhere; tools accept overrides.- Generated project files go under
.flowtrace/in the user's repo. - Schema version is
2.0.0and all capture layers lock to it together.
.claude/rules/(loaded automatically):autonomous-strategy.md,commit-discipline.md,security-awareness.md, plus per-language rules..claude/skills/holds the language pattern skills plusdebug,testing,validation..claude/commands/hasstatus(repo health check).CONTRIBUTING.md,ROADMAP.md,TRUNCATION_SYSTEM.md,docs/— deeper context before large changes.
No v1. The v1 agents (a standalone Java premain agent, a separate JS agent,
and Go / Rust / .NET implementations) emitted a different schema —
{"timestamp":<ms>,"event":"ENTER",...,"durationMicros":<n>} — with no
trace_id or span_id, so nothing in the v2 pipeline can read their output.
They have been deleted along with the install scripts that drove them. Do not
resurrect them or reintroduce v1 field names.
No jig. This repo was previously scaffolded by jig (an orchestrator project,
now obsolete) which installed a hook pipeline, 14 subagents, workflow graphs and
an MCP entry. All of it has been removed. Every hook was invoked through a
hardcoded interpreter path (/home/rixmerz/.local/share/uv/tools/jig-mcp/bin/python3)
that exists on no other machine, so the pipeline failed on every tool call for
every other contributor. Do not reintroduce jig, DCC (cube_*), graph workflows
(graph_*) or execute_mcp_tool proxying.