codeintel-cli

Original:🇨🇳 Chinese
Translated

Use the codeintel command-line tool: intelligent indexing and field trace query for Go codebases. Features include building indexes (init), querying symbol/field read-write summaries (query fields), field tracing (trace-backward/forward), full-chain data value tracing (value-trace), call relationship analysis (callers/callees/impact), export (export), and Web service (serve). This skill is used when users request to analyze field data flows in Go codebases, trace field users/producers, check function field read-write operations, or query call relationships.

7installs
Added on

NPX Install

npx skill4agent add schaepher/codeintel codeintel-cli

SKILL.md Content (Chinese)

View Translation Comparison →

codeintel CLI User Guide

codeintel is an intelligent indexing tool for Go codebases (SSA field tracing), with output stored in SQLite (
.codeintel/codeintel.db
). Repository module:
github.com/schaepher/codeintel
.

Build and Installation

bash
# Build within the codeintel repository
go build -o codeintel ./cmd/codeintel
# Or install to GOBIN
make install

Command Quick Reference

bash
codeintel init --repo <path>               # Full index build (requires go.mod; will prompt to enter module directory at go.work root)
codeintel update --repo <path>             # Incremental update (git detects changed files, full analysis + incremental write)
codeintel serve --repo <path> --addr :8096 # Start graph exploration Web service (frontend AntV G6, default port :8090)
codeintel query <sub> ... --repo <path>    # Query (see below; all subcommands support --json / --compact)
codeintel export --repo <path> [--out x.json]  # Export field double-layer index JSON (field → producer/consumer)
codeintel export graph --type value-trace|callees|lifecycle --target <node> [--format mermaid|dot] [--out file]
                                           # Graph export: value-trace defaults to mermaid (function grouping), callees defaults to dot,
                                           # lifecycle diagram ([storage]/[observation]/[read]/[write] + condition annotations)
codeintel clean --repo <path> --force      # Delete index (must clean + init rebuild after schema changes)
codeintel version

query Subcommands

SubcommandPurposeKey Parameters
symbol <sym>
Symbol details (including callers/callees)
fields <func>
Function field read-write summary (direct_read/write + indirect_write)
trace-backward <field> --func <func>
Reverse trace of field production points
--max-depth N
default 8
trace-forward <field> --func <func>
Forward trace of subsequent field usage
--max-depth N
value-trace <nodeID>
Full chain of data values (cross-function, grouped by function context)
--max-depth N
callers/callees <sym>
Callers/callees
--depth N
default 1
impact <sym>
Impact analysis
--depth N
default 3
summary <node>
Cross-layer summary: main chain of entry → compute → write → consume (each step with file:line)
--format mermaid
  • All query subcommands support
    --json
    (structured output) and
    --compact
    (no indentation)
  • Logs are written to
    .codeintel/codeintel.log
    (same directory as db), only query results are kept in stdout
  • <sym>
    accepts canonical ID (
    symbol:go:<pkg>:<name>
    , method
    (T).m
    ) or name (reports error and lists candidates if multiple matches)
  • <field>
    is a type-qualified path (e.g.,
    example.com/app/internal/agent.Config.APIKey
    )
  • <nodeID>
    is a complete node ID (e.g.,
    symbol:go:...:(Manager).Run#m.cfg.APIKey.read@47
    )

Real-world Examples

Take a Go repository (module
example.com/app
, with the
m.cfg.APIKey
field of an LLM agent) as an example:
bash
# 1. Build index (first time or after schema changes)
codeintel init --repo <target-repo>

# 2. Function field read-write summary (after verification, you can see [direct_read]/[direct_write]/[indirect_write] groups)
codeintel query fields "(Manager).Run" --repo <target-repo>

# 3. Forward trace of field users
codeintel query trace-forward example.com/app/internal/agent.Config.APIKey \
  --func "(Manager).Run" --repo <target-repo>

# 4. Full chain of data values (cross-function): first query node ID, then trace
sqlite3 <target-repo>/.codeintel/codeintel.db \
  "SELECT id FROM nodes WHERE kind='field_access' AND json_extract(properties,'\$.instance_path')='m.cfg.APIKey' LIMIT 1"
codeintel query value-trace "<ID obtained above>" --repo <target-repo>

Output Interpretation

  • fields summary:
    [direct_read]
    reads fields,
    [direct_write]
    writes fields,
    [indirect_write]
    writes indirectly via aliases/call closures (e.g.,
    m.mu :55 m.mu.Lock()
    ). The summary table deduplicates by field UNIQUE (only the first line is listed for multiple accesses to the same field), details are in graph nodes
  • value-trace: grouped by
    【function name】
    + indented tree,
    ←
    production chain (reverse),
    →
    usage chain (forward), edge types (data_flows_to/argument/returns/phi_operand),
    [read]/[write]
    markers and line numbers
  • Intermediate layers of read chains (e.g., inner layer
    m.cfg
    of
    m.cfg.APIKey
    ) are marked as read instead of write;
    []T{...}
    literal initialization does not generate element nodes
  • Path conditions: trace lines may include
    [condition: ...]
    (if/type branch/env, calculated during query)
  • Dynamic dispatch: symbol interface types show candidate implementations (
    [register 0.9]
    /
    [enum 0.7]
    + registration points)
  • Persistence: SQL writes are mapped to
    users.name
    virtual nodes (field → table.column, visible via value-trace)
  • Global traceability: global variables share nodes across functions (
    var.<name>
    ), value-trace can reach initialization expressions
  • Cross-layer summary:
    query summary <node>
    outputs the main lifecycle chain (entry/compute/write/consume)

Verification and Notes

  • Change verification matrix:
    make test
    (unit),
    make it
    (integration, requires scip-go),
    make e2e
    (22 playwright cases, port 8096, specify verification repository with
    E2E_REPO=<repo>
    )
  • No automatic schema migration (user_version=2): after schema changes, verification repositories must run
    clean --force
    +
    init
    to rebuild, otherwise version mismatch error will occur
  • Push to git after each modification and verification (user agreement)
  • Logs: zap + OTel writes to
    .codeintel/codeintel.log
    (main rough parsing --repo passed to Setup); debug logs with --verbose are also in the file; stdout only contains query results
  • Pitfall:
    pkill -f "codeintel-e2e serve"
    will match its own command line and kill itself (use
    pgrep -x codeintel-e2e
    + kill)
  • Index query has no network dependencies; build requires
    go
    and optional
    scip-go
    (scip adapter degrades and skips if missing)