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.
Repository Layout
Code skills follow a simplified folder structure that separates specifications from generated code:
my-cskill/
├── cskill.md # Main skill definition
├── specs/ # Specification files
│ ├── index.js.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)
└── src/ # Generated code (auto-created)
├── index.mjs # Generated entrypoint
├── core.js # Generated core module
└── utils.js # Generated utility module
Key conventions:
specs/folder contains specification files named after the JavaScript files they describe- Spec files use
.mdextension (e.g.,index.js.md→ generatesindex.mjs) src/folder is auto-generated and contains the executable code- No manual editing of
src/files - they are regenerated from specs
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(args)
### Description
Formats a user object into a standardized string.
### Input
- args: Object containing user data
- user: Object representing the user
- firstName (string, mandatory): The user's first name
- lastName (string, mandatory): The user's last name
- age (number, mandatory): The user's age
### Processing Logic
1. Receive the user object from args.user
2. Validate that the user object and all its mandatory properties are present
3. If validation fails, return error string
4. If validation succeeds, process data and return formatted result
### Example
```javascript
// Input:
{
"user": {
"firstName": "Jane",
"lastName": "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 and writes it to the src/ folder.
- All
.mdfiles from thespecs/folder are read recursively - Relevant sections from
cskill.md(Input Format, Output Format, Constraints, Examples) are included - Everything is combined in a single LLM prompt for code generation
- The generated
.mjsfiles are written to thesrc/folder - Code regenerates automatically when spec files are newer than generated files
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:
- Extracts arguments from your prompt (or uses pre-provided arguments)
- Dynamically imports and executes
src/index.mjs - Wraps primitive results in
{ result: value }format - Returns the execution result
- 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
- Pre-provided args support: Can skip argument extraction when called programmatically
- 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: May create
src/folder and generate code files
executeSkillPrompt(options)
Executes the pre-generated code with provided arguments.
- Parameters:
skillRecord: Skill record objectrecursiveAgent: Agent with LLM accesspromptText: User's natural language promptoptions: Additional execution optionsargs(optional): Pre-structured arguments to pass directly to the skill, bypassing LLM extraction
- Returns: Promise that resolves with execution result (primitives wrapped in
{ result: value }) - Side effects: None (uses pre-generated code)
Example with pre-provided args:
await subsystem.executeSkillPrompt({
skillRecord,
recursiveAgent,
promptText: 'Format this user',
options: {
args: {
user: { firstName: 'John', lastName: '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: Checks src folder existence and signature match
Error Handling
The subsystem handles various error conditions gracefully:
- Missing specs folder: Warns and skips code generation
- Missing src folder: Automatically regenerates code
- 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
- Conversational flows: Use Interactive 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
- Code Generation Skills - Comparison with regular code generation skills