GitHub 1
Skip to content

Hooks and MCP servers

Start syncs from agent sessions, sync MCP servers and agent hook files into each agent, and run your own commands after a sync.

Three features have "hook" or "MCP" in their name. They do different jobs and are set up in different places.

FeatureSet up withWhat it does
Session hooksfleetrc hook installStart a sync when a Claude Code or Codex session opens.
MCP serverssources[].mcpWrite MCP servers into each agent's config.
Hooks in the manifestsources[].agentHooks and hooksSync hook files into agents, or run your commands after a sync.

init adds a SessionStart hook to Claude Code and Codex. When a session opens, the hook starts a background sync. Nothing else in the manifest controls it.

fleetrc hook install            # each agent whose folder exists
fleetrc hook install codex      # one agent, creating its folder if needed
fleetrc hook remove
AgentFile
claude-codesettings.json in ~/.claude, or in CLAUDE_CONFIG_DIR
codexhooks.json in ~/.codex

Both commands keep your other hooks and fields, take --dry-run and --json, and exit 1 when a file does not parse. init --no-hooks skips the install, and so does fleet init --no-hooks on each host.

The hook runs fleetrc hook run <agent>. It reads the event from stdin, ignores anything but SessionStart, and starts fleetrc sync in the background only when:

  • no sync was attempted in the last 15 minutes, and
  • no sync is running.

The 15 minutes count from the last attempt, not the last success, so a sync that fails offline waits for the next window. The hook makes no network call, prints nothing and always exits 0, so it never blocks a session. The sync it starts logs to fleetrc-sync.log in the state folder's logs directory and runs with the PATH saved when you ran hook install, not the agent's.

fleetrc installs no prompt hook. An old UserPromptSubmit entry (fleetrc hook prompt) starts no sync. In Claude Code it only prints a line naming skills that arrived after the session began. hook install replaces these entries with the session hook, and doctor warns about them.

Note

Codex runs a new hook only after you approve it. Open /hooks in Codex once per machine and approve fleetrc's hook. Codex records approval with a hash of each hook, so fleetrc rewrites its own entry in place and leaves a no-op where it removes one that other hooks follow.

On a machine with no agent, such as a server, use the timer instead.

sources[].mcp is the path of a file in the source, in Claude Code's format. fleetrc writes each server into every agent's own config and removes it when you drop it from the file.

{
  "mcpServers": {
    "docs": {
      "command": "npx",
      "args": ["-y", "docs-mcp"],
      "env": { "DOCS_TOKEN": "${DOCS_TOKEN}" }
    },
    "search": {
      "type": "http",
      "url": "https://mcp.example.com",
      "headers": { "Authorization": "Bearer ${SEARCH_TOKEN}" }
    }
  }
}
mcp.json
{
  "sources": [{ "id": "personal", "git": "me/agent-config", "mcp": "mcp.json" }]
}
.fleetrc/manifest.json

A server is local (command, args, env, cwd) or remote (url, headers, type of http or sse). Add "agents": ["claude-code", "cursor"] to send it to fewer agents. The manifest's agents decides which agents get servers at all, from Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Grok and OpenCode.

Write secrets as ${VAR} and set VAR where each agent starts. fleetrc translates the reference into each agent's syntax, such as ${env:VAR} for Cursor and {env:VAR} for OpenCode. A literal value in a header, or in an env key that contains TOKEN, KEY, SECRET, PASSWORD or AUTH, fails that server and syncs the others.

An agent that cannot take a server as written skips it with the reason. Codex reads a variable only as a whole value, so "Authorization": "Bearer ${SEARCH_TOKEN}" works there and "--token=${TOKEN}" does not.

If you edit a synced entry by hand, the next sync holds it as it is and says so. Compare it with the manifest's version:

fleetrc diff mcp/claude-code/docs

Delete the held entry in the agent's config to take the manifest's. A server of the same name that fleetrc did not write is left alone and reported as foreign.

sources[].agentHooks syncs hook definitions into agents, in each agent's own format. A string path is a Claude Code file. An object gives a path per agent: claude-code, codex, grok, gemini-cli or cursor.

{
  "sources": [
    {
      "id": "personal",
      "git": "me/agent-config",
      "agentHooks": { "claude-code": "hooks/claude.json", "codex": "hooks/codex.json" }
    }
  ]
}
.fleetrc/manifest.json

fleetrc translates nothing here. Claude Code's hooks go into a plugin at ~/.claude/skills/fleetrc, so a skill named fleetrc is refused. Codex's go into hooks.json, Grok's into ~/.grok/hooks, Gemini CLI's into settings.json and Cursor's into hooks.json, each beside your own. As with MCP, a hand-edited entry is held. In Codex, a new or changed group waits for approval in /hooks, and sync says so with a review: line.

The root manifest's hooks run shell commands after a sync that changed matching files.

{
  "hooks": [
    { "name": "pstack", "run": "node build.mjs", "on": ["personal:pstack/**"] }
  ]
}
.fleetrc/manifest.json
FieldMeaning
runThe shell command. Required.
nameNames the hook in the report. Defaults to run.
on<source id>:<glob> patterns, matched against paths from the source's root. Default: any change.

The command gets the sync report as JSON on stdin and two variables: FLEETRC_HOOK, the hook's name, and FLEETRC_CHANGED, the matched <source>:<file> lines, one per line. Output is kept in the report. A command that exits nonzero fails the sync, and one still running after 5 minutes is stopped.

mcp, agentHooks, hooks, fleet, hub and report run commands or name machines. A manifest you extend loses them, with a warning, so a team repository cannot run code on your machine.