code-context-graph — Annotation System
AI-driven annotation workflow for adding structured metadata to code. Annotations are indexed and searchable via FTS.
Subcommands
| Command |
Description |
Example |
annotate [file|dir] |
AI-generate annotations for code |
ccg annotate internal/analysis/ |
example [language] |
Show annotation writing example |
ccg example go |
tags |
Show all annotation tag reference |
ccg tags |
MCP Tools (1)
| Tool |
Description |
get_annotation |
Get annotation and doc tags for a specific node |
Available Tags
| Tag |
Purpose |
Example |
@index |
File/package description |
@index Payment processing service |
@intent |
Why this function exists |
@intent verify credentials before session creation |
@domainRule |
Business rule |
@domainRule lock account after 5 failures |
@sideEffect |
Side effects |
@sideEffect sends notification email |
@mutates |
State changes |
@mutates user.FailedAttempts, session.Token |
@requires |
Precondition |
@requires user.IsActive == true |
@ensures |
Postcondition |
@ensures session != nil |
@param |
Parameter description |
@param username the login ID |
@return |
Return description |
@return JWT token on success |
@see |
Related function |
@see SessionManager.Create |
AI Annotation Workflow
ccg annotate is NOT a CLI binary command — it is an AI-driven workflow executed by Claude.
When the user runs ccg annotate [file|dir], Claude should:
Step 1: Read target files
- If a file path is given, read that file
- If a directory is given, find all source files (
.go, .py, .ts, .java, etc.)
- Skip test files, vendor, node_modules
Step 2: Analyze each function/class/file
For each declaration, read the code and determine:
- What it does (→ summary line above declaration)
- Why it exists (→
@intent)
- Business rules it enforces (→
@domainRule)
- Side effects (→
@sideEffect: DB writes, API calls, file I/O, notifications)
- What state it changes (→
@mutates: fields, tables, caches)
- Prerequisites (→
@requires: auth, valid input, active state)
- Guarantees (→
@ensures: return conditions, post-state)
- File/package purpose (→
@index on package declaration)
Step 3: Write annotations
- Add annotations as comments directly above the declaration
- Use the language's comment syntax (
// for Go, # for Python, etc.)
- Do NOT overwrite existing annotations — only add missing ones
- Do NOT add trivial annotations (e.g.,
@intent returns the name for getName())
Step 4: Rebuild
Do not invoke /ccg-build automatically. Report that reindexing is pending and
that the user must explicitly name ccg-build in a new request.
Annotation Quality Rules
@intent should describe WHY, not WHAT (not "creates user" but "register new account for onboarding flow")
@domainRule should be specific business logic, not generic validation
@sideEffect only for actual side effects (DB, network, file, notification)
@index should summarize the module's responsibility in one line
- Skip getters/setters/trivial functions — annotate functions with business meaning
- Write annotations in the same language as existing code comments (Korean if Korean, English if English)
Example Output
// @index User authentication and session management service.
package auth
// AuthenticateUser validates credentials and creates a session.
// Called from login API handler.
//
// @param username user login ID
// @param password plaintext password (hashed internally)
// @return JWT token on success
// @intent verify user identity before granting system access
// @domainRule lock account after 5 consecutive failed attempts
// @domainRule locked accounts auto-unlock after 30 minutes
// @sideEffect writes login attempt to audit_log table
// @sideEffect sends security alert email on 3rd failed attempt
// @mutates user.FailedAttempts, user.LockedUntil, user.LastLoginAt
// @requires user.IsActive == true
// @ensures err == nil implies valid JWT with 24h expiry
func AuthenticateUser(username, password string) (string, error) {
Searching Annotations
Annotations are indexed in FTS and searchable via ccg search (see /ccg skill):
@intent — function purpose/goal
@domainRule — business rules
@sideEffect — side effects
@mutates — state changes
@index — file/package level description
Example: user asks "결제 관련 코드" → ccg search "결제" finds functions annotated with payment-related @intent/@domainRule.
1---2name: ccg-annotate-23description: code-context-graph — annotation system. AI-driven annotation workflow, tag reference, and annotation search.4---56# code-context-graph — Annotation System78AI-driven annotation workflow for adding structured metadata to code. Annotations are indexed and searchable via FTS.910## Subcommands1112| Command | Description | Example |13|---------|-------------|---------|14| `annotate [file\|dir]` | AI-generate annotations for code | `ccg annotate internal/analysis/` |15| `example [language]` | Show annotation writing example | `ccg example go` |16| `tags` | Show all annotation tag reference | `ccg tags` |1718## MCP Tools (1)1920| Tool | Description |21|------|-------------|22| `get_annotation` | Get annotation and doc tags for a specific node |2324## Available Tags2526| Tag | Purpose | Example |27|-----|---------|---------|28| `@index` | File/package description | `@index Payment processing service` |29| `@intent` | Why this function exists | `@intent verify credentials before session creation` |30| `@domainRule` | Business rule | `@domainRule lock account after 5 failures` |31| `@sideEffect` | Side effects | `@sideEffect sends notification email` |32| `@mutates` | State changes | `@mutates user.FailedAttempts, session.Token` |33| `@requires` | Precondition | `@requires user.IsActive == true` |34| `@ensures` | Postcondition | `@ensures session != nil` |35| `@param` | Parameter description | `@param username the login ID` |36| `@return` | Return description | `@return JWT token on success` |37| `@see` | Related function | `@see SessionManager.Create` |3839## AI Annotation Workflow4041`ccg annotate` is NOT a CLI binary command — it is an AI-driven workflow executed by Claude.4243When the user runs `ccg annotate [file|dir]`, Claude should:4445### Step 1: Read target files46- If a file path is given, read that file47- If a directory is given, find all source files (`.go`, `.py`, `.ts`, `.java`, etc.)48- Skip test files, vendor, node_modules4950### Step 2: Analyze each function/class/file51For each declaration, read the code and determine:52- **What it does** (→ summary line above declaration)53- **Why it exists** (→ `@intent`)54- **Business rules it enforces** (→ `@domainRule`)55- **Side effects** (→ `@sideEffect`: DB writes, API calls, file I/O, notifications)56- **What state it changes** (→ `@mutates`: fields, tables, caches)57- **Prerequisites** (→ `@requires`: auth, valid input, active state)58- **Guarantees** (→ `@ensures`: return conditions, post-state)59- **File/package purpose** (→ `@index` on package declaration)6061### Step 3: Write annotations62- Add annotations as comments directly above the declaration63- Use the language's comment syntax (`//` for Go, `#` for Python, etc.)64- Do NOT overwrite existing annotations — only add missing ones65- Do NOT add trivial annotations (e.g., `@intent returns the name` for `getName()`)6667### Step 4: Rebuild68Do not invoke `/ccg-build` automatically. Report that reindexing is pending and69that the user must explicitly name `ccg-build` in a new request.7071## Annotation Quality Rules7273- `@intent` should describe WHY, not WHAT (not "creates user" but "register new account for onboarding flow")74- `@domainRule` should be specific business logic, not generic validation75- `@sideEffect` only for actual side effects (DB, network, file, notification)76- `@index` should summarize the module's responsibility in one line77- Skip getters/setters/trivial functions — annotate functions with business meaning78- Write annotations in the same language as existing code comments (Korean if Korean, English if English)7980## Example Output8182```go83// @index User authentication and session management service.84package auth8586// AuthenticateUser validates credentials and creates a session.87// Called from login API handler.88//89// @param username user login ID90// @param password plaintext password (hashed internally)91// @return JWT token on success92// @intent verify user identity before granting system access93// @domainRule lock account after 5 consecutive failed attempts94// @domainRule locked accounts auto-unlock after 30 minutes95// @sideEffect writes login attempt to audit_log table96// @sideEffect sends security alert email on 3rd failed attempt97// @mutates user.FailedAttempts, user.LockedUntil, user.LastLoginAt98// @requires user.IsActive == true99// @ensures err == nil implies valid JWT with 24h expiry100func AuthenticateUser(username, password string) (string, error) {101```102103## Searching Annotations104105Annotations are indexed in FTS and searchable via `ccg search` (see `/ccg` skill):106- `@intent` — function purpose/goal107- `@domainRule` — business rules108- `@sideEffect` — side effects109- `@mutates` — state changes110- `@index` — file/package level description111112Example: user asks "결제 관련 코드" → `ccg search "결제"` finds functions annotated with payment-related @intent/@domainRule.