Awesome-omni-skill copilot-log-analysis
Analyzing GitHub Copilot session log files to extract token usage, model information, and interaction data. Use when working with session files, understanding the extension's log analysis methods, or debugging token tracking issues.
git clone https://github.com/diegosouzapw/awesome-omni-skill
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/ai-agents/copilot-log-analysis" ~/.claude/skills/diegosouzapw-awesome-omni-skill-copilot-log-analysis && rm -rf "$T"
skills/ai-agents/copilot-log-analysis/SKILL.mdCopilot Log Analysis Skill
This skill documents the methods and approaches used by the GitHub Copilot Token Tracker extension to analyze Copilot session log files. These files contain chat sessions, token usage, and model information.
Overview
The extension analyzes two types of log files:
files: Standard VS Code Copilot Chat session files.json
files: Copilot CLI/Agent mode sessions (one JSON event per line).jsonl
Session File Discovery
Key Method: getCopilotSessionFiles()
getCopilotSessionFiles()Location:
src/extension.ts (lines 975-1073)
Helper Methods: getVSCodeUserPaths() (lines 934-972), scanDirectoryForSessionFiles() (lines 1078-1110)
This method discovers session files across all VS Code variants and locations:
Supported VS Code Variants:
- VS Code (Stable)
- VS Code Insiders
- VS Code Exploration
- VSCodium
- Cursor
- VS Code Server/Remote
File Locations Checked:
- Workspace Storage:
{VSCode User Path}/workspaceStorage/{workspace-id}/chatSessions/*.json - Global Storage (Legacy):
{VSCode User Path}/globalStorage/emptyWindowChatSessions/*.json - Copilot Chat Extension Storage:
{VSCode User Path}/globalStorage/github.copilot-chat/**/*.json - Copilot CLI Sessions:
~/.copilot/session-state/*.jsonl
Platform-Specific Paths:
- Windows:
%APPDATA%/{Variant}/User - macOS:
~/Library/Application Support/{Variant}/User - Linux:
(respects~/.config/{Variant}/User
)XDG_CONFIG_HOME - Remote/Server:
,~/.vscode-server/data/User~/.vscode-server-insiders/data/User
Helper Method: getVSCodeUserPaths()
getVSCodeUserPaths()Location:
src/extension.ts (lines 934-972)
Returns all possible VS Code user data paths for different variants and platforms.
Helper Method: scanDirectoryForSessionFiles()
scanDirectoryForSessionFiles()Location:
src/extension.ts (lines 1078-1110)
Recursively scans directories for
.json and .jsonl session files.
Field Extraction Methods
Parsing and Token Accounting: parseSessionFileContent()
parseSessionFileContent()Location:
src/sessionParser.ts (lines 184-347)
Purpose: Parses session files and returns tokens, interactions, model usage, and editor type-safe model IDs.
How it works:
- Accepts raw file content along with callbacks for token estimation and model detection.
- Supports both
(Copilot Chat) and.json
(CLI/agent) formats, including delta-based JSONL streams..jsonl - Counts interactions (user messages), input tokens, and output tokens while grouping by model.
- Uses
(lines 1139-1155 inestimateTokensFromText()
) for character-to-token estimation.src/extension.ts
Model Detection Logic: getModelFromRequest()
getModelFromRequest()Location:
src/extension.ts (lines 1102-1134)
- Primary:
request.result.metadata.modelId - Fallback: parses
for known model patternsrequest.result.details - Detected patterns: GPT-3.5-Turbo, GPT-4 family (4, 4.1, 4o, 4o-mini, 5, o3-mini, o4-mini), Claude Sonnet (3.5, 3.7, 4), Gemini (2.5 Pro, 3 Pro, 3 Pro Preview); defaults to
gpt-4 - Display name mapping in
(lines 1778-1811) adds variants such as GPT-5 family, Claude Haiku, Claude Opus, Gemini 3 Flash, Grok, and Raptor when present ingetModelDisplayName()
.metadata.modelId
Editor Type Detection: getEditorTypeFromPath()
getEditorTypeFromPath()Location:
src/extension.ts (lines 111-143)
Purpose: Determines which VS Code variant created the session file.
Detection patterns:
- Contains
→/.copilot/session-state/'Copilot CLI' - Contains
→/code - insiders/'VS Code Insiders' - Contains
→/code - exploration/'VS Code Exploration' - Contains
→/vscodium/'VSCodium' - Contains
→/cursor/'Cursor' - Contains
→.vscode-server-insiders/'VS Code Server (Insiders)' - Contains
→.vscode-server/'VS Code Server' - Contains
→/code/'VS Code' - Default →
'Unknown'
Token Estimation Algorithm
Character-to-Token Conversion: estimateTokensFromText()
estimateTokensFromText()Location:
src/extension.ts (lines 1139-1155)
Approach: Uses model-specific character-to-token ratios
- Default ratio: 0.25 (4 characters per token)
- Model-specific ratios loaded from
src/tokenEstimators.json - Formula:
Math.ceil(text.length * tokensPerChar)
Model matching:
- Checks if model name includes the key from tokenEstimators
- Example:
matches keygpt-4ogpt-4o
Caching Strategy
Cache Structure: SessionFileCache
SessionFileCacheLocation:
src/extension.ts (lines 72-77)
Stores pre-calculated tokens, interactions, model usage, and file mtime to avoid re-processing unchanged files.
Cache Methods:
(lines 227-230): Validates cached entry by mtimeisCacheValid()
(lines 232-234): Retrieves cached datagetCachedSessionData()
(lines 236-254): Stores data with FIFO eviction after 1000 filessetCachedSessionData()
(lines 250-264): Drops cache entries for missing filesclearExpiredCache()
(lines 811-845): Reads session content, parses viagetSessionFileDataCached()
, and caches resultsparseSessionFileContent()
Schema Documentation
Schema Files Location
Directory:
docs/logFilesSchema/
Key files:
: Manual curated schema with descriptionssession-file-schema.json
: Auto-generated field discovery (generated by PowerShell script)session-file-schema-analysis.json
: Complete guide for schema analysisREADME.md
: Quick reference guideSCHEMA-ANALYSIS.md
: VS Code variant detection documentationVSCODE-VARIANTS.md
Note: The analysis JSON file is auto-generated and may not exist in fresh clones. It is created by running the schema analysis script documented below.
Schema Analysis
See the Executable Scripts section for available utilities:
- Quick session file discoveryget-session-files.js
- Detailed diagnosticsdiagnose-session-files.js
- PowerShell schema analysisanalyze-session-schema.ps1
JSON File Structure (VS Code Sessions)
Primary fields used by extension:
{ "requests": [ { "message": { "parts": [ { "text": "user message content" } ] }, "response": [ { "value": "assistant response content" } ], "result": { "metadata": { "modelId": "gpt-4o" }, "details": "Used GPT-4o model" } } ] }
Key paths:
- Input tokens:
requests[].message.parts[].text - Output tokens:
requests[].response[].value - Model ID:
requests[].result.metadata.modelId - Model details:
requests[].result.details - Interaction count:
requests.length
JSONL File Structure (Copilot CLI)
Event types:
{"type": "user.message", "data": {"content": "..."}, "model": "gpt-4o"} {"type": "assistant.message", "data": {"content": "..."}} {"type": "tool.result", "data": {"output": "..."}}
Key fields:
- Event type:
type - User input:
(whendata.content
)type: 'user.message' - Assistant output:
(whendata.content
)type: 'assistant.message' - Tool output:
(whendata.output
)type: 'tool.result' - Model:
(optional, defaults tomodel
)gpt-4o
Pricing and Cost Calculation
Pricing Data
Location:
src/modelPricing.json
Contains per-million-token costs for input and output:
{ "pricing": { "gpt-4o": { "inputCostPerMillion": 1.75, "outputCostPerMillion": 14.0, "category": "gpt-4" } } }
Cost Calculation: calculateEstimatedCost()
calculateEstimatedCost()Location:
src/extension.ts (lines 776-802)
Formula:
- Input cost =
(inputTokens / 1_000_000) * inputCostPerMillion - Output cost =
(outputTokens / 1_000_000) * outputCostPerMillion - Total cost = input cost + output cost
- Fallback to
pricing for unknown modelsgpt-4o-mini
Executable Scripts
This skill includes three executable scripts that can be run directly to analyze session files. Always run scripts with their appropriate command first before attempting to read or modify them.
Script 1: Quick Session File Discovery
Purpose: Quickly discover all Copilot session files on your system with summary statistics.
Location:
.github/skills/copilot-log-analysis/get-session-files.js
When to use:
- Need a quick overview of session file locations
- Want to know how many session files exist
- Need sample paths for manual inspection
- Troubleshooting why session files aren't being found
Usage:
# Basic output with summary statistics node .github/skills/copilot-log-analysis/get-session-files.js # Show all file paths (verbose mode) node .github/skills/copilot-log-analysis/get-session-files.js --verbose # JSON output for programmatic use node .github/skills/copilot-log-analysis/get-session-files.js --json
What it does:
- Scans all VS Code variants (Stable, Insiders, Cursor, VSCodium, etc.)
- Finds files in workspace storage, global storage, and Copilot CLI locations
- Categorizes files by location and editor type
- Shows total counts and sample file paths
Example output:
Platform: win32 Home directory: C:\Users\YourName VS Code installations found: C:\Users\YourName\AppData\Roaming\Code\User C:\Users\YourName\AppData\Roaming\Code - Insiders\User Total session files found: 274 Session files by location: Workspace Storage: 192 files Global Storage (Legacy): 67 files Copilot Chat Extension: 6 files Copilot CLI: 9 files Session files by editor: VS Code: 265 files VS Code Insiders: 9 files
Script 2: Detailed Session File Diagnostics
Purpose: Comprehensive diagnostic tool that analyzes session file structure, content, and provides debugging information.
Location:
.github/skills/copilot-log-analysis/diagnose-session-files.js
When to use:
- Debugging session file discovery issues
- Need detailed information about session file structure
- Investigating token counting discrepancies
- Troubleshooting parser failures
- Understanding session file metadata and format variations
Usage:
# Basic diagnostic report node .github/skills/copilot-log-analysis/diagnose-session-files.js # Verbose output with all file paths and details node .github/skills/copilot-log-analysis/diagnose-session-files.js --verbose
What it does:
- Discovers all session files across VS Code variants
- Reports file locations, counts, and metadata
- Analyzes file structure (JSON vs JSONL format)
- Validates session file integrity
- Provides diagnostic information for troubleshooting
- Shows file modification times and sizes
Script 3: Schema Analysis and Field Discovery
Purpose: PowerShell script that analyzes session files to discover field structures and generate schema documentation.
Location:
.github/skills/copilot-log-analysis/analyze-session-schema.ps1
When to use:
- Need to understand the complete structure of session files
- Discovering new fields added by VS Code updates
- Generating schema documentation
- Understanding field variations across different VS Code versions
- Creating or updating schema reference files
Usage:
# Analyze session files and generate schema pwsh .github/skills/copilot-log-analysis/analyze-session-schema.ps1 # Specify custom output directory pwsh .github/skills/copilot-log-analysis/analyze-session-schema.ps1 -OutputPath ./output
What it does:
- Scans all discovered session files
- Extracts and catalogs all field names and structures
- Generates JSON schema documentation
- Creates field analysis reports
- Outputs to
docs/logFilesSchema/session-file-schema-analysis.json - Documents field types, occurrences, and variations
Note: This script generates the
session-file-schema-analysis.json file referenced in the Schema Documentation section below.
Usage Examples
Example 1: Finding all session files
const sessionFiles = await getCopilotSessionFiles(); console.log(`Found ${sessionFiles.length} session files`);
Example 2: Analyzing a specific session file
const filePath = '/path/to/session.json'; const stats = fs.statSync(filePath); const mtime = stats.mtime.getTime(); const content = await fs.promises.readFile(filePath, 'utf8'); const estimate = (text: string, model = 'gpt-4o') => Math.ceil(text.length * 0.25); const detectModel = (req: any) => req?.result?.metadata?.modelId ?? 'gpt-4o'; const parsed = parseSessionFileContent(filePath, content, estimate, detectModel); const editorType = getEditorTypeFromPath(filePath); console.log(`Tokens: ${parsed.tokens}`); console.log(`Interactions: ${parsed.interactions}`); console.log(`Editor: ${editorType}`); console.log(`Models:`, parsed.modelUsage);
Example 3: Processing daily statistics
const now = new Date(); const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate()); const sessionFiles = await getCopilotSessionFiles(); const estimate = (text: string, model = 'gpt-4o') => Math.ceil(text.length * 0.25); const detectModel = (req: any) => req?.result?.metadata?.modelId ?? 'gpt-4o'; let todayTokens = 0; for (const file of sessionFiles) { const stats = fs.statSync(file); if (stats.mtime >= todayStart) { const content = await fs.promises.readFile(file, 'utf8'); const parsed = parseSessionFileContent(file, content, estimate, detectModel); todayTokens += parsed.tokens; } }
Diagnostic Tools
Output Channel Logging
Location: Throughout
src/extension.ts
Methods available:
(line 146): Info-level logginglog(message)
(line 151): Warning-level loggingwarn(message)
(line 156): Error-level loggingerror(message, error?)
All logs go to "GitHub Copilot Token Tracker" output channel.
Diagnostic Report Generation
Method:
generateDiagnosticReport()
Location: src/extension.ts (lines 1813-2019)
Creates comprehensive report including:
- System information (OS, Node version, environment)
- GitHub Copilot extension status
- Session file discovery results
- Token usage statistics
- No sensitive data (code/conversations excluded)
Access via:
- Command Palette: "Generate Diagnostic Report"
- Details panel: "Diagnostics" button
File References
When working with log analysis, refer to these files:
-
Main implementation:
src/extension.ts- All field extraction methods
- Session file discovery logic
- Caching implementation
-
Configuration files:
- Token estimation ratiossrc/tokenEstimators.json
- Model pricing datasrc/modelPricing.json
- Data files documentationsrc/README.md
-
Schema documentation:
docs/logFilesSchema/- Complete schema reference
- Field analysis tools
- VS Code variant information
-
Skill resources:
.github/skills/copilot-log-analysis/
- Quick session file discovery scriptget-session-files.js
- Detailed diagnostic tooldiagnose-session-files.js
- PowerShell schema analysis scriptanalyze-session-schema.ps1
- This documentationSKILL.md
-
Project instructions:
.github/copilot-instructions.md- Architecture overview
- Development guidelines
Common Issues and Solutions
Issue: No session files found
Solution:
- Run diagnostic script:
node .github/skills/copilot-log-analysis/diagnose-session-files.js - Check if Copilot Chat extension is active
- Verify user has started at least one Copilot Chat session
- Check OS-specific paths are correct
Issue: Token counts seem incorrect
Solution:
- Verify
has correct ratios for modelstokenEstimators.json - Check if new models need to be added
- Review session file content to verify expected structure
- Check cache hasn't become stale (cache uses mtime)
Issue: Model not detected properly
Solution:
- Check
detection logicgetModelFromRequest() - Review
string patternsrequest.result.details - Add new model pattern if needed
- Update
with new modelmodelPricing.json
Notes
- All file paths must be absolute
- Token estimation is approximate (character-based)
- Caching significantly improves performance
- Session files grow over time as conversations continue
- JSONL format is newer (Copilot CLI/Agent mode)
- The extension processes files sequentially with progress callbacks