top | item 46549444

Show HN: Executable Markdown files with Unix pipes

126 points| jedwhite | 2 months ago | reply

I wanted to run markdown files like shell scripts. So I built an open source tool that lets you use a shebang to pipe them through Claude Code with full stdin/stdout support.

task.md:

    #!/usr/bin/env claude-run

    Analyze this codebase and summarize the architecture.
Then:

    chmod +x task.md

    ./task.md
These aren't just prompts. Claude Code has tool use, so a markdown file can run shell commands, write scripts, read files, make API calls. The prompt orchestrates everything.

A script that runs your tests and reports results (`run_tests.md`):

    #!/usr/bin/env claude-run --permission-mode bypassPermissions

    Run ./test/run_tests.sh and summarize what passed and failed.
Because stdin/stdout work like any Unix program, you can chain them:

    cat data.json | ./analyze.md > results.txt

    git log -10 | ./summarize.md

    ./generate.md | ./review.md > final.txt
Or mix them with traditional shell scripts:

    for f in logs/\*.txt; do

        cat "$f" | ./analyze.md >> summary.txt

    done
This replaced a lot of Python glue code for us. Tasks that needed LLM orchestration libraries are now markdown files composed with standard Unix tools. Composable as building blocks, runnable as cron jobs, etc.

One thing we didn't expect is that these are more auditable (and shareable) than shell scripts. Install scripts like `curl -fsSL https://bun.com/install | bash` could become:

    `curl -fsSL https://bun.com/install.md | claude-run`
Where install.md says something like "Detect my OS and architecture, download the right binary from GitHub releases, extract to ~/.local/bin, update my shell config." A normal human can actually read and verify that.

The (really cool) executable markdown idea and auditability examples are from Pete Koomen (@koomen on X). As Pete says: "Markdown feels increasingly important in a way I'm not sure most people have wrapped their heads around yet."

We implemented it and added Unix pipe semantics. Currently works with Claude Code - hoping to support other AI coding tools too. You can also route scripts through different cloud providers (AWS Bedrock, etc.) if you want separate billing for automated jobs.

GitHub: https://github.com/andisearch/claude-switcher

What workflows would you use this for?

101 comments

order
[+] Someone|2 months ago|reply
There’s nothing specific markdown to this. It could just as well be some other markup language, plaintext, or even any other textual language.

You could, for example, put a C program on lines 2 and further and expect/hope/pray Claude to interpret or compile and run that (adding a comment “run the following program; download and compile an interpreter or compiler if needed first” as an instruction to Claude would improve your chances)

[+] jedwhite|2 months ago|reply
Yes, you can use this with any text file and file extension to send file content to Claude Code with unix-like pipe support. Markdown happens to be a format that models like Claude work well with. And they provide a very readable way to mix structured and unstructured content along with code. But I use this with other plain text files regularly.

You could also pass commented code/scripts straight into Claude Code using it quickly without changing how they execute. The prompt instructions could go at the top of a valid file (say python/typescript) as comments, e.g.

`claude-run --azure --opus my_script.py`

[+] JohnKemeny|2 months ago|reply
I have developed my personal agentic file format `.ag` for this purpose.

Here is the template I start with:

    #!/usr/bin/env gpt-agent
     
    input: <target/context (e.g., cwd)>
     
    task: |
      <one clear objective>
     
    output: |
      <deliverables + required format>
     
    require:
      - <must be true before start; otherwise stop + report>
     
    invariant:
      - <must stay true while working (scope + safety)>
     
    ensure:
      - <must be true at the end (definition of done)>
     
    rescue: |
      <what to do if any requirement/invariant/ensure cannot be met>
[+] jedwhite|2 months ago|reply
Thanks for this. I find templates helpful too, and that's a neat structure. I use templates heavily with Obsidian for non-code tasks also. If you want to try it out, you can use this with the claude-run tooling with flags etc with files using your `.ag` extension with the modified shebang.

`#!/usr/bin/env claude-run --permission-mode bypassPermissions`

Or use the .ag files you have unmodified:

`claude-run --opus --vercel task.ag`

[+] nullpoint420|2 months ago|reply
Great idea, this reminds me of a Makefile! However, I do dread the cmake version of this that will nevertheless emerge in the next 10 years.
[+] wiether|2 months ago|reply
I think I get the idea... but why not officially create a new file type altogether?

Not only it would avoid any confusion (Markdown wasn't meant to be executable?) but it would allow future extensions in a domain that is moving fast.

The recent incident (https://news.ycombinator.com/item?id=46532075) regarding Claude Code's changelog shows that pure Markdown can break things if it is consumed raw.

Also, regarding: "Detect my OS and architecture, download the right binary from GitHub releases, extract to ~/.local/bin, update my shell config."

I have a hard time seeing how this is "more auditable" than a shell script with hardcoded URLs/paths.

"the right binary" is something that would make me reject an issue from a PM, asking for clarifications because it's way too vague.

But maybe that's why I'll soon get the sack?

[+] jedwhite|2 months ago|reply
Another format is an interesting idea. This tool will work with any text file content and file extension. So you could create another text-based format yourself and use it in theory.

I think the reasons Markdown is appealing include:

- It's just a text file.

- LLMs like Claude have high comprehension of the format, so Claude Code does very well with it.

- You can mix structured and unstructured text, and code with plain language: YAML frontmatter, outline/headings, code blocks, tables, links and images etc.

I used a heavily condensed version of the example prompt that Pete Koomen posted about as a simplified example, so that's really just me cutting it back to the most simple form of the concept.

In real-use it would be detailed, verbose and specific, and include the actual code blocks and external shell script references to retrieve and execute. So this really is just a proof of concept to give an idea of the sort of thing that people could create in future.

I know lots of us developers joke about getting the sack and losing out to AI. But for what it's worth, the sorts of points you raise are exactly why I think skilled developers become even more valuable than ever with AI.

Programming will change massively this next decade. But it has many times even in my life. So I'm definitely in the camp that thinks this is a new programming abstraction level, and Claude Code and Codex and others are useful tools that improve the productivity of skilled coders. Especially when they are used carefully and thoughtfully.

[+] DocTomoe|2 months ago|reply
So ... you are letting a nondeterministic LLM operate on the shell, via quasi-shellscript. This will appeal mostly to people who do not have the skillset to write an actual shell-script.

In short, isn't that like giving a voice-controlled scalpel to a random guy on the street an tell them 'just tell it to neurosurgery', and hope it accidentally does the right procedure?

[+] jedwhite|2 months ago|reply
I know this will not appeal to developers who don’t see a legitimate role for the use of AI coding tools with nondeterministic output.

It is intended to be a useful complement to traditional Shell scripting, Python scripting etc. for people who want to add composable AI tooling to their automation pipelines.

I also find that it helps improve the reliability of AI in workflows when you can break down prompts into re-useable single-task-focused modules that leverage LLMs for tasks they are good at (format.md, summarize-logs.md, etc). These can then be chained with traditional Shell scripts and command line tools.

Examples are summarizing reports, formatting content. These become composable building blocks.

So I hope that is something that has practical utility even for users like yourself who don’t see a role for plain language prompting in automation per se.

In practice this is a way to add composable AI-based tooling into scripts.

Many people are concerned about (or outright opposed to) the use of AI coding tools. I get that this will not be useful for them. Many folks like myself find tools like Claude helpful, and this just makes it easier to use them in automation pipelines.

[+] jrmg|2 months ago|reply
Don’t worry, it’s “more auditable”!
[+] rewilder12|2 months ago|reply
IDK man it feels like you are making a less-useful unsafe wheel.

- file types exist for a reason

- this is just prompt engineering which is already easy to do

[+] jedwhite|2 months ago|reply
I agree that script execution safety is a real concern, as it is with AI coding tools generally. By default the runnable markdown files do not have permission to execute code, unless you specifically add those permissions.

I can see there might be valid arguments for enforcing file type associations for execution at the OS level. These are just text files, and Unix-like environments support making text files executable with a shebang as a universal convention.

I am a fan of that unix-like philosophy generally: tools that try to do a single thing well, can be chained together, and allow users to flexibly create automations using plain text. So I tried to stick with that approach for these scripts.

I'm a bear of little brain, and prompt engineering makes my head hurt. So part of the motivation was to be able to save prompts and collections of prompts once I've got them working, and then execute on demand. I think the high readability of markdown as scripts is helpful for creating assets that can be saved, shared and re-used, as they are self-documenting.

[+] zahlman|2 months ago|reply
Aside from what several others said about having done something similar locally, wouldn't this be a trivial modification to Simon Willison's `llm` wrapper?
[+] jedwhite|2 months ago|reply
Big fan of Simon Willison. It would be great to see support for executing markdown files directly added to other tools like `llm`. And to Claude Code, Codex themselves.

claude-run is just a bunch of little convenience scripts, but for it to work effectively with code execution, the handling needs to do a little more than just `cat` the file output, for example stripping shebang lines, supporting flags and permissions and a few other things. But all very simple if you see the repo.

Adding support for session isolation and support for different cloud providers and API keys to keep things separate from one's personal Claude subscription took a little work. But that is optional.

[+] serious_angel|2 months ago|reply
Oh dear... but... but why let some LLM set of unknown source of unknown iteration... execute code... in your machine...?

I was excited in the possibly extravagant implementation idea and... when I read enough to realize it's based on some yet another LLM... Sorry, no, never. You do you.

[+] m-hodges|2 months ago|reply
> but why let some LLM set of unknown source of unknown iteration... execute code... in your machine...?

That’s entirely what Claude Code does.

[+] jedwhite|2 months ago|reply
You can use this without letting the markdown scripts you write execute any code at all, whether that is via Claude Code or other AI tool in future.

The default permissions are to not allow execution. Which means that you can use the eval and text-generation capabilities of LLMs to perform assessments and evaluations of piped-in content without ever executing code themselves.

The script shebang has to explicitly add the permissions to run code, which you control. It supports the full Claude Code flag model for this.

[+] yakkomajuri|2 months ago|reply
A few people have already mentioned similar tools here but one worth mentioning is Atuin Desktop (yes, the same shell history Atuin): https://blog.atuin.sh/atuin-desktop-runbooks-that-run/

"Executable runbooks" is the name given to the concept there

[+] jedwhite|2 months ago|reply
Thanks, it’s great to see people trying different approaches to runnable prompts and variations on literate programming. I think it’s an area with a lot of potential, and I expect there will be a lot of interesting ideas come out of it.
[+] jedwhite|2 months ago|reply
We made some improvements to support remote markdown script execution and piping.

Run scripts from the web:

    ```bash
    
    curl -fsSL https://andisearch.github.io/ai-scripts/analyze.md | claude-run
    
    echo "Explain what a Makefile does" | claude-run         # Simple prompt
    
    ```
Shebang flags in the markdown (like --permission-mode bypassPermissions) are honored.

There is a new initiative installmd.org from Nick Khami at Mintlify to support experiments with this approach.

https://installmd.org

[+] trollbridge|2 months ago|reply
Executable markdown? Why not just write a shell script?
[+] jedwhite|2 months ago|reply
There are some tasks that LLMs are good at, but which can be hard to do with traditional command line tools or scripts. This is true even when you are a skilled coder and expert in Shell scripting. Examples include summarization, judgement-based evaluation, formatting etc.

Executable markdown provides a method of building these tasks into traditional pipelines as small, single-task-focused, composable modules. They also have the advantage that they can be easily shared and re-used.

[+] PurpleRamen|2 months ago|reply
Looks more like executable prompt-files, as there seem to be no extra markdown-handling except removing the shebang. I know AIs are good at handling Markdown-Syntax, but do they support other markup-languages too? So you could use whatever you want here.
[+] jedwhite|2 months ago|reply
Yes you can use this with any text file format and file extension. Markdown just happens to work well with Claude Code and is very readable. But some other comments here mention `.ag` as a nice alternative, and plain text with C code. But you can also use it to send yaml, xml, simple text, or commented code in directly.

The scripts are all pretty simple but they also:

- Handle script-context-relevant flags and control code execution permissions

- Convenience flags for directing scripts to run across cloud providers rather than a personal Claude subscription.

- Session isolation, especially between your regular interactive `claude` command and running with API keys

This means that your runnable script use can be kept isolated from your regular personal Claude environment that you use for interactive development.

[+] linkregister|2 months ago|reply
I found this useful.

This could be dinosaur mindset from 2022, but would it not make sense to prompt the LLM to create a bash script based on these instructions, so it could be more deterministic? Claude code is pretty reliable, but this is probably only one and a half nines at best.

As for safety, running this in a devcontainer[1][2] or as part of a CI system should be completely fine.

1. (conventional usage) https://code.visualstudio.com/docs/devcontainers/containers

2. (actual spec) https://containers.dev/

[+] jedwhite|2 months ago|reply
Thank you, and yes! That is what I already frequently do for quick automation tasks.

As you say, Claude is actually very good at writing shell scripts and using tools on-the-fly. But I know there is an AI-confidence factor involved for developers making the choice to leverage that.

For simple tasks (in practice) I already find you can often prompt the whole thing.

For tasks where you already have the other traditional scripts or building blocks, or where it is complex, then you might break it up.

Interestingly, you can intermix these approaches.

You can have runnable markdown that writes and runs scripts on the fly, mixed with running command line tools, and chained along with traditional tools in a bash script, and then call that script from a runnable markdown that passes in test results, or analyzes the code base and passes recommendations in.

The composability and ability to combine and embed code blocks and tool use within plain language is quite powerful. I’m still learning how to use this.

I’m glad it is already useful and thank you.

[+] rognjen|2 months ago|reply
Jupyter notebooks also exist. Also see https://en.wikipedia.org/wiki/Literate_programming
[+] jedwhite|2 months ago|reply
I'm also a fan and heavy user of Jupyter notebooks and literate programming in general. I think the use case for runnable mardown files with AI tooling for automation applies to complementary cases.

Having said that, there are ad hoc automation tasks that I've traditionally used Jupyter notebooks to do that I'm finding are easier to get running using markdown files and Claude Code. It's early days and I still am getting a feel for this myself.

There are some comments from earlier with discussion of other literal program tools.

[+] graemefawcett|2 months ago|reply
I took that idea just as far as I could and landed here

https://zenodo.org/records/18181233

It parses the AST out of it and then has a play

We're using it as an agentic control plane for a fortune 500s developer platform.

Keep going with yours, you'll find it

[+] ksherlock|2 months ago|reply
I'm not the target demographic, but this seems like a step backwards.

Like, once upon a time maybe you gave your jr programmer a list of things to do, and depending on their skill, familiarity with the cli, hangover status, spelling abilities, etc, you'll get different results. So you write a deterministic shell script.

[+] jedwhite|2 months ago|reply
I know there are two polarized camps on the topic of AI coding. Even for people who are concerned about it and prefer to use traditional scripting, there are some benefits worth considering in having runnable, composable prompt modules.

There are some tasks that are challenging to achieve with traditional code, but where modern LLMs perform strongly.

Examples include summarization, complex content formatting and restructuring, natural language classification, and evaluation judgements.

I’ve found that it is useful to be able to easily incorporate these along with traditional Shell scripts and command line tools as part of workflow pipelines. And I hope it can be useful for other people too.

[+] chrismorgan|2 months ago|reply
I get the intent, but it’s bizarre to hear invocation of nondeterministic tools that occasionally delete people’s entire drives “more auditable”.
[+] jedwhite|2 months ago|reply
My view is that readability and ease of understanding have a real impact on auditability. Nondeterministic output also clearly has a significant impact on auditability.

The balance between readability and determinism for auditability partly relates to developer philosophy. Tech is famous for religious arguments. I have friends who hate AI coding, and want to avoid nondeterminstic tools at all costs. And other friends whose productivity has increased significantly, and who see the future of programming as natural language.

The quality of AI models and tools like Claude Code is improving fast, and there are many developers who find value in them, myself included. I built this to make life easier for developers who want to use AI tools for automation.

I find it much faster to parse and understand plain language than many code scripts I've seen. It was one of Python's great insights that people spend more time reading code than writing it. And there is a tradeoff in auditability between determinism and the ability to quickly read and understand what systems do.

There are clearly many people who find AI useful, and who are becoming skilled in its use as a tool. This is just a little tool that I put together for myself and other people who fall in that basket.

Learning where to use AI tools appropriately - how to constrain the dangers while maximizing the value - is part of the challenge. From using this particular tool for real work, it fits some use cases well, and can make things easier both to understand and share, as well as to write.

I hope it's useful for some other people wanting to use AI for scripting and automation.

I think that quickly understandable instructions are part of auditability. Not the whole thing, and their use needs to be balanced with safety and security. But an important part of it.

I accept there are plenty of folks who don't see AI tools that way. We're sharing this for people who see the value in this new approach, even though it is a fast-moving field and there are a lot of imperfections.

Any reasonably competent Claude Code user who is careful about setting permissions boundaries is no more going to delete their hard drive than a competent command line user would. There will be things that go wrong with AI, as before it.

In years of tech support, I've personally had to help people who neutered their Windows install or deleted files they needed. Those things happen and I'd argue they come down to skill issues, with AI or without. New tools have a learning curve.

I get that you think that's bizarre to see readability with AI-based tools as more auditable, and I really do understand that perspective.

[+] tobyhede|2 months ago|reply
I've taken this a step further with https://rundown.cool.

Define runbooks with markdown, and a tool that supports the agent through the workflow.

[+] redhale|2 months ago|reply
From the title, I thought this was going to be a link to mdflow [0], which seems like a very similar tool.

[0] https://mdflow.dev/

[+] jedwhite|2 months ago|reply
They're quite different, I think. Some advantages with claude-run include:

- You make standard Markdown files directly executable using a shebang line.

- No special Markdown formatting or syntax needed. The Markdown itself is clean and standard, rather than using variable placeholders or any kind of special syntax.

- Regular filenames work: no special filename format needed. It just works like regular shell scripts with flags and piping

- Works with any text file format and file extension (xml, yaml, .ag etc)

- Includes support for session isolation

- Keeps script use separate from your regular Claude Code subscription

- Allows you to specify the provider cloud / model in scripts, or switch them on the fly.

It is intended to be more unix-like in philosophy.

[+] VikingCoder|2 months ago|reply
Does it help get repeatable results if you say, "Use a random seed of 42 for this task"? Or if you somehow lower the temperature, so it's more deterministic?
[+] jedwhite|2 months ago|reply
At the moment, it looks like Claude Code does not support using ‘temperature’ or ‘seed’ flags. It would be awesome if they add that.

Using the request to use a seed within the prompt will mean that when Claude rights the code it could use that seed inside what it writes for randomize functions. But sadly it wouldn’t impact Claude’s own text generation’s determinism.

There is active interest on GitHub to support this. But the most recent issue with it I could see was closed in July as “not planned”