Skip to content

trace: never install agent hooks at the user level (home directory) #3812

Open

Description

@migmartri

Problem

Chainloop Trace installs agent hooks at the project level: each provider writes its hook file relative to the repository root (.claude/settings.json, .codex/hooks.json, .cursor/hooks.json, .github/hooks/chainloop-trace.json, .opencode/plugins/chainloop-trace.ts, .pi/extensions/chainloop-trace.ts).

But nothing stops that root from being the user's home directory. In that case Trace writes the agent's user-level configuration, and every session of that agent, in any project, loads the Chainloop hooks.

This can happen in two ways:

  1. chainloop trace run outside a git repository. When no repository is found, trace run uses the current working directory as the root (app/cli/cmd/trace_run.go) and still calls InstallHooksForTraceRun for each selected provider (app/cli/pkg/action/trace_run.go). Run from $HOME, it writes ~/.claude/settings.json, ~/.codex/hooks.json and ~/.cursor/hooks.json. The files are restored when the run exits, but:
    • while the run lasts, every other session of that agent picks up the hooks;
    • if the process is killed without cleanup (for example kill -9 or a crash), the hooks stay in the user-level file.
  2. $HOME is itself a git repository (for example a dotfiles repository). Both trace init and trace run then resolve the repository root to $HOME and install the hooks permanently (init) or temporarily (run) into the user-level files.

Proposal

Trace must never write agent hook files at the user level.

  • Before installing agent hooks, resolve the root (with symlinks evaluated) and compare it with the user's home directory. Also compare it with agent-specific home folders where they apply ($CODEX_HOME, $COPILOT_HOME).
  • If the root is the home directory:
    • trace init: fail with a clear error that tells the user to run it inside a project repository.
    • trace run: fail with a clear error, or skip installing agent hooks with a warning.
  • Add tests that cover both paths (no git repository with the working directory at $HOME, and a git repository rooted at $HOME).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions