What Is a Snippet? An Engineer's Guide to Reusable Pieces of Code and Text
How many times this week did you type the same paragraph in a quote, or hunt again for the same Excel formula? A snippet lets you save that piece once and paste it in a second. This guide shows what snippets are, where you meet them in AI, coding and office work, and how to use them without getting burned.
01What is a snippet, in one sentence
A snippet is a short piece of code or text meant to be reused. It can be a five-line Python function, an Excel formula, a standard closing paragraph for emails, or a prompt that works well with Claude.
Why bother? So you stop retyping the same thing, so the whole office writes and calculates the same way, and so you save time and typos. A piece that was checked once and saved does not need to be checked again every time.
Note: in search, the word snippet also has a completely different meaning, the summary Google shows under a result. More on that below.
02Think of a rubber stamp on the desk
Old offices had stamps: "Checked and approved", "True copy", the company address. Nobody wrote those by hand each time, they just stamped. A snippet is a digital stamp: a ready, checked piece you drop in with one action instead of rewriting it and getting one letter wrong.
03Where you meet snippets
A code block in an AI answer
When you ask Claude or ChatGPT for a script, the code appears in its own box with a copy button. That is a classic code snippet.
Text-expander snippets
Text expander apps, and your operating system's text replacement setting, turn a short code like ;thanks into a full paragraph.
Saved prompts
A prompt that worked great for reviewing a report or summarising a meeting, saved and pasted again instead of rewritten.
VS Code snippets
The VS Code editor lets you define a short trigger that expands into a whole block of code, such as a standard header for every calculation script.
Excel formulas and HTML embeds
A standard check formula, or embed code you paste into a website: a Google Analytics tag, a YouTube video or a calculator.
Google's featured snippet
A different meaning altogether: the highlighted answer box Google sometimes shows above the results, quoting a piece of a web page.
04The safe path: from a Claude answer to your file
- 1Ask and understandAsk Claude for a line-by-line explanation, not just the code
- 2CopyUse the box's copy button so no character or space is lost
- 3Test on a copyRun it on a copy of the file or a test site, never the original
- 4Check by handTry one case where you already know the answer
- 5Save with a nameA clear name and a short note: what it does, when, who checked it
05Where to keep your favourite prompts
A text expander
Type a short trigger and the full prompt appears, in any app or website. Best for short prompts you use daily.
Claude Project instructions
A Project can hold standing instructions that apply to every chat inside it, such as "always answer in Hebrew, in SI units". Availability depends on your plan. See Context that stays.
A Skill
When a prompt has grown into a full procedure with a template and checklist, turn it into a Skill that Claude loads by itself when needed. See Procedures for AI.
A plain text file or shared doc
The simple option: one document with all your good prompts, sorted by topic. Works for any team, nothing to install.
06Your first VS Code snippet in 5 minutes
- 1
Open snippet settings
Go to File, Preferences, Configure Snippets, or run Snippets: Configure Snippets from the Command Palette.
- 2
Pick a language
For example python, so the snippet only appears in Python files. A global file for all languages is also possible.
- 3
Write a name, trigger and body
Each snippet has a prefix (the trigger you type), a body (the lines inserted) and an optional description.
- 4
Save and try it
In a Python file, type the trigger, pick it from the suggestion list, and the whole block appears.
- 5
Share with the team
A snippets file in the project's .vscode folder is available to everyone working on that project.
07Example: unit conversion in Python
08Example: an Excel formula for an edge distance check
09Example: a standard reply to a quote request
10Example: embedding a calculator in the company website
11What you need, where to keep the snippet, and why
| Need | Where to keep it | Why |
|---|---|---|
| A sentence or email you send daily | Text expander or OS text replacement | Works in every app, a few keystrokes |
| A prompt you use a lot | Prompt document or text expander | Instantly available, easy to improve and share |
| Standing instructions for one topic | Claude Project instructions | Applies automatically to every chat in the project |
| A full procedure with template and checklist | Skill | Claude loads it by itself when the task fits |
| A code block repeated across scripts | VS Code user snippets | Inserted with a trigger, shareable with the team |
| An Excel check formula | Template sheet with a note | Checked once, stays consistent |
| Embed code for a website | A tidy text file or a saved WordPress block | No more hunting for the code on every new page |
12FAQ
Can I run code from Claude without understanding it?
Better not. Ask for a line-by-line explanation, run it first on a copy of the file, and check it against a case where you know the answer. This matters most for VBA macros that change files or delete data.
What about passwords and API keys?
Never paste a snippet that contains a password, API key or token into a chat, a shared doc or a website. If code needs a key, keep it separately (for example in an environment variable) and leave only its name in the code.
Can I copy any code I find online?
Not always. Code on websites and GitHub comes with a licence that says what you may do with it. Before putting such a piece into a commercial product, check the licence, see GitHub without code.
What is the difference between a snippet and a Skill?
A snippet is a piece you paste yourself. A Skill is a package of instructions Claude loads by itself when the task fits. A prompt that has grown into a full procedure is a good candidate for a Skill.
And what is a featured snippet?
It is an SEO term: a highlighted answer box Google sometimes shows above the results, quoting part of a page. It has nothing to do with code, but a short, clear answer near the top of an article improves your chances of appearing there.
Is an old snippet still correct?
Not necessarily. Standards, factors and prices change. Write a date and source in every snippet, and review your list every few months.