trace

module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: MIT

README

Trace

Git-native session capture for AI coding agents

Quick StartHow It WorksCommandsConfigurationContributing


Trace hooks into your Git workflow to capture AI agent sessions as you work. Sessions are indexed alongside commits, creating a searchable record of how code was written — not just what changed.

Ecosystem Boundaries

Trace is a Hawk support engine. Keep the dependency edge one-way:

  • trace uses local-only types (trace/redaction event types are trace-scoped, not shared contracts)
  • do not import hawk/internal/*
  • do not import removed legacy path hawk/shared/types
  • do not import other engines (eyrie, yaad, tok, sight, inspect) — engines are peers, not dependencies

What you get

Capability Description
Understand why code changed Full prompt/response transcripts, files touched, token usage
Rewind instantly Go back to any checkpoint when an agent goes sideways
Fork & A/B Branch a new independent session from any checkpoint to explore alternatives
Resume seamlessly Pick up where you or a coworker left off on any branch
Cost attribution USD cost broken down per session and per tool from recorded token usage
Clean git history All session data lives on a separate branch — zero noise
Audit & compliance Searchable, versioned record of every AI interaction

Supported Agents

Agent Status
Claude Code Fully supported
Codex Fully supported
Gemini CLI Fully supported
OpenCode Fully supported
Cursor Supported (rewind unavailable)
Factory AI Droid Fully supported
Copilot CLI Fully supported

Quick Start

Trace is a library, not a standalone binary. Its full command tree is built by cli.NewRootCmd() and surfaced inside the Hawk CLI as hawk trace ... (Hawk is in development — no public install yet). There is no separate trace binary to install.

Contributors — build/test the library from source:

git clone https://github.com/GrayCodeAI/trace && cd trace
go build ./...
go test ./...

Once Hawk is available, use the commands under hawk trace:

# Enable in your project
cd your-project
hawk trace enable

# Check status
hawk trace status

That's it. Trace runs silently in the background via Git hooks.


How It Works

Your Branch                    trace/checkpoints/v1
     |                                  |
     v                                  |
[Base Commit]                           |
     |                                  |
     |  +--- Agent works ---+           |
     |  |  Step 1           |           |
     |  |  Step 2           |           |
     |  |  Step 3           |           |
     |  +-------------------+           |
     |                                  |
     v                                  v
[Your Commit] ----------------------> [Session Metadata]
     |                           (transcript, prompts,
     v                            files touched, tokens)

Key principles:

  • Zero commits on your active branch
  • Session data stored on trace/checkpoints/v1 orphan branch
  • Checkpoints created automatically at each commit
  • Non-destructive rewind — restores files without altering history
  • Works on any branch (main, feature, etc.)

Typical Workflow

1. Enable

trace enable                     # Interactive setup
trace enable --agent claude-code # Non-interactive

2. Work normally

Use your AI agent as before. Trace captures everything in the background.

trace status   # Check session anytime

3. Rewind if needed

trace checkpoint rewind   # Select a checkpoint to restore

4. Resume on another branch

trace session resume <branch>   # Restore session metadata & continue

5. Disable (optional)

trace disable   # Removes hooks, code untouched

Commands

Command Description
trace enable Enable Trace in your repository
trace disable Remove hooks from repository
trace status Show current session info
trace agent Add, remove, or list agent integrations
trace configure Update non-agent settings
trace checkpoint List, explain, rewind, search checkpoints
trace checkpoint rewind Rewind to a previous checkpoint
trace checkpoint explain Explain a session or checkpoint
trace fork Clone a checkpoint into a new independent session for A/B testing
trace annotate Attach a comment to a session or checkpoint
trace ci-init Configure Trace to auto-capture sessions in CI
trace session View and manage sessions
trace session resume Restore session on a branch
trace session attach Attach to a detached session
trace session export Export a session (JSON envelope or asciinema cast)
trace clean Clean up orphaned session data
trace doctor Diagnose and fix issues
trace login Authenticate with Trace
trace version Show CLI version

Run trace <command> --help for detailed usage.


Configuration

Trace stores config in .trace/ at the repo root.

Project settings (.trace/settings.json)

Shared with the team, committed to git:

{
  "enabled": true,
  "strategy_options": {
    "push_sessions": true,
    "summarize": { "enabled": true }
  }
}

Local overrides (.trace/settings.local.json)

Personal, gitignored:

{
  "log_level": "debug"
}

All options

Option Values Description
enabled true / false Toggle Trace
log_level debug, info, warn, error Logging verbosity
strategy_options.push_sessions true / false Auto-push checkpoints on git push
strategy_options.checkpoint_remote {"provider": "github", "repo": "..."} Push checkpoints to separate repo
strategy_options.summarize.enabled true / false AI summaries at commit time
attribution.attribute_co_authored_by true / false Append Co-authored-by: <agent> trailer (default on)
attribution.attribute_author true / false Set the git author to the agent (default off)
attribution.attribute_committer true / false Set the git committer to the agent (default off)
dirty_commits true / false Auto-commit a dirty working tree before an agent session (default on; --no-dirty-commits to skip)
webhooks {"urls": ["..."], "events": ["..."]} POST a JSON notification on session lifecycle events (default off)
telemetry true / false Anonymous usage analytics

Checkpoint Remote

Push session data to a separate private repo:

trace enable --checkpoint-remote github:myorg/checkpoints-private

Security & Privacy

  • Session transcripts live on trace/checkpoints/v1 in your repo
  • Secrets are automatically redacted (API keys, tokens, credentials) — best-effort
  • Shadow branches used during sessions are local-only and never pushed
  • See docs/security-and-privacy.md for details

Troubleshooting

Issue Fix
"Not a git repository" cd into a git repo first
"Trace is disabled" trace enable
"No rewind points" Work with your agent, then commit
Shadow branch conflict trace clean --force

Debug mode:

TRACE_LOG_LEVEL=debug trace status

Reset everything:

trace clean --all --force

Accessibility:

export ACCESSIBLE=1   # Screen reader friendly mode

Development

# Prerequisites: mise (https://mise.jdx.dev/)
git clone https://github.com/GrayCodeAI/trace.git
cd trace && mise install && mise trust

# Build
mise run build

# Test
mise run test          # Unit tests
mise run test:ci       # Full suite (unit + integration)

# Lint & format
mise run fmt && mise run lint

See CLAUDE.md for architecture details.


License

MIT — see LICENSE


Built by GrayCode AI

Directories

Path Synopsis
cli
hook_registry.go provides hook command registration for agents.
hook_registry.go provides hook command registration for agents.
agent
Package agent provides interfaces and types for integrating with coding agents.
Package agent provides interfaces and types for integrating with coding agents.
agent/claudecode
Package claudecode implements the Agent interface for Claude Code.
Package claudecode implements the Agent interface for Claude Code.
agent/codex
Package codex implements the Agent interface for OpenAI's Codex CLI.
Package codex implements the Agent interface for OpenAI's Codex CLI.
agent/copilotcli
Package copilotcli implements the Agent interface for GitHub Copilot CLI.
Package copilotcli implements the Agent interface for GitHub Copilot CLI.
agent/cursor
Package cursor implements the Agent interface for Cursor.
Package cursor implements the Agent interface for Cursor.
agent/external
Package external provides an adapter that bridges external agent binaries (discovered via PATH as trace-agent-<name>) to the agent.Agent interface.
Package external provides an adapter that bridges external agent binaries (discovered via PATH as trace-agent-<name>) to the agent.Agent interface.
agent/factoryaidroid
Package factoryaidroid implements the Agent interface for Factory AI Droid.
Package factoryaidroid implements the Agent interface for Factory AI Droid.
agent/geminicli
Package geminicli implements the Agent interface for Gemini CLI.
Package geminicli implements the Agent interface for Gemini CLI.
agent/opencode
Package opencode implements the Agent interface for OpenCode.
Package opencode implements the Agent interface for OpenCode.
agent/pi
Package pi implements the Agent interface for the pi coding agent (https://github.com/earendil-works/pi-mono).
Package pi implements the Agent interface for the pi coding agent (https://github.com/earendil-works/pi-mono).
agent/pi/pijsonl
Package pijsonl provides shared parsing primitives for Pi's session JSONL format.
Package pijsonl provides shared parsing primitives for Pi's session JSONL format.
agent/skilldiscovery
Package skilldiscovery holds the per-agent registries (curated built-ins, install hints) and the keyword match helper that the `trace review` picker uses to discover review-adjacent skills.
Package skilldiscovery holds the per-agent registries (curated built-ins, install hints) and the keyword match helper that the `trace review` picker uses to discover review-adjacent skills.
agent/spawn
Package spawn provides the Spawner interface used by both `entire review` and `trace investigate` to start an agent process non-interactively.
Package spawn provides the Spawner interface used by both `entire review` and `trace investigate` to start an agent process non-interactively.
agent/testutil
Package testutil provides shared test utilities for agent packages.
Package testutil provides shared test utilities for agent packages.
agent/vogon
Package vogon implements the Agent interface for a deterministic test agent used as an E2E canary.
Package vogon implements the Agent interface for a deterministic test agent used as an E2E canary.
agentlaunch
Package agentlaunch is the shared "launch a normal coding agent session with a composed prompt" helper, used by `entire review --fix` and `trace investigate fix`.
Package agentlaunch is the shared "launch a normal coding agent session with a composed prompt" helper, used by `entire review --fix` and `trace investigate fix`.
api
benchutil
Package benchutil provides test fixture helpers for CLI benchmarks.
Package benchutil provides test fixture helpers for CLI benchmarks.
checkpoint
Package checkpoint provides types and interfaces for checkpoint storage.
Package checkpoint provides types and interfaces for checkpoint storage.
checkpoint/id
Package id provides the CheckpointID type for identifying checkpoints.
Package id provides the CheckpointID type for identifying checkpoints.
cost
Package cost computes USD cost attribution for agent token usage.
Package cost computes USD cost attribution for agent token usage.
execx
Package execx provides explicit helpers for spawning subprocesses with a chosen TTY attachment mode, replacing env-var signalling with real OS state.
Package execx provides explicit helpers for spawning subprocesses with a chosen TTY attachment mode, replacing env-var signalling with real OS state.
gitexec
Package gitexec runs the git CLI from inside the codebase.
Package gitexec runs the git CLI from inside the codebase.
gitremote
Package gitremote provides general-purpose git remote URL utilities: parsing, resolving, and redacting remote URLs.
Package gitremote provides general-purpose git remote URL utilities: parsing, resolving, and redacting remote URLs.
interactive
Package interactive provides TTY-related helpers shared between the cli and strategy packages without inducing an import cycle (strategy cannot import cli).
Package interactive provides TTY-related helpers shared between the cli and strategy packages without inducing an import cycle (strategy cannot import cli).
internal/flock
Package flock provides a small cross-process advisory-lock primitive built on POSIX flock (Unix) / LockFileEx (Windows).
Package flock provides a small cross-process advisory-lock primitive built on POSIX flock (Unix) / LockFileEx (Windows).
investigate
Package investigate contains the env-var contract between `entire investigate` (which spawns the agent process) and the lifecycle hook (which adopts the session), plus the persisted run state for resuming an investigation.
Package investigate contains the env-var contract between `entire investigate` (which spawns the agent process) and the lifecycle hook (which adopts the session), plus the persisted run state for resuming an investigation.
jsonutil
Package jsonutil provides JSON utilities with consistent formatting.
Package jsonutil provides JSON utilities with consistent formatting.
lockfile
Package lockfile provides cross-process file locks.
Package lockfile provides cross-process file locks.
logging
Package logging provides structured logging for the Trace CLI using slog.
Package logging provides structured logging for the Trace CLI using slog.
mdrender
Package mdrender renders markdown to terminal-styled output using the shared trace CLI palette (orange H1, cyan H2, indigo H3, plus chroma syntax highlighting).
Package mdrender renders markdown to terminal-styled output using the shared trace CLI palette (orange H1, cyan H2, indigo H3, plus chroma syntax highlighting).
osroot
Package osroot provides traversal-resistant file I/O helpers built on os.Root (Go 1.24+).
Package osroot provides traversal-resistant file I/O helpers built on os.Root (Go 1.24+).
provenance
Package provenance owns the env-var contract that lets the lifecycle hook recognize a spawned agent process as part of `entire review` or `entire investigate`.
Package provenance owns the env-var contract that lets the lifecycle hook recognize a spawned agent process as part of `entire review` or `entire investigate`.
recap
Package recap contains the server-backed data types and static renderer behind `trace recap`.
Package recap contains the server-backed data types and static renderer behind `trace recap`.
review
Package review — see env.go for package-level rationale.
Package review — see env.go for package-level rationale.
review/types
Package types defines the per-agent abstraction interfaces for `trace review`.
Package types defines the per-agent abstraction interfaces for `trace review`.
search
Package search provides search functionality via the Trace search service.
Package search provides search functionality via the Trace search service.
settings
Package settings provides configuration loading for Trace.
Package settings provides configuration loading for Trace.
strategy
Package strategy provides the manual-commit strategy for managing Claude Code session changes via shadow branches and checkpoint condensation.
Package strategy provides the manual-commit strategy for managing Claude Code session changes via shadow branches and checkpoint condensation.
stringutil
Package stringutil provides UTF-8 safe string manipulation utilities.
Package stringutil provides UTF-8 safe string manipulation utilities.
summarize
Package summarize provides AI-powered summarization of development sessions.
Package summarize provides AI-powered summarization of development sessions.
testutil
Package testutil provides shared test utilities for both integration and e2e tests.
Package testutil provides shared test utilities for both integration and e2e tests.
trail
Package trail provides types and helpers for managing trail metadata.
Package trail provides types and helpers for managing trail metadata.
trailers
Package trailers provides parsing and formatting for Trace commit message trailers.
Package trailers provides parsing and formatting for Trace commit message trailers.
transcript
Package transcript provides shared types and utilities for parsing JSONL transcripts.
Package transcript provides shared types and utilities for parsing JSONL transcripts.
transcript/compact
Package compact converts full.jsonl transcripts into a normalized, compact transcript.jsonl format.
Package compact converts full.jsonl transcripts into a normalized, compact transcript.jsonl format.
tuiutil
Package tuiutil hosts width-aware text helpers for fixed-width TUI dashboards: ANSI/control-char stripping, display-width-based truncation and padding, and a compact duration formatter.
Package tuiutil hosts width-aware text helpers for fixed-width TUI dashboards: ANSI/control-char stripping, display-width-based truncation and padding, and a compact duration formatter.
uiform
Package uiform builds huh forms wired to Trace's standard theme and accessibility behavior.
Package uiform builds huh forms wired to Trace's standard theme and accessibility behavior.
validation
Package validation provides input validation functions for the Trace CLI.
Package validation provides input validation functions for the Trace CLI.
versioninfo
Package versioninfo exposes the trace CLI version metadata.
Package versioninfo exposes the trace CLI version metadata.
webhook
Package webhook delivers best-effort HTTP notifications on Trace session lifecycle events.
Package webhook delivers best-effort HTTP notifications on Trace session lifecycle events.
cmd
trace command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL