cpk code
cpk code queries the index populated by cpk scan. Four subcommands cover the 90% of exploration tasks an agent needs: finding symbols, tracing imports, impact analysis, and getting an overview.
These commands work offline. They read .codepakt/data.db directly — no server daemon required.
Prerequisites
Run cpk scan at least once before querying. If cpk code summary shows files_scanned: 0, the index is empty.
cpk code summary
Project overview: file count, symbol counts by kind, languages detected, last scan time.
cpk code summary
{
"files_scanned": 223,
"symbols_count": 958,
"imports_count": 1223,
"by_kind": {
"class": 245,
"function": 9,
"interface": 21,
"method": 673,
"type": 4,
"variable": 6
},
"by_language": {
"typescript": 222,
"javascript": 1
},
"last_scan": "2026-04-09 08:21:13"
}
Use this first when landing in an unfamiliar codebase. The by_kind breakdown tells you the shape of the code at a glance (e.g., a NestJS project shows lots of classes + methods; a functional TypeScript library shows lots of functions + types).
cpk code symbols
Find symbols by name, kind, file prefix, or export status. All filters combine (AND).
# Find by name (LIKE match — partial names work)
cpk code symbols --name AuthService
# All symbols of a specific kind
cpk code symbols --kind class
cpk code symbols --kind function
cpk code symbols --kind interface
# All symbols in a file or directory (prefix match)
cpk code symbols --file src/auth/
cpk code symbols --file src/server/routes/tasks.ts
# Only exported symbols
cpk code symbols --exported
# Combine filters
cpk code symbols --kind class --file src/services/
cpk code symbols --name Controller --kind class --exported
Example output:
[
{
"name": "AuthService",
"kind": "class",
"file": "src/auth/auth.service.ts",
"line": 18,
"exported": true,
"parent": null,
"signature": "class AuthService { constructor( private jwtService: JwtService, private config: ConfigService, ) {} async login(...) { ... } }"
},
{
"name": "login",
"kind": "method",
"file": "src/auth/auth.service.ts",
"line": 42,
"exported": false,
"parent": "AuthService",
"signature": "async login(email: string, password: string): Promise<LoginResult> { ... }"
}
]
Flags:
| Flag | Description |
|---|---|
-n, --name <name> | Match on symbol name (LIKE %name%) |
-k, --kind <kind> | function, class, interface, type, method, variable |
-f, --file <path> | File path or directory prefix |
--exported | Only exported symbols |
-l, --limit <n> | Max results (default: 100, max: 500) |
--human | Human-readable output |
cpk code imports
Show what a file imports. Answers “where does this function come from?” without reading the file.
cpk code imports --file src/auth/auth.service.ts
[
{ "importer": "src/auth/auth.service.ts", "imported": "@nestjs/common", "names": ["Injectable", "Logger"] },
{ "importer": "src/auth/auth.service.ts", "imported": "@nestjs/jwt", "names": ["JwtService"] },
{ "importer": "src/auth/auth.service.ts", "imported": "src/users/users.service", "names": ["UsersService"] },
{ "importer": "src/auth/auth.service.ts", "imported": "bcrypt", "names": ["compare", "hash"] }
]
Relative paths (./users/users.service) are resolved to project-relative paths. Bare module names (@nestjs/common, bcrypt) are preserved as-is.
cpk code dependents
Impact analysis — show which files import a given file. Use this before changing a shared file to understand the blast radius.
cpk code dependents --file src/shared/types.ts
[
{ "importer": "src/auth/auth.service.ts", "imported": "src/shared/types", "names": ["User", "LoginResult"] },
{ "importer": "src/server/routes/tasks.ts", "imported": "src/shared/types", "names": ["Task", "TaskStatus"] },
{ "importer": "src/cli/api-client.ts", "imported": "src/shared/types", "names": ["Task", "Agent", "CodeSymbol"] }
]
Matches both ./shared/types and ./shared/types.js/.ts variants. If you’re about to refactor types.ts, this list tells you exactly which files to check.
When to use what
| Question | Command |
|---|---|
”Where is AuthService defined?” | cpk code symbols --name AuthService |
| ”What classes exist in the auth module?” | cpk code symbols --kind class --file src/auth/ |
”Does this codebase already have a normalizeEmail helper?” | cpk code symbols --name normalize |
| ”What does this service import from?” | cpk code imports --file src/.../service.ts |
| ”What breaks if I change this file?” | cpk code dependents --file src/.../file.ts |
| ”What’s the overall shape of this project?” | cpk code summary |
| ”Show me all exported types” | cpk code symbols --kind type --exported |
Offline mode
cpk code * bypasses the HTTP server entirely. The commands:
- Read the project ID from
.codepakt/config.json - Look up the DB path from
~/.codepakt/index.json - Open
.codepakt/data.dbdirectly with better-sqlite3 - Run the query and print JSON
If the server is running, queries still work the same way — they just don’t go through HTTP. If the server is stopped, queries still work. The daemon only matters for task coordination.
Related
- cpk scan — build or refresh the index
- Architecture — how the index is stored and queried