# Repository Briefing: trailhq/Trail-Code
> Source: https://repoforai.com/repo/trailhq/Trail-Code (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/trailhq/Trail-Code
- **Official Docs / Website**: https://trailhq.com/trail-code
- **Category**: Coding, Skills & MCP (AI 编程 / Skills / MCP)
- **Primary Language**: TypeScript
- **License**: MIT
- **Engineering Health**: A (87/100 · Maintenance 35/35 · Adoption 21/25 · Releases 11/20 · License 20/20)
- **Review Snapshot**: 2026-12-02
- **Deployment / Stack Signals**: Docker, MCP, CLI, Local AI
- **Momentum**: 11,599 ★ total (+15 24h / +83 7d) · 1,039 forks
- **Topics**: `ai-agents`, `anthropic`, `claude-code`, `cli`, `code-graph`, `codex`, `context-engineering`, `cursor`, `developer-tools`, `gemini`, `knowledge-graph`, `llm`
- **When to Use**: Best for: Teams whose coding agents repeatedly trace cross-file dependencies and rediscover decisions already made in the same repository. Pilot on one representative repo, review the generated configuration and learnings, and compare push and pull on real tasks. Skip if: Search and a small instruction file already suffice, or your rollout requires a complete compiler-accurate call graph, centralized cross-repository memory today, or no client configuration changes.

## Overview
```text
### Architecture & Core Mechanics
Trail-code is a local TypeScript/Node.js CLI with an MCP tool interface and two separate stores. The graft map uses Tree-sitter to extract symbols, imports, and calls into linked Markdown under `graft/`. A query checks the working tree and rebuilds only what changed, including uncommitted edits. The map is disposable; durable decisions live in repository `.trail/` files or personal `~/.trail/` files. A normal checkout needs neither a database nor a background index server.

The manifest includes `tree-sitter-wasm` and `web-tree-sitter`, Commander for CLI argument handling, and `vscode-jsonrpc` plus `vscode-languageserver-protocol` for optional language-server integration. Claude Code hooks can supply relevant code at prompt time and surface dependents after an edit. MCP clients can instead request targeted symbol and file context on demand. The manifest also includes Anthropic and OpenAI SDKs; the default parsing path does not require a model or API key.

### Key Capabilities & Differentiators
Dedicated extractors provide scope-aware cross-file call and import resolution for TypeScript/JavaScript, Python, Go, Java, Kotlin, PHP, Swift, and R. The generic tier can emit symbols and name-matched call edges for languages such as Rust and C++; OCaml, Zig, GLSL, and Bash currently provide symbols without call edges. Vue, Svelte, and Astro script content goes through the TypeScript extractor. `trail build --lsp` can add more precise edges with language servers such as `rust-analyzer`, `clangd`, or `gopls`; `--deep` adds model-generated summaries under a configured provider key.

Agents can save corrections and decisions as learnings, and `trail check` can flag conflicts with recorded decisions before a PR. In a 162-run Claude Sonnet 5 benchmark across two repositories, upfront context cut mean cost from $0.0429 to $0.0292 and latency from 39.8 s to 15.8 s at 93% aggregate correctness, though one corpus lost three points. On-demand queries reached 98% correctness with less of the speed gain. A separate 50-issue SWE-bench Verified run solved 33 issues with the map versus 27 without it.

### Trade-offs & Limitations
Compared with grep and a hand-maintained `CLAUDE.md`, the map reduces repeated navigation across files and lets decision notes be reviewed alongside code. In return, teams maintain agent wiring and need to curate what gets treated as durable guidance. Static edges are useful for narrowing an investigation, not proving impact: name matching can be ambiguous, coverage varies by language, and opt-in LSP resolution adds local dependencies and processing. Use compiler or language-server results and tests when validating a risky refactor.

Upfront context saves retrieval turns but spends prompt budget before the agent knows what it needs. On-demand MCP queries avoid that upfront payload at the cost of more retrieval turns. The benchmark favors different modes on different metrics and is not a workload-independent estimate. Local indexing removes hosted-model cost from the default map, not from the coding agent or optional summaries. Review session-derived learnings before committing them: repository notes are visible to anyone with a clone. Cross-repository team workspaces are planned, not a current substitute for centralized governance.

### Hardware & Deployment Guide
The current quick start is `npm install -g @trailhq/trail-code`, then `trail init` from the repository. The supplied manifest still lists the legacy `@nanonets/graft` package and `graft` binary, with a Node.js engine range of `^20.16.0 || >=22.3.0`. The naming transition preserves the old package and command; `graft upgrade` adds `trail`. No GitHub release is listed, so there is no release milestone to pin the migration to. Use `trail init --dry-run` to inspect proposed agent wiring, and `--no-global` to avoid changes to user-level files. In particular, narrowing `--agents` can remove Trail-code wiring for clients left off the list.

Commit the intended team configuration and `.trail/` learnings, not the generated `graft/` cache. Personal mode keeps setup out of Git; the core workflow requires no model key or dedicated GPU. Optional LSP indexing needs a supported server on `PATH`, while deep summaries need provider credentials. The Dockerfile targets the GitHub App, not routine CLI/MCP setup. It needs Git at runtime to fetch PR refs and separates dependency installation from the project build to avoid invalidating the grammar build layer on source edits.
```

## Key Capabilities
```text
- Index storage: `graft/` is a regenerable cache of linked Markdown nodes; queries refresh changed inputs, including uncommitted edits.
- Resolution tiers: Language-specific extractors resolve scoped calls and imports; generic extractors use name matching, and some grammars emit symbols only.
- Agent integration: Hooks supply prompt-time context and post-edit dependency information where supported; MCP tools provide on-demand lookup.
- Memory boundaries: Repository learnings live in `.trail/` for sharing via Git, while personal learnings stay in `~/.trail/`.
- Optional enrichment: `trail build --lsp` adds language-server-resolved edges; `trail build --deep` adds provider-generated summaries.
- Benchmark trade-off: Across 162 runs on two repositories, push cut mean latency from 39.8 s to 15.8 s at the same 93% aggregate correctness; pull reached 98% with less of the speed gain.
```

## Quick Start / Clone
```bash
npm install -g @trailhq/trail-code && trail init
```
