codemap_routine_add_script

Associate a script with a routine.

routinescriptworkflow

Parameters

NameTypeRequiredDescription
routineNamestring✅ RequiredRoutine name
categorystringaudit | build | orient | close | utility✅ RequiredScript category
scriptNamestring✅ RequiredScript name (filename without .js extension)

Usage Examples

MCP Usage (for AI Agents like Claude)

json
{
  "name": "codemap_routine_add_script",
  "arguments": {
    "routineName": "deploy",
    "scriptName": "run-tests"
  }
}

Example Output

JSON Response

json
{
  "success": true,
  "data": {
    "script": {
      "category": "audit",
      "name": "check-dependencies"
    },
    "message": "Added script \"audit/check-dependencies\" to routine \"pre-release\"."
  }
}
ℹ️When to Use This Tool
    Use codemap_routine_add_script when you need to:
  • Add custom JavaScript scripts to routine workflows
  • Execute project-specific automation as part of routines
  • Run audit, build, orient, close, or utility scripts in workflows
  • Chain custom logic with macros and checklist items
  • Create sophisticated workflow automation with custom code
💡Common Patterns
Pre-Release Audit Workflow
Add audit scripts to release routine:
1. Create script: codemap_script_create({ category: "audit", name: "check-deps" })
2. Add to routine: codemap_routine_add_script({
routineName: "pre-release",
category: "audit",
scriptName: "check-deps"
})
3. Routine runs dependency audit before release


Session Automation
Add orient script to session start:
codemap_routine_add_script({
routineName: "session-start",
category: "orient",
scriptName: "load-project-context"
})


Build Pipeline
Chain build scripts:
codemap_routine_add_script({ routineName: "build", category: "build", scriptName: "compile-ts" })
codemap_routine_add_script({ routineName: "build", category: "build", scriptName: "bundle-assets" })
codemap_routine_add_script({ routineName: "build", category: "build", scriptName: "optimize" })
💡Pro Tips
  • Script must exist first: Create script with codemap_script_create before adding to routine
  • Category determines script type: Choose category based on script purpose (audit, build, orient, close, utility)
  • Scripts execute in order: Like macros, scripts run in the sequence they were added
  • Access CodeMap context: Scripts have full access to CodeMap API and project data
  • Combine with macros: Mix scripts and macros in same routine for maximum flexibility
Best Practices
  • Use scripts for complex logic that shell commands can't handle
  • Keep scripts focused on single responsibility
  • Add scripts in logical execution order within the routine
  • Test scripts individually before adding to critical routines
  • Document script purpose using routine messages or comments
  • Use appropriate category to organize scripts by function
⚠️Common Mistakes
Mistake: Adding script that doesn't exist
codemap_routine_add_script({ 
routineName: "deploy",
category: "build",
scriptName: "webpack-bundle" // Script not created
})
// Error: Script "build/webpack-bundle" not found

Instead: Create script first
codemap_script_create({ 
category: "build",
name: "webpack-bundle",
code: "/* webpack build logic */"
})
codemap_routine_add_script({
routineName: "deploy",
category: "build",
scriptName: "webpack-bundle"
})


---

Mistake: Wrong script category
// Audit script but labeled as build
codemap_routine_add_script({
routineName: "check",
category: "build", // Wrong category
scriptName: "lint-check"
})

Instead: Use correct category
codemap_routine_add_script({ 
routineName: "check",
category: "audit", // Correct: linting is auditing
scriptName: "lint-check"
})


---

Mistake: Including file extension in scriptName
codemap_routine_add_script({ 
routineName: "build",
category: "build",
scriptName: "compile.js" // Extension included
})
// Looks for build/compile.js.js

Instead: Omit .js extension
codemap_routine_add_script({ 
routineName: "build",
category: "build",
scriptName: "compile" // No extension
})
// Correctly finds build/compile.js


---

Mistake: Not handling script failures
// Script added to routine but throws errors
codemap_routine_add_script({
routineName: "deploy",
category: "build",
scriptName: "risky-script"
})
// Routine fails when script errors

Instead: Add error handling in script
// In script code:
try {
// Risky operation
} catch (error) {
console.error('Script failed:', error);
// Return error response instead of throwing
return { success: false, error: error.message };
}


---

Mistake: Mixing up routine name and script name
codemap_routine_add_script({ 
routineName: "check-dependencies", // This is the script name
category: "audit",
scriptName: "pre-release" // This is the routine name
})

Instead: Use correct names in correct parameters
codemap_routine_add_script({ 
routineName: "pre-release", // Routine name
category: "audit",
scriptName: "check-dependencies" // Script name
})