Thanks for the response.  At a minimum, I'd recommend changing the error message from "Not in a source block" to something more descriptive as most people's initial response will be, "uhhh, but it looks like I am."   Ideally, an additional comment marker would delineate the source block from the meta-programmed variables to allow the edited source code's verbatim replacement.  Or it might make sense to have a setting that separates the tangled source file from the meta programmed variables.  Using your example above, it could tangle to something like the following: #!/bin/sh # [[file:~/tmp/test.org::org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE][org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE]]. ./noideahowtonamethesegenerically.sh    # the naming seems tricky to me echo $x# org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE ends here If babel was starting anew, I'd prefer that as it seems cleaner than adding another comment (assumption: majority of languages have an include-like facility of some sort).  Given the number of languages currently supported, the additional comment delimiters seem less disruptive. --Brad On Thursday, October 4, 2018, 8:19:30 AM PDT, Grant Rettke wrote: On Thu, Oct 4, 2018 at 2:09 AM Brad Knotwell wrote: > I've been playing with org-babel-detangle and I've noticed something that's either a bug or a limitation.  It's confusing enough that > it's worth writing down if it's expected.  Basically, it doesn't work if there are variables defined in the begin_src header.  I've > attached an example below.  The first one won't detangle and the last two will. That is expected behavior. Org can only detangle the content of source blocks. It can't deduce how that source code got in there. Maybe this example says it better: #+begin_src sh sh :tangle hw.sh :var x=(random) :shebang #!/bin/sh :comments link echo $x #+end_src Tangles to #!/bin/sh # [[file:~/tmp/test.org::org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE][org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE]] x='422131055910453451' echo $x # org_gcr_2018-10-04T08-35-43-05-00_cosmicality_CCEACAA2-A6B3-4FDD-9259-7F633316F0CE ends here