YouTip LogoYouTip

Skills Toolchain

Skills withtoolchainintegration | Tutorial\\n\\nSkills can integrate with external toolchains, allowing Skills to accomplish tasks that Claude alone cannot complete.\\n\\nThis article introduces how to call command-line tools, system tools, and third-party libraries in a Skill, and provides a complete integration example.\\n\\n* * *\\n\\n## Tool Types That Skills Can Call\\n\\n| Tool Type | Example | Invocation Method |\\n| --- | --- | --- |\\n| System Commands | ls, cp, find, wc | subprocess.run() |\\n| Language Runtimes | python, node, bash | subprocess.run() |\\n| Document Processing Tools | pandoc, pdflatex | subprocess.run() |\\n| Media Processing Tools | ffmpeg, imagemagick | subprocess.run() |\\n| Python Libraries | pandas, openpyxl, pypdf | Direct call after import |\\n| Node.js Tools | prettier, eslint | npx call |\\n\\n> Before calling external tools, ensure they are installed in the running environment. The Claude sandbox comes with common tools (python3, pip, node, npm) pre-installed, but tools like pandoc and ffmpeg require additional installation.\\n\\n* * *\\n\\n## Calling External Commands in Scripts\\n\\nPython's subprocess module is the standard way to call external commands, and it's recommended to wrap it into a reusable utility function.\\n\\n## Example\\n\\n# File path: scripts/tool_integration.py\\n\\nimport subprocess\\n\\nimport sys\\n\\nimport json\\n\\ndef run_command(cmd: list, timeout: int=60) ->dict:\\n\\n"""\\n\\n Run external command and capture output\\nParameters:\\n\\n cmd: Command list, e.g., ["pandoc", "--version"]\\n\\n timeout: Timeout in seconds, default 60\\n\\nReturns:\\n\\n Dictionary containing success, stdout, stderr, returncode\\n\\n """\\n\\ntry:\\n\\n result =subprocess.run(\\n\\ncmd,\\n\\n capture_output=True,# Capture both stdout and stderr\\n\\n text=True,# Return as string, not bytes\\n\\n timeout=timeout\\n\\n)\\n\\nreturn{\\n\\n"success": result.returncode==0,\\n\\n"returncode": result.returncode,\\n\\n"stdout": result.stdout.strip(),\\n\\n"stderr": result.stderr.strip()\\n\\n}\\n\\nexcept FileNotFoundError:\\n\\nreturn{\\n\\n"success": False,\\n\\n"returncode": -1,\\n\\n"stdout": "",\\n\\n"stderr": f"Command does not exist: {cmd}, please confirm it is installed"\\n\\n}\\n\\nexcept subprocess.TimeoutExpired:\\n\\nreturn{\\n\\n"success": False,\\n\\n"returncode": -1,\\n\\n"stdout": "",\\n\\n"stderr": f"Command execution timed out (exceeded {timeout} seconds)"\\n\\n}\\n\\n# Example: Convert Markdown to HTML using pandoc\\n\\nif __name__ =="__main__":\\n\\n result = run_command([\\n\\n"pandoc",\\n\\n"/mnt/user-data/uploads/readme.md",\\n\\n"-o","/mnt/user-data/outputs/readme.html",\\n\\n"--standalone"\\n\\n])\\n\\nif result:\\n\\nprint("Conversion successful")\\n\\nelse:\\n\\nprint(f"Conversion failed: {result['stderr']}")\\n\\nsys.exit(1)\\n\\n* * *\\n\\n## Checking Tool Availability\\n\\nChecking whether required tools are installed before Skill execution can provide clear feedback before the task fails midway.\\n\\n## Example\\n\\n# File path: scripts/check_tools.py\\n\\nimport shutil\\n\\nimport sys\\n\\nREQUIRED_TOOLS =[\\n\\n("pandoc","sudo apt-get install pandoc"),\\n\\n("ffmpeg","sudo apt-get install ffmpeg"),\\n\\n("convert","sudo apt-get install imagemagick"),\\n\\n]\\n\\ndef check_tools(tools: list) ->bool:\\n\\n"""Check tool list, returns True if all are ready"""\\n\\n all_ok =True\\n\\nfor tool, install_cmd in tools:\\n\\n path =shutil.which(tool)# Find tool path in PATH\\n\\nif path:\\n\\nprint(f" Installed: {tool} β†’ {path}")\\n\\nelse:\\n\\nprint(f" Not installed: {tool} Install command: {install_cmd}")\\n\\n all_ok =False\\n\\nreturn all_ok\\n\\nif __name__ =="__main__":\\n\\nprint("Checking tool dependencies...")\\n\\nif not check_tools(REQUIRED_TOOLS):\\n\\nprint("\\\\n Please install missing tools first.")\\n\\nsys.exit(1)\\n\\nprint("\\\\n All tools are ready, continuing execution.")\\n\\nChecking tool dependencies... Installed: pandoc β†’ /usr/bin/pandoc Not installed: ffmpeg Install command: sudo apt-get install ffmpeg Not installed: convert Install command: sudo apt-get install imagemagick Please install missing tools first.\\n\\n* * *\\n\\n## Declaring Tool Dependencies in SKILL.md\\n\\nUse the compatibility field in YAML frontmatter to list all external dependencies, so users know what needs to be prepared before installing the Skill.\\n\\n--- name: doc-converter description: > Convert documents between different formats, supporting Markdown, HTML, PDF, Word. Triggered when users need format conversion or document export. compatibility: tools: - pandoc >= 2.14 # Document format conversion - python >= 3.8 # Run auxiliary scripts python_packages: - pypdf >= 3.0 # PDF processing - python-docx >= 1.0---\\n\\n* * *\\n\\n## Integrating Node.js Tools\\n\\nThrough npx, you can directly call CLI tools from npm packages without global installation.\\n\\n## Example\\n\\n# File path: scripts/use_node_tool.py\\n\\nimport subprocess\\n\\nimport sys\\n\\ndef run_prettier(file_path: str) ->bool:\\n\\n"""Format code file using prettier"""\\n\\n result =subprocess.run(\\n\\n["npx","--yes","prettier","--write", file_path],\\n\\n capture_output=True,\\n\\n text=True\\n\\n)\\n\\nif result.returncode==0:\\n\\nprint(f"Formatting successful: {file_path}")\\n\\nreturn True\\n\\nprint(f"Formatting failed: {result.stderr}")\\n\\nreturn False\\n\\nif __name__ =="__main__":\\n\\nif len(sys.argv)<2:\\n\\nprint("Usage: python use_node_tool.py ")\\n\\nsys.exit(1)\\n\\nsys.exit(0 if run_prettier(sys.argv)else 1)\\n\\n> `npx --yes` will automatically download the tool package on first run, requiring network connection to the npm registry. In network-restricted environments, install globally in advance: `npm install -g prettier`.\\n\\n* * *\\n\\n## Standardized Processing of Tool Call Results\\n\\nDifferent tools have different output formats. It's recommended to wrap them uniformly at the Skill layer, exposing only a consistent structure externally.\\n\\n| Processing Method | Applicable Scenario | Typical Tools |\\n| --- | --- | --- |\\n| Capture stdout | Tools output results to standard output | pandoc, wc, cat |\\n| Check return code | Tools return 0 on success, non-zero on failure | Almost all CLI tools |\\n| Read output file | Tools write results to specified file | ffmpeg, pandoc -o |\\n| Parse JSON output | Tools support --json parameter | eslint --format json |\\n\\n* * *\\n\\n## Complete Integration Example: Markdown to PDF Report\\n\\nThe following example combines pandoc with Python scripts to implement a complete Markdown β†’ PDF generation Skill script.\\n\\n## Example\\n\\n# File path: scripts/md_to_pdf.py\\n\\n# Complete workflow: Check tools β†’ Validate input β†’ Call pandoc β†’ Confirm output\\n\\nimport subprocess\\n\\nimport shutil\\n\\nimport sys\\n\\nimport os\\n\\nimport json\\n\\nfrom datetime import datetime\\n\\ndef check_pandoc() ->bool:\\n\\n"""Check if pandoc is available"""\\n\\nif not shutil.which("pandoc"):\\n\\nprint("Error: pandoc not found, please run: sudo apt-get install pandoc")\\n\\nreturn False\\n\\nreturn True\\n\\ndef validate_input(md_path: str) ->bool:\\n\\n"""Validate input Markdown file"""\\n\\nif not os.path.exists(md_path):\\n\\nprint(f"Error: file does not exist β†’ {md_path}")\\n\\nreturn False\\n\\nif not md_path.lower().endswith(".md"):\\n\\nprint(f"Error: file must be .md format β†’ {md_path}")\\n\\nreturn False
← Skills VersioningSkills Multi Step β†’