Help us improve
Share bugs, ideas, or general feedback.
From bms
Comprehensive C-AL performance analyzer for Classic Microsoft Dynamics NAV (Navision). Targets Classic NAV anti-patterns: N+1 queries, LOCKTABLE overuse, FlowField overuse, key/index misalignment, heavy transactions, and page trigger abuse. Zero-dependency Python — no packages required. Use when the user asks about analyzing codeunits, tables, or pages, finding performance bottlenecks, locking/blocking issues, or optimizing Classic NAV / C-AL code. Trigger: "/codeunit-analyzer", "analyze codeunit", "scan bottlenecks", "performance issues".
npx claudepluginhub bmsuisse/skills --plugin writingHow this skill is triggered — by the user, by Claude, or both
Slash command
/bms:codeunit-analyzerThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> [!IMPORTANT]
Provides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Guides systematic root-cause debugging when tests fail, builds break, or unexpected errors occur. Provides a structured triage checklist to preserve evidence, localize, and fix issues instead of guessing.
Share bugs, ideas, or general feedback.
[!IMPORTANT] This tool targets Classic Microsoft Dynamics NAV (C-AL). It is NOT for Business Central AL.
SETLOADFIELDSdoes not exist in Classic NAV — use thesetloadfieldssub-command only if you have explicitly migrated to Business Central.
Zero-dependency C-AL analysis tool using only Python standard library. Focuses on Classic NAV performance patterns.
[!CAUTION] This skill is strictly read-only. It must never write to, overwrite, or modify any codeunit, table, or page source file (
.cs,.c-al, or any other AL file).Allowed actions:
- Print a report to the console.
- Save findings to a separate output/report file (JSON, Markdown, etc.).
- If the user explicitly asks to apply a fix, copy the file first (e.g.,
<name>.patched.cs) and modify only the copy — never the original.If a user asks to "fix" or "update" a codeunit, always confirm whether they want:
- A report with suggested code changes (default), or
- A copy of the file with the fix applied.
Never silently change source files.
List all available .cs and .c-al files in the workspace.
Analyze a specific codeunit with bottleneck detection and dependency extraction.
Scan all codeunits for performance issues and generate ranked report.
Get actionable refactoring suggestions with code examples.
Dedicated audit that finds every FINDSET, FINDFIRST, FIND, FINDLAST, or GET without
SETLOADFIELDS and ranks them by urgency score — combining:
SELECT *; pinning
fields with SETLOADFIELDS skips those expensive sub-queries entirely.The table metadata JSON files can optionally include field_count (int) and has_flow_fields
(bool) to enable precise scoring. If absent, the analyzer falls back to neutral multipliers.
Before any command, resolve two things: the Python executable and the codeunits, tables, or pages directories. Do both in one shot:
# 1. Find Python
PYTHON=$(command -v python3 || command -v python || echo "uv run python")
$PYTHON --version || { echo "Python not found. Install via: brew install python OR uv python install 3.12"; exit 1; }
# 2. Find the SKILL path
SKILL="$(dirname "$(dirname "$(find . -path '*codeunit-analyzer/scripts/analyze.py' | head -1)")")"
# 3. Find the codeunits, tables, or pages directories — check common locations
CODEUNITS_DIR=$(
for candidate in codeunits data/codeunits src/codeunits .agents/data/codeunits; do
[ -d "$candidate" ] && { echo "$candidate"; break; }
done
)
# 4. If not found, search from project root
if [ -z "$CODEUNITS_DIR" ]; then
CODEUNITS_DIR=$(find . -name "*.c-al" -o -name "*.cs" 2>/dev/null | head -1 | xargs dirname 2>/dev/null)
fi
# 5. Export so the script picks it up automatically
export CODEUNITS_DIR
echo "Python : $PYTHON"
echo "Skill : $SKILL/scripts/analyze.py"
echo "Codeunits: $CODEUNITS_DIR"
If
CODEUNITS_DIRis still empty, ask the user where their.cs/.c-alfiles are and set it manually:export CODEUNITS_DIR=/path/to/codeunits
With those three variables set, all commands become:
$PYTHON $SKILL/scripts/analyze.py list
$PYTHON $SKILL/scripts/analyze.py scan
$PYTHON $SKILL/scripts/analyze.py analyze <file>
No setup required beyond the pre-flight above.
# List all available codeunits
$PYTHON $SKILL/scripts/analyze.py list
# Analyze a specific codeunit
$PYTHON $SKILL/scripts/analyze.py analyze 1.cs
# Scan all codeunits for bottlenecks
$PYTHON $SKILL/scripts/analyze.py scan
# Save scan results to file
$PYTHON $SKILL/scripts/analyze.py scan -o bottlenecks.json
# Get optimization suggestions
$PYTHON $SKILL/scripts/analyze.py optimize 80.cs
# SETLOADFIELDS audit — project-wide (ranked by urgency)
$PYTHON $SKILL/scripts/analyze.py setloadfields
# SETLOADFIELDS audit — single file
$PYTHON $SKILL/scripts/analyze.py setloadfields 80.cs
# SETLOADFIELDS audit — save JSON, show top 10 tables
$PYTHON $SKILL/scripts/analyze.py setloadfields --top 10 -o slf_report.json
User says:
Action:
$PYTHON $SKILL/scripts/analyze.py list
Output: Table showing: File name | Object name | ID
User says:
Action:
$PYTHON $SKILL/scripts/analyze.py analyze <filename>
Steps:
list firstoptimizeOutput includes:
User says:
Action:
$PYTHON $SKILL/scripts/analyze.py scan
Save to JSON:
$PYTHON $SKILL/scripts/analyze.py scan -o bottlenecks_$(date +%Y%m%d).json
Steps:
Output includes:
User says:
Action:
$PYTHON $SKILL/scripts/analyze.py optimize <filename>
Steps:
Output includes:
User says:
Action (project-wide):
python .skills/codeunit-analyzer/scripts/analyze.py setloadfields
Action (single file):
python .skills/codeunit-analyzer/scripts/analyze.py setloadfields <filename>
Flags:
--top N — show only the N most urgent tables--json — output raw JSON-o <file> — save findings to a JSON fileOutput includes:
Scenario 1: User invokes with just "list"
User: /codeunit-analyzer list
→ Run: $PYTHON $SKILL/scripts/analyze.py list
→ Show table of all codeunits
Scenario 2: User wants to analyze but doesn't specify file
User: /codeunit-analyzer analyze
→ Run list first to show options
→ Ask: "Which file would you like to analyze?"
→ User selects file
→ Run: $PYTHON $SKILL/scripts/analyze.py analyze <selected_file>
Scenario 3: User provides filename directly
User: /codeunit-analyzer analyze 1.cs
→ Run: $PYTHON $SKILL/scripts/analyze.py analyze 1.cs
→ Display results immediately
Scenario 4: Generic request
User: "Find performance issues"
→ Infer command: scan
→ Run: $PYTHON $SKILL/scripts/analyze.py scan
The script detects these Classic NAV performance anti-patterns:
[!NOTE] Patterns are grouped by how they manifest in Classic NAV.
SETLOADFIELDS(Business Central only) is intentionally excluded from the main scan.
Database queries inside loops causing massive slowdown.
Example:
// ❌ Bad: Queries database for each iteration
REPEAT
Customer.GET(SalesLine."Sell-to Customer No.");
...
UNTIL SalesLine.NEXT = 0;
// ✅ Good: Query once, process in memory
Customer.GET(SalesHeader."Sell-to Customer No.");
REPEAT
...
UNTIL SalesLine.NEXT = 0;
Manual transaction commits that break rollback behavior.
Example:
// ❌ Bad: Breaks automatic rollback
IF Customer.INSERT THEN BEGIN
COMMIT; // Don't do this!
MESSAGE('Customer created');
END;
// ✅ Good: Let NAV handle transactions
IF Customer.INSERT THEN BEGIN
MESSAGE('Customer created');
END;
Database writes inside nested loops.
Example:
// ❌ Bad: Write operation in nested loop
REPEAT
ItemEntry.SETRANGE("Item No.", SalesLine."No.");
IF ItemEntry.FINDSET THEN
REPEAT
ItemEntry.Processed := TRUE;
ItemEntry.MODIFY; // Slow!
UNTIL ItemEntry.NEXT = 0;
UNTIL SalesLine.NEXT = 0;
// ✅ Good: Use bulk operations
REPEAT
ItemEntry.SETRANGE("Item No.", SalesLine."No.");
ItemEntry.MODIFYALL(Processed, TRUE); // Fast!
UNTIL SalesLine.NEXT = 0;
Too many individual write operations (>10 per codeunit).
Recommendation: Batch operations or use MODIFYALL/DELETEALL.
Too many database calls inside REPEAT...UNTIL blocks — the single biggest
Classic NAV performance killer.
Classic NAV uses page-level locking. LOCKTABLE inside a loop holds the lock
for every iteration, blocking all concurrent users.
Example:
// ❌ Bad: lock held for entire loop
REPEAT
Table.LOCKTABLE;
Table.MODIFY;
UNTIL Table.NEXT = 0;
// ✅ Good: acquire once
Table.LOCKTABLE;
IF Table.FINDSET THEN
REPEAT Table.MODIFY; UNTIL Table.NEXT = 0;
Each CALCFIELDS issues a separate SQL sub-query. 4+ calls in one procedure
without caching is a Classic NAV sign of denormalisation or missing local variables.
Example:
// ❌ Bad: 4 separate sub-queries
Cust.CALCFIELDS(Balance);
Cust.CALCFIELDS('Sales (LCY)');
Cust.CALCFIELDS('Profit (LCY)');
Cust.CALCFIELDS('Balance Due');
// ✅ Good: one batched call + cache in variables
Cust.CALCFIELDS(Balance, 'Sales (LCY)', 'Profit (LCY)', 'Balance Due');
BalanceDue := Cust.'Balance Due';
Classic NAV table reads must follow the defined key order. Filtering on a non-leading key field causes a full table scan. The detector flags single-field SETRANGE filters on large tables as potential key misalignments.
Example:
// ❌ Bad: key is 'Document Type, No.' but we skip the first field
Line.SETRANGE('No.', DocNo); // full scan!
// ✅ Good: lead with the primary key field
Line.SETRANGE('Document Type', DocType);
Line.SETRANGE('No.', DocNo);
IF Line.FINDSET THEN ...
================================================================================
[1] [CRITICAL] - N Plus One Query
================================================================================
Procedure: PostSalesOrder
Score: 150 points
Issue:
Database query inside loop - causes N+1 query problem
Recommendation:
Load all records at once using FINDSET, then process in memory
Code Example:
// Use FINDSET outside loop
IF Table.FINDSET THEN
REPEAT
// Process here
UNTIL Table.NEXT = 0;
[
{
"pattern": "n_plus_one_query",
"severity": "critical",
"score": 150,
"procedure": "PostSalesOrder",
"explanation": "Database query inside loop - causes N+1 query problem",
"recommendation": "Load all records at once using FINDSET",
"example": "// Use FINDSET outside loop\nIF Table.FINDSET THEN...",
"codeunit": {
"file": "80.cs",
"object_name": "Sales-Post",
"object_id": "80"
}
}
]
OneTrade/
├── scripts/
│ └── analyze.py # Standalone script (zero deps)
├── data/
│ └── codeunits/ # Your .cs/.c-al files
└── .skills/
└── codeunit-analyzer/ # This skill
That's it! No requirements.txt, no pip install, no virtual environment.
1. No codeunits found
Error: No codeunits found.
Expected directory: c:\Users\...\data\codeunits
Solution: Create the data directory and add your .cs or .c-al files.
2. File not found
Error: FileNotFoundError: '80.cs'
Solution: Run $PYTHON $SKILL/scripts/analyze.py list to see available files.
3. No bottlenecks detected
[OK] No bottlenecks detected - this codeunit is already optimized!
Solution: Great news! No action needed.
The analyzer incorporates advanced source-correlated checks natively adopted from al-perf:
setloadfields sub-command when explicitly targeting BC. Not triggered in the standard scan. Navision defaults to SELECT * across the network, bloating the buffer.FINDSET operations lacking SETRANGE or SETFILTER, severely impacting SQL Server memory caching by pulling entire tables.[EventSubscriber] procedures containing data-loops or heavy read operations. Because Navision Event Subscribers run globally and synchronously, any blocked loop here degrades the entire ERP execution context.Check Python version:
python --version # Should be 3.10+
Run from project root:
$PYTHON $SKILL/scripts/analyze.py list
Check data directory:
ls data/codeunits/*.cs | wc -l
If empty, add your C-AL files to data/codeunits/.
chmod +x scripts/analyze.py
$PYTHON $SKILL/scripts/analyze.py list
Note: No caching implemented yet - each run re-parses files. This keeps the code simple and dependency-free.
python .skills/codeunit-analyzer/scripts/scripts/analyze.py list
Output:
Found 2414 codeunits:
File Object Name ID
==================================================================================
1.cs ApplicationManagement 1
80.cs Sales-Post 80
...
$PYTHON $SKILL/scripts/analyze.py analyze 80.cs
Output:
================================================================================
CODEUNIT: Sales-Post
================================================================================
ID: 80
Procedures: 15
File: 80.cs
================================================================================
PERFORMANCE BOTTLENECKS (5 issues)
================================================================================
Critical: 2
High: 2
Medium: 1
[Detailed bottleneck information follows...]
$PYTHON $SKILL/scripts/analyze.py scan -o scan_results.json
Output:
================================================================================
BOTTLENECK SCAN SUMMARY
================================================================================
Total Issues: 147
Critical: 23
High: 45
Medium: 67
Low: 12
================================================================================
TOP OFFENDERS (by total score)
================================================================================
1. Sales-Post (80.cs)
Issues: 12 | Critical: 3 | High: 5 | Medium: 4
Total Score: 850 points
[Top 10 worst codeunits listed...]
Full report saved to: scan_results.json
This is a simplified parser using regex. It may not detect:
For production use, consider the full analysis service with Pydantic schemas and comprehensive parsing.
| Feature | Standalone Script | Full Service |
|---|---|---|
| Dependencies | None | Pydantic, Cashews, etc. |
| Setup | Zero | Virtual env + pip install |
| Speed | Fast | Faster (cached) |
| Accuracy | Good (regex) | Excellent (full parser) |
| Offline | ✅ Yes | ✅ Yes |
| Table metadata | ❌ No | ✅ Yes |
| AI explanations | ❌ No | ✅ Yes (with Azure) |
| Best for | Quick analysis | Production use |
Use standalone for: Quick scans, CI/CD, no-dependency environments Use full service for: Detailed analysis, AI insights, production workflows
When the user asks for a PDF or Word document of the analysis results, use the dedicated community skills instead of building your own export:
| Format | Skill | Install |
|---|---|---|
| Word (.docx) | docx | https://skills.sh/anthropics/skills/docx |
| PDF (.pdf) | pdf | https://skills.sh/anthropics/skills/pdf |
Workflow:
--json or pipe to a file).docx or pdf skill to format and export.Trigger phrases that should prompt you to suggest / use these skills:
Ready to use! No installation, no dependencies, just Python. 🚀
Heavy queries (GET >= 3), nested database writes (MODIFY), or PAGE.RUN calls inside OnAfterGetRecord and similar UI rendering triggers.
Recommendation: Cache records inside Temp tables or run heavy logic exclusively via user-explicit OnAction events.