Code Skills
Code skills generate executable JavaScript code from detailed specifications and execute it safely. This subsystem is designed for skills that require dynamic code generation based on comprehensive functional and technical specifications, enabling complex logic without manual coding.
Descriptor Snapshot
Every code skill lives in .AchillesSkills/<domain>/<skill_name>/cskill.md.
The descriptor defines the skill's purpose, input/output formats, and references the specifications folder:
# User Profile Formatter
Formats a user's data into a readable string based on external functional specifications.
## Summary
Formats a user's data into a readable string based on external functional specifications.
## Input Format
- **user**: An object representing the user.
- `firstName` (string): The user's first name.
- `lastName` (string): The user's last name.
- `age` (number): The user's age.
## Output Format
- **Type**: `string`
- **Success Example**: "Full Name: Jane Doe, Age: 25 (Adult)"
- **Error Example**: "Error: Incomplete user data provided."
## Constraints
- The generated code must handle cases where the 'user' object or its properties are null or undefined.
The cskill.md file focuses on the high-level interface while detailed implementation
specifications are kept in the specs/ folder.
Input Format
section documents the expected structure, but the skill must parse any structured data from the prompt text itself.
Repository Layout
Code skills mirror the specs/ tree directly into runnable code under the skill root:
my-cskill/
├── cskill.md # Main skill definition
├── specs/ # Specification files
│ ├── index.mjs.md # Spec for index.mjs (main entrypoint)
│ ├── core.js.md # Spec for core.js (core logic)
│ └── utils.js.md # Spec for utils.js (utility functions)
├── index.mjs # Generated entrypoint (from specs/index.mjs.md)
├── core.js # Generated core module (from specs/core.js.md)
└── utils.js # Generated utility module (from specs/utils.js.md)
Key conventions:
specs/folder contains specification files named after the JavaScript files they describe- Spec files use
.mdextension (e.g.,index.mjs.md→ generatesindex.mjs) - Generated files live alongside the descriptor at the skill root;
- Do not manually edit generated files; update
specs/and regenerate
Specification Files
Specification files in the specs/ folder describe the code to be generated. Each file
corresponds to a JavaScript module and uses a structured format. Specifications should contain
only descriptions, requirements, and examples - not actual implementation code.
# Specification for index.js
## Function: action(context)
### Description
Formats a user object into a standardized string.
### Input
- promptText: Natural language instruction containing the user data
### Processing Logic
1. Parse the user data from promptText
2. Validate that the required fields are present
3. If validation fails, return error string
4. If validation succeeds, process data and return formatted result
### Example
```javascript
// Input:
"Format user data for Jane Doe, age 25"
// Output:
"Full Name: Jane Doe, Age: 25 (Adult)"
```
The LLM uses these specifications to generate complete, self-contained JavaScript modules. The specification describes what the code should do, not how to do it.
Code Generation Lifecycle
Code skills follow a two-phase lifecycle that separates code generation from execution:
Phase 1: Code Generation
When RecursiveSkilledAgent discovers a code skill (cskill.md), it automatically generates
the executable code from your specifications using the mirror code generator
and writes it directly under the skill directory.
- All
.mdfiles from thespecs/folder are read recursively - The generator focuses on specs and no longer depends on
cskill.mdsections - Everything is combined in a single LLM prompt for code generation
- Generated files mirror the
specs/paths (e.g.,specs/utils/foo.mjs.md→utils/foo.mjs) - Code regenerates automatically when specs are newer than the oldest expected target or any target is missing
For detailed information about how RecursiveSkilledAgent handles code skill discovery and generation,
see the Agent Runtime documentation.
Phase 2: Skill Execution
When you execute a code skill, the subsystem:
- Passes the raw prompt text directly to the skill action
- Dynamically imports and executes
index.mjsat the skill root - Wraps primitive results in
{ result: value }format - Returns the execution result
The generated action receives an object with promptText, plus injected
llmAgent and recursiveAgent references for advanced workflows.
- Automatic generation: Code is generated automatically during skill discovery
- Single-step generation: All specs and sections combined in one LLM prompt
- Timestamp-based caching: Only regenerates when specs change
- Multi-file support: Can generate multiple modules from multiple spec files
- Primitive result wrapping: Ensures consistent return format
Public API
prepareSkill(skillRecord)
Prepares the skill by generating code from specifications if needed.
- Parameters:
skillRecord- Skill record object with descriptor and paths - Returns: Promise that resolves when preparation is complete
- Side effects: Generates code files alongside the descriptor
executeSkillPrompt(options)
Executes the pre-generated code with the prompt text.
- Parameters:
skillRecord: Skill record objectrecursiveAgent: Agent with LLM accesspromptText: User's natural language promptoptions: Additional execution options
- Returns: Promise that resolves with execution result (primitives wrapped in
{ result: value }) - Side effects: None (uses pre-generated code)
Example:
await subsystem.executeSkillPrompt({
skillRecord,
recursiveAgent,
promptText: 'Format user data for John Doe, age 30'
});
checkIfRegenerationNeeded(skillRecord, currentSignature)
Determines if code regeneration is needed based on current state.
- Parameters:
skillRecord: Skill record with cached signaturecurrentSignature: Current specs signature
- Returns: Promise that resolves to boolean
- Logic: Compares newest spec to oldest expected target (mirroring
specs/paths) and triggers regeneration when any target is missing or stale
Error Handling
The subsystem handles various error conditions gracefully:
- Missing specs folder: Warns and skips code generation
- Code generation failure: Throws error with details
- Execution failure: Throws error with process output
- Invalid arguments: Returns structured error messages
When to Use Code Skills
Code skills are ideal for:
- Complex business logic: Multi-step processing with validation
- Data transformation: Converting between formats and structures
- Algorithm implementation: Custom algorithms described in natural language
- Integration layers: Adapters between different systems
- Domain-specific processing: Industry-specific calculations and rules
Consider other skill types for:
- Simple responses: Use Claude skills
- Database operations: Use DBTable skills
- Tool orchestration: Use MCP or Orchestration skills
See Also
- Code Skills Tutorial - Hands-on guide with examples
- Skill System Overview - Architecture and design principles
- Agent Runtime - How agents execute skills
- Dynamic Code Generation Skills - Comparison with dynamic code generation skills